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.
Related
In Android, is there a clean way to display only a given part of a bitmap in an ImageView (for example a single sprite of a sprite sheet), without having to :
Manually split the bitmap png into small pngs (=> more drawables embedded in the app, tedious manual operation possibly leading to bugs, or loose the spritesheet).
Have small pngs used in the ImageViews, with the sprite sheet being generated (=> complicated)
Create "dirty" subclasses for ImageView, Drawable, etc (=> the more we use Android API "ASIS" the better)
Programmatically create sub-bitmaps of the big bitmap (=> We have to do all the work programmatically)
For instance I have tried creating an ImageView of width/height of 40dp, and setting its drawable as a ClipDrawable displaying only the part of the bitmap I wanted, but it did not go well :
the clipped part did not fill the parent when using Gravity.CENTER when creating the ClipDrawable.
The whole "big" PNG was displayed when using Gravity.FILL.
Furthermore this solution is feasable with a simple sprite sheet (for example 2*2 sprites), but I do not think it is possible when using something like a 4*4 sprite sheet. I think ClipDrawable is not meant for such a use.
Isn't there something "clean and easy" like in OpenGL where you can set a texture Id, and set the texture coordinates to display only part of the texture? Considering my researchs I think the best solution is to manually split the big bitmap with Bitmap.createBitmap, when I'd rather ask before starting something like that.
PS : I consider using SpriteSheets because of OpenGl, although my "menus" are developed using Android APIs, hence using ImageView.
Are you familiar with Canvas at all? I think that is another way that would work for you.
You create one bitmap in memory, then use drawBitmap to draw just the current chunk you want.
Here is a snippet from the manual:
public void drawBitmap (Bitmap bitmap, Rect src, Rect dst, Paint paint)
This function ignores the density associated with the bitmap. This is because the source and destination rectangle coordinate spaces are in their respective densities, so must already have the appropriate scaling factor applied.
Parameters
bitmap The bitmap to be drawn
src May be null. The subset of the bitmap to be drawn
dst The rectangle that the bitmap will be scaled/translated to fit into
paint May be null. The paint used to draw the bitmap
I'm new to Android (and Java for that matter), and I'm making a simple game. I'm stuck.
My problem is this:
I have 2 png images (a background and foreground) that take up the whole screen on startup. I now want to be able to set the width of the "drawn portion" of the foreground to the x-coordinate of ON_DRAG. My control method works fine; it's used like this:
g.drawRect(0, 0, scene.getLine(), g.getHeight(), Color.GREEN);
where scene.getLine() returns the x-value of the touch. So at this point I can draw a green rectangle above my images. But what I actually want is for those rectangle dimensions to "punch a hole" in my top-layer png (so the background is revealed beneath). I do not want to scale the foreground.
I have tried clipRect, but it doesnt work because I have other images that need to be drawn on top of these two, and clipRect prevents this. I have looked at a bunch of "PorterDuffXfermode" code, but cannot understand how to apply it to my situation, and cannot make it work. i.e. I can make a Paint with the PorterDuff "SRC" mode set, but I dont know how to define "source" and "destination" images so the Paint will work its magic. A final consideration with this is that even if the PorterDuff would work, Im not sure it would be practical given that I want this thing to run at 60fps.
Any suggestions?
Thanks.
You can call canvas.save() before a clip and canvas.restore() after your drawing to return the canvas to the sate it was in before you stared. Then you can draw your additional images.
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.
I have two bitmap overlapped .The top bitmap is transparent and when user touch to screen i copy pixels from another bitmap to top bitmap.My goal is to give to users the feeling of erasing image with touching to see another image.However it is not working properly especially when user drags his finger too fast on the screen.I made a few tests and i beleive drawing bitmaps to the canvas every time cause the lag but i don't know how to fix it.
It looks like a Canvas or Bitmap isn't redrawn until you wipe it yourself. That means you just have change the alpha value of the pixels in the top Canvas/bitmap/thingy that are being "painted" rather than redrawing the entire canvas for every update.
I need do draw on Android's Canvas using Blur effect,
it is a very simple feature,
I need to draw a circular area, which is blurred (the foreground) and the background transparent, I can do everything with manipulating the colour alpha to do it with custom transparency but I need it to be blurred instead of transparent..
any ideas?
(For those who are coming back, though this is an old question)
On the Paint object which you are using to draw the Color, set
paint.setMaskFilter(new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL))
Then, in Android Manifest.xml, set
android:hardwareAccelerated="false"
for your activity
(Blur doesn't work when hardware acceleration is true)
For more explanation refer
Android BlurMaskFilter has no effect in canvas.drawOval while text is blurred
If you're not gonna need to manipulate it afterwards you could just draw to a buffer and blur it yourself pixel by pixel, then blit that buffer to screen when you need to paint it.
Or this: http://developer.android.com/reference/android/graphics/BlurMaskFilter.Blur.html
Take a look at this: Android, Blur Bitmap instantly?
Again I would recommend you first to draw into a bitmap. Scale it down (try different sizes), and the scale it back up to the original size (either as a new bitmap or if you use hw acceleration do it while you draw).