converting Java bitmap to byte array

Bitmap bmp = intent.getExtras().get(“data”); int size = bmp.getRowBytes() * bmp.getHeight(); ByteBuffer b = ByteBuffer.allocate(size); bmp.copyPixelsToBuffer(b); byte[] bytes = new byte[size]; try { b.get(bytes, 0, bytes.length); } catch (BufferUnderflowException e) { // always happens } // do something with byte[] When I look at the buffer after the call to copyPixelsToBuffer the bytes are all 0… … Read more

How to Resize a Bitmap in Android?

I have a bitmap taken of a Base64 String from my remote database, (encodedImage is the string representing the image with Base64): profileImage = (ImageView)findViewById(R.id.profileImage); byte[] imageAsBytes=null; try { imageAsBytes = Base64.decode(encodedImage.getBytes()); } catch (IOException e) {e.printStackTrace();} profileImage.setImageBitmap( BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length) ); profileImage is my ImageView Ok, but I have to resize this image before … Read more

How to convert a Drawable to a Bitmap?

I would like to set a certain Drawable as the device’s wallpaper, but all wallpaper functions accept Bitmaps only. I cannot use WallpaperManager because I’m pre 2.1. Also, my drawables are downloaded from the web and do not reside in R.drawable. 2Best Answer 21 This piece of code helps. Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_resource); Here … Read more