读书人

bit地图转字节

发布时间: 2012-07-04 19:33:54 作者: rapoo

bitmap转字节

byte[] flattenBitmap(Bitmap bitmap) {

? ? ? ? // Try go guesstimate how much space the icon will take when serialized

? ? ? ? // to avoid unnecessary allocations/copies during the write.

? ? ? ? int size = bitmap.getWidth() * bitmap.getHeight() * 4;

? ? ? ? ByteArrayOutputStream out = new ByteArrayOutputStream(size);

? ? ? ? try {

? ? ? ? ? ? bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);

? ? ? ? ? ? out.flush();

? ? ? ? ? ? out.close();

? ? ? ? ? ? return out.toByteArray();

? ? ? ? } catch (IOException e) {

? ? ? ? ? ? Log.w("Favorite", "Could not write icon");

? ? ? ? ? ? return null;

? ? ? ? }

? ? }

读书人网 >移动开发

热点推荐