I create a bitmap after doing some canvas and paint operations and then Base64 encode it to 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 that would be the case ?
Code that generates the bitmap -
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);
Code that converts the bitmap to a Base64 encoded string -
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);
Even if the fonts are exactly the same, hinting (both of the character glyphs and lines) will be dependent on the underlying hardware as well as the browser.
This is a well known characteristic of the HTML canvas.
If you want to be able to generate exactly the same image on 2 different devices then you'd need to work on uint array with your own primitives for drawing / your own font handlers.