Colors look very different in Android emulator or Android device when drawing using Canvas
and Paint
compared with Adobe Photoshop or Google Chrome running in the same Mac (and same screen).
See the next screenshot to see the difference. On the left side is a website in Google Chrome and on the right side is the Android emulator with two squares which should match the two colors in the website.
If I copy and paste the RGB colors to Adobe Photoshop, the colors match with the ones displayed in the website. If I run my Android app in a real device, the colors still look like the colors displayed in the Android emulator.
The code I used to draw the Canvas
is this:
Bitmap bitmap = Bitmap.createBitmap(
imageView.getWidth(),
imageView.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint1 = new Paint();
paint1.setColor(Color.parseColor("#23B2A8"));
canvas.drawRect(0, 0, 200, 200, paint1);
Paint paint2 = new Paint();
paint2.setColor(Color.parseColor("#213468"));
canvas.drawRect(200, 0, 400, 200, paint2);
imageView.setImageBitmap(bitmap);
There is a big difference. Am I doing something wrong? I want the colors to look similar.
Thanks for reading!
The issue was in the ImageView
definition. I had an android:tint
attribute.
<ImageView
android:id="@+id/myImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:tint="#55ff0000" />
Removing the attribute solves the issue.