I create a bitmap after doing some canvas and paint operations, and then Base64 encodes it into a string. When I repeat the process on a separate device and compare the base64 encoded strings returned by the two devices, they are different. Any ideas on why this is?
The code that generates the bitmap is
Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.save();
canvas.rotate(45, midX, midY);
canvas.restore();
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setTextSize(45);
paint.setTextAlign(Align.CENTER);
paint.setTextColor(Color.parseColor(colorString));
StaticLayout staticLayout = new StaticLayout("Text", paint, width,Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
staticLayout.draw(canvas);
The code that converts the bitmap to a Base64 encoded string is
int size = bitmap.getRowBytes() * bitmap.getHeight();
byte[] byteArray;
ByteBuffer byteBuffer = ByteBuffer.allocate(size);
bitmap.copyPixelsToBuffer(byteBuffer);
byteArray = byteBuffer.array();
String encodedString = Base64.encodeToString(byteArray, Base64.NO_WRAP);
source
share