This example introduces several static functions for creating Mutable Bitmap defined in Bitmap.
[Java]
// These three are initialized with colors []
MBitmaps [0] = Bitmap. createBitmap (colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap. Config. ARGB_8888 );
MBitmaps [1] = Bitmap. createBitmap (colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap. Config. RGB_565 );
MBitmaps [2] = Bitmap. createBitmap (colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap. Config. ARGB_4444 );
// These three will have their colors set later
MBitmaps [3] = Bitmap. createBitmap (WIDTH, HEIGHT,
Bitmap. Config. ARGB_8888 );
MBitmaps [4] = Bitmap. createBitmap (WIDTH, HEIGHT,
Bitmap. Config. RGB_565 );
MBitmaps [5] = Bitmap. createBitmap (WIDTH, HEIGHT,
Bitmap. Config. ARGB_4444 );
// These three are initialized with colors []
MBitmaps [0] = Bitmap. createBitmap (colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap. Config. ARGB_8888 );
MBitmaps [1] = Bitmap. createBitmap (colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap. Config. RGB_565 );
MBitmaps [2] = Bitmap. createBitmap (colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap. Config. ARGB_4444 );
// These three will have their colors set later
MBitmaps [3] = Bitmap. createBitmap (WIDTH, HEIGHT,
Bitmap. Config. ARGB_8888 );
MBitmaps [4] = Bitmap. createBitmap (WIDTH, HEIGHT,
Bitmap. Config. RGB_565 );
MBitmaps [5] = Bitmap. createBitmap (WIDTH, HEIGHT,
Bitmap. Config. ARGB_4444); and use compress to generate PNG or JPEG images:
[Java]
For (int I = 0; I <mBitmaps. length; I ++ ){
MJPEG [I] = codec (mBitmaps [I], Bitmap. CompressFormat. JPEG, 80 );
MPNG [I] = codec (mBitmaps [I], Bitmap. CompressFormat. PNG, 0 );
}
...
Private static Bitmap codec (Bitmap src, Bitmap. CompressFormat format,
Int quality ){
ByteArrayOutputStream OS = new ByteArrayOutputStream ();
Src. compress (format, quality, OS );
Byte [] array = OS. toByteArray ();
Return BitmapFactory. decodeByteArray (array, 0, array. length );
}
Author: mapdigit