Android common translucent error

I use anti aliasing to make my images smoother. When using anti-aliasing, a dark frame will be drawn around the images. This is because Android uses black and mixes it with yellow. This is the problem of geral! When I draw a rectangle and set the alpha value to 127, the image also becomes dark. Instead of using black Android, you should use white to paint transparency.

Is there a workaround for solving this problem?

Sample source code for drawing a translucent rectangle on canvas. The rectangle is also dark, but it should be bright.

Bitmap bmp = Bitmap.createBitmap(200, 200, Config.ARGB_8888); Canvas canvas = new Canvas(bmp); Paint rPaint = new Paint(); rPaint.setColor(Color.parseColor("#F7E836")); rPaint.setAlpha(127); rPaint.setStyle(Paint.Style.FILL); canvas.drawRect(0, 0, 100, 100, rPaint); 

Images are SVG graphics that are displayed with the following library: http://code.google.com/p/svg-android/

I think I found a mistake. The problem is SurfaceView. Its background is black. The same translucent error occurs when I use the code above and display it on an ImageView, and the background color of the user interface element behind ImageView is black. The background color of SurfaceView is always black. If I change this to white using setBackgroundColor, the SurfaceView will turn white, but the white background will be painted on top of all my other images drawn using OpenGL. I think they need to be switched. First, the background color must be drawn, and the material is OpenGL.

+6
source share
1 answer

Put links to the original source images and show how to smooth them (code).

When the image is smoothed, the algorithm will insert colors between the colors that make up the edges. Thus, with your yellow star image, if the background was white, it will try to add pixels around the edge that are between yellow and white (a lighter shade of yellow). This is what β€œsmooths” the image.

But if the image has an indexed color space, these lighter shades of yellow probably do not exist in the image tray, and as a result, you can get almost any other color in its place, whatever the color in the sections of the index according to the calculated index value.

The image in your question is indexed png and therefore has this problem.

If this is a problem, you need to convert the original source images to an unindexed color space or hide them before indexing images that do not work, if the images need to be scaled by your application or if you need to smooth out different types of background.

Another thing that can happen is that your anti-aliasing is on a different background than you think, in particular, the yellow star is anti-aliased correctly if the background was black, placing your code is the easiest way this is outside.

+2
source

Source: https://habr.com/ru/post/898219/


All Articles