Array of bytes from View in android -
i have drawing view, , trying array of bytes view on button click
this code:
public void onclick( drawview.setdrawingcacheenabled(true); string imgsaved = mediastore.images.media.insertimage( getcontentresolver(), drawview.getdrawingcache(), uuid.randomuuid().tostring() + ".png", "drawing"); } }
please help!
if view imageview first convert bitmap convert byte array
convert imageview bitmap
public static bitmap getimageviewasbitmap(imageview imageview) { imageview.builddrawingcache(); bitmap bmap = imageview.getdrawingcache(); return bmap; }
convert bitmap byte array
public byte[] getbitmapasbytearray(bitmap bitmap) { bytearrayoutputstream outputstream = new bytearrayoutputstream(); bitmap.compress(compressformat.png, 0, outputstream); return outputstream.tobytearray(); }
convert byte array bitmap
public static bitmap getbytearrayasbitmap(byte[] bitmap) { bitmap bm = null; try { bm = bitmapfactory.decodestream(new bytearrayinputstream(bitmap)); } catch (exception e) { } return bm; }
to call these methods that:
provide imageview give bitmap
bitmap m1bitmap= getimageviewasbitmap(myimageview);
provide bitmap give byte array
byte[] mbytearray =getbitmapasbytearray(mbitmap);
provide byte array give bitmap
bitmap m2bitmap= getbytearrayasbitmap(byte[] bitmap);
Comments
Post a Comment