1. Convert picture to binary stream
Public byte [] Getbitmapbyte (Bitmap Bitmap) { new bytearrayoutputstream (); // parameter 1 conversion type, parameter 2 compression quality, parameter 3 byte throttle resource Bitmap.compress (Bitmap.CompressFormat.JPEG,N, out); Try { out.flush (); Out.close (); Catch (IOException e) { e.printstacktrace (); } return Out.tobytearray (); }
2. Change the binary stream into a picture (BITMAP)
Public Bitmap getbitmapfrombyte (byte[] temp) { ifnull) { = Bitmapfactory.decodebytearray (temp, 0, temp.length); return bitmap; } Else { returnnull; } }
Swap binary streams for pictures (drawable)
Public Drawable getbitmapfrombyte (byte[] temp) { ifnull) { = Drawable.createfromstream (Bais, "image"); return drawable; } Else { returnnull; } }
3. Convert Bitmap to Drawable
Public StaticBitmap Drawabletobitmap (drawable drawable) {intwidth =drawable.getintrinsicwidth (); intHeight =drawable.getintrinsicheight (); Bitmap Bitmap=bitmap.createbitmap (width, height, drawable.getopacity ()! = Pixelformat.opaque?Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565); Canvas Canvas=NewCanvas (bitmap); Drawable.setbounds (0,0, Width,height); Drawable.draw (canvas); returnbitmap; }
Or
New Fastbitmapdrawable (bitmap);
Or
Bitmapdrawable tempdrawable = (bitmapdrawable) drawable; Tempdrawable.getbitmap ();
Android transforms the image into stream storage and converts the flow to an image