0

I'm developing an android app and I'm facing a weird issue. I'm doing some image processing on a SurfaceView. I'm drawing the processed image using a canvas and the following method:

canvas.drawBitmap(image, x, y, paint)

My SurfaceView has a colored background (#3500ffff, kind of very dark green) and once the image is drawn, I can notice that its original colors are not conserved. It has a very slight dark green tint, like if the bitmap alpha was changed.

Did anyone already encounter this issue? Would you have an idea on how to fix this?

Nicolas P.
  • 581
  • 1
  • 4
  • 15
  • 1
    Are you sure you have the right color? #00ffff looks to me like very light green. Having Alpha = 35 means its more transparent. So if you do have a 'dark green' tint, that means you're drawing a transparent light green on black background? – f20k Jan 19 '11 at 20:43
  • Yes sorry I was confused, this is actually a very light green. It's the color I use for the background of my different layouts and since alpha = 35, it looks like a dark green with the black background of the activities. – Nicolas P. Jan 19 '11 at 21:33

2 Answers2

1

This would happen with a 16 bits destination. 16 bits buffers encode pixels in 565 format, which gives you a higher precision in the green channel, which sometimes result in greenish tints. A 32 bits destination/bitmap would solve this issue.

Romain Guy
  • 97,993
  • 18
  • 219
  • 200
  • I tried to get a copy of my bitmap setting it's Config to ARGB_8888 and I also changed the pixels format of my SurfaceHolder to RGBA_8888 but it didn't seem to solve the issue. Am I doing wrong somewhere? – Nicolas P. Jan 19 '11 at 22:41
0

Presuming that your image is not transparent how did you define paint, it should not be a transparent colour or use some special effect. Try using null for paint.

The other thing is what are you drawing first the image or the background? Just wondering if your drawing order is correct.

If you set your surface to be non-transparent will the image change colour then?

Another thing I noticed which I think is connected with events sychronisation is that sometimes drawing on surface creates a semi-transparent sprite when moving the finger very fast over the screen which initialises drawing.

Lumis
  • 21,517
  • 8
  • 63
  • 67
  • I need paint for setting a ColorMatrixColorFilter. I'm first drawing the background (defined in the xml layout, so drawn when the view is created). I think you got the point, as the drawing method is controlled by a thread in SurfaceViews, my bitmap is drawn in a loop and thus a very slight transparent sprite can be noticed unfortunately. – Nicolas P. Jan 20 '11 at 01:56
  • You have to draw background colour just before you draw bitmap like: canvas.drawColor(myColour); canvas.drawBitmap(image, x, y, paint); in onDraw. I don't know what kind of paint you produce with ColorMatrix... – Lumis Jan 20 '11 at 09:48