Reputation: 3
I am trying to convert my Java Applet which connects to a video surveillance server to run on Android. I am having issues with trying to convert a byte array containing a JPEG image to a Bitmap object on Android.
The Applet code is:
private Toolkit Tk = Toolkit.getDefaultToolkit();
private Image m_Image = null;
byte[] buf = this.SockClient.ReadStream(size));
m_Image = tk.createImage(buf);
My Android code is:
private Bitmap m_Image = null;
ByteBuffer bb = null;
m_Image = Bitmap.createBitmap(320,240,Bitmap.Config.RGB_565);
byte[] buf = this.SockClient.ReadStream(size);
bb = ByteBuffer.wrap(buf);
m_Image.copyPixelsFromBuffer(bb);
I am getting a NullPointerException after calling copyPixelsFromBuffer.
I'm guessing I am using the wrong methods to do the job.
Upvotes: 0
Views: 476
Reputation: 1006944
Use BitmapFactory
and decodeByteArray()
to convert a byte[]
of JPEG data to a Bitmap
.
Upvotes: 1