Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitmap-backed canvas.drawRect fails with paint #7188

Closed
hoisie opened this issue Mar 26, 2022 · 5 comments
Closed

Bitmap-backed canvas.drawRect fails with paint #7188

hoisie opened this issue Mar 26, 2022 · 5 comments
Labels
starter issue Small/simple issues for new contributors

Comments

@hoisie
Copy link
Contributor

hoisie commented Mar 26, 2022

  @Test
  public void drawRect_toCanvas() {
    Bitmap bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888);
    bitmap.eraseColor(Color.BLACK);
    assertThat(bitmap.getPixel(0, 0)).isEqualTo(Color.BLACK);

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setStyle(Style.FILL);
    paint.setAntiAlias(true);
    paint.setColor(Color.WHITE);
    canvas.drawRect(0, 0, 10, 10, paint);
    assertThat(bitmap.getPixel(0, 0)).isEqualTo(Color.WHITE);
  }
@hoisie hoisie added the starter issue Small/simple issues for new contributors label Mar 26, 2022
@hoisie
Copy link
Contributor Author

hoisie commented Mar 26, 2022

This test passes on an emulator, but fails in Robolectric with:

assertThat(bitmap.getPixel(0, 0)).isEqualTo(Color.WHITE);
Expected :-1
Actual   :-16777216

@s-deepak-kumar
Copy link

s-deepak-kumar commented Mar 27, 2022

Can You Please Assign It To Me?

@Akshay2131
Copy link
Contributor

@hoisie i looked into it.. As output is coming as -16777216. In binary form, -16777216=11111111 00000000 00000000 00000000
Here, representation of bits is as: first 8-bits: Alpha, second 8-bits: Red, third 8-bits: green and last 8-bits: blue.
Here, in -16777216 RGB bits are all 0. It means it represents fully opaque black color.
for white color, RGB should be all 1.
what u think @hoisie

@utzcoz
Copy link
Member

utzcoz commented Mar 27, 2022

@Akshay2131 you can use https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#toHexString(int) to identify different more convenient, e.g.

assertThat(Integer.toHexString(bitmap.getPixel(0,0)).isEqualsTo(Integer.toHexString(Color.WHITE));

Here, in -16777216 RGB bits are all 0. It means it represents fully opaque black color.

It represents Bitmap-backed canvas.drawRect fails with paint. It's recommend to see what Robolectric does to support Bitmap backed Canvas.

@utzcoz
Copy link
Member

utzcoz commented Apr 5, 2022

Fixed by #7210.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
starter issue Small/simple issues for new contributors
Projects
None yet
Development

No branches or pull requests

4 participants