I need to draw a bitmap on top of a completely rendered GLSurfaceView. By completely rendered I mean that the entire thing is filled with colorized triangles. Obviously the bitmap will hide the triangles underneath it, but I would like to minimize how much is hidden.
The bitmap is 64x64 pixels and has many empty areas that are translucent in the PNG file. When I draw the bitmap by making a square with two triangles, the translucent areas become black (the green areas in the picture above), perhaps because the app background is black. Is there an easy way to get the translucent areas to not affect the image (the second image above)? Do I need to create a complex set of triangles that exactly outlines the non-translucent parts when I render the bitmap?
I am developing on a Motorola Xoom, Android 3.0. Thanks for your time.
Use the alpha test.
Related
I want to apply the border to this custom view shape
which created by many canvas.draw...() in onDraw()
The border that i want to create and apply to my custom view should have equal range all the way with some distance from the custom view and it should also cover small circle in each slice.
Any idea how to make this?
Thanks.
This isn't so much an answer, but more of a recommendation. Take a look at the Porter-Duff modes available to you. Worst case you may need to do some per pixel image manipulation which should be fine as long as the view isn't animated.
On second thought, here's an idea: why not create two images: one large circle which will always draw behind everything and a second which will always draw behind the small circles. The large circle would just be the complete border you want displayed, whereas the small circles would actually only be a semi circle border, which would render on top of the large circle (covering the large circle border under it). The key would then be to rotate the small border circle depending on where it's located. I hippie that makes sense, but it should work and be very efficient too.
Another option would be to separate the rendering into white circles and slightly larger border color circles. If you render the slightly larger (border color) circles first, then render the normal circles (white) on top, then you won't have to worry about any rotations and it will render correctly if the small outer circles begin to overlap.
So the idea is similar to the first suggestion. You'll still need a large circle and small circle (both white), but in addition, you'll need slightly larger border colored large and small circles.
I hope this description is a little clearer, but I assume that you are comfortable enough with compound drawables to figure out the rest, given that you've gotten this far in making your view.
All the best implementing it, and feel free to ask for any clarification! :)
I'm writing an Android app that involves some 2D drawing operations. I am trying to use saveLayer and xfermode SRC_IN to draw the intersection of 2 images. It seems to work OK if I don't rotate anything, but if I rotate one of the images, it seems to treat the pixels outside the rotated rectangle bounding the image as opaque (part of the intersection), or more likely, as not part of the drawing operation (unaffected by the transparent pixels laid on top of it).
Below is a picture of what I'm talking about. The "5" and "3" images near the bottom are being "intersected" by drawing the "3" image (rotated) with xfermode SRC_IN on the "5". I have shown all three images on a gradient background to help visualize transparency.
After some thought, I suspect that the area outside the clipping rectangle of the "3" is not being treated as opaque, but rather simply not being treated as part of the drawing operation. What's interesting is that if I mark the layer as a software layer instead of a hardware layer the while number "5" shows up in the background instead of just the parts outside 3's clipping rectangle. I don't understand this.
How is the area affected by an SRC_IN drawing operation determined? (Normally it doesn't matter, but one unique feature of SRC_IN is that it has to turn opaque pixels transparent based on what is transparent in the image being drawn, so the overall size of that is drawn is important even though it normally wouldn't be.) How can I make the pixels outside the drawn area of the 3 be treated as not part of the intersection? Do I need to enlarge the clipping rectangle that is active when drawing the 3?
I have a transparent bitmap (clock face) that I redraw to mimic
a chronograph, and it works perfectly( overlaying different dials) use a base
empty faceplate PNG and draw the needles on top of it with a little trig/high school stuff
The problem: I need to loop thru this updating the values of the needles and overlaying
several dials., it works but the border gets grainy the more I loop thru it, if I use a non-transparent base faceplate it is fine... I've been trying all kinds of things/suggestions without success, I need the transparency to work for the overlaying.
Some resizing goes on as the final ImageView size where it is drawn can be different than the base faceplate size, tried createScaleBitmap, with a Matrix no difference stayed with the basic drawBitmap(bmp, rect1, rect2, myPaint)
Did use the ARG_8888 creating my bitmaps
have a method that returns the transparent bitmap with the needle worked out properly
I draw this on an ImageView with setImageBitmapm tried drawing on a bitmap first
but no difference
try to clear the bitmap before drawing the dials(PorterDuff.mode), no difference
Is there any trick or unknown way Android handles the transparent redrawing? Will setting Alpha to Zero make any difference? My Bitmap is already transparent.
I'm trying to make an app in Android in which you can put different tipes of clothes on different characters.To do this i have made a square on which i put a texture (the character) with transparency (so you ca see the background, arround him) and then i added another square where the texture is the piece of clothing.The problem is that both squares with their specific textures show the backgroud, but the second square does not show the square behind him.
I guess my question is how can i make the second square show the first square and the background on the transparent parts?
make use of the Alpha component. which adds transparency to the pixel.
Look at this linkvwhich help you better
I am new to OpenGL. How to set background image for OpenGL. Actually when I am rendering the square texture and normal square (means which is including with colors). Texture also change its color...
I don't completely understand your question, but there is no background image in OpenGL. If you want to have an image as background of your rendering, just draw a textured square covering the whole screen before drawing everything else.
In case you have depth buffering enabled, you should also make sure your background image doesn't write to the depth buffer, so that the other things you render after it are actually rendered on top of the background. This can either be done by rendering it at the far plane so it gets the maximum depth of 1 or by just disabling depht writes using
glDepthMask(GL_FALSE);
and of course enabling it again (using glDepthMask(GL_TRUE)) after it is drawn.
But of course OpenGL is no scene or image management system and has no notion of any persistent scene or images and forgets about anything after it has been drawn. This means, like everything else you have to draw this background image each frame before the other scene objects are drawn.