How can I make an empty/invisible bitmap? - android

Is there any way to create a bitmap that, when you use it in on a view in the setImageBitmap method, it looks like no image was actually set at all?
EDIT: To clarify, I want the bitmap to not be visible, or it can be visible, as long as its nothing, as long as the user cant see it im happy.
EDIT2: I cannot use setVisibility because my ImageView also has a setBackground attribute that I want to remain visible. If I set the view to invisible, the background AND the bitmap image are affected, and I dont want that. I only want the bitmap image to be invisible.

You could call imageView.setImageBitmap(null) to remove the current image and keep the background.

You could make a 1x1 pixel bitmap which is nothing but empty canvas (in photoshop perhaps), then use the draw9patch tool to make it stretch.
EDIT: If you just need it not to draw, you can call setVisibility(View.INVISIBLE) on the view like so:
imageView.setVisibilty(View.INVISIBLE)

← Image is here
above is a 50X50 transparent image created in photoshop download and use it,

Related

How can I make an ImageView that doesn't draw the transparent parts of the image?

I need my custom ImageView (called ItemAnimationView) to not draw any part of its image that is transparent.
I use this class for a lot of instances and for a lot of different images, so it would be best if I could solve this problem only with methods that I can call on ImageView, as editing all the different images manually won't work.
So is there some kind of ColorFilter that does not only filter out one certain color but instead every pixel that is transparent to any degree?
Also it would be quite convenient if there was a way to do this without accessing the actual bitmap, as the only lines of code I use for the view so far are
setImageResource(item.getResourceID());
and some animating, so I don't have the associated Bitmap object.
I achieved the desired effect using a ColorMatrixColorFilter with this matrix:
{1f,0f,0f,0f,0f,
0f,1f,0f,0f,0f,
0f,0f,1f,0f,0f,
0f,0f,0f,256f,-256*254};

Convert view into bitmap with modification

Requirement : User should be able to share the layout(which has image and text) as image.
Solution which i tried:
Bitmap b = Bitmap.createBitmap(myView.getWidth(), myView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
myView.draw(c);
This is working as expected. But I have few issues.
Issues:
I have few buttons and text which i don't want to convert as image. Also,I want to add my App logo as a watermark on the Bitmap image.
My solution for the above issue:
Before converting to Bitmap Image, Change visibility state of Button and Logo Image
Create one more layout behind the actual layout in a sharable image format. Use this layout to get Bitmap Image (not cool efficient, But easy way)
My question:
The above solutions are valid?
Or Is there any other method to do in an efficient way?
PS: I am not looking for code. :)
Issue 1: yes, you have to change visibility of those views you don't want them to be converted into image(the easiest way).
Issue 2: for adding a watermark, you can just draw it on canvas(you can use canvas.drawBitmap to do it) instead of putting it in the layout.

ImageView - change image and wait for layout to finish update

I am changing a image in an ImageView while already displaying the image. This COULD leed to a change of the layout as the image may be of a different size.
I draw some arrows/marks to special points on an image and animate them... My problem now is, that I need to wait for the setImage... function of the ImageView to finish so that I can calculate all necessary data under consideration of the new image...
first update of image
On my first displayment of my view I wait with ViewTreeObserver().addOnGlobalLayoutListener of my ImageView and calculate all points afterwards...
on following updates of the image (view is already visible)
I don't know how to do it here...
How can I wait for setImage... to finish drawing and only afterwards do my custom work?
Try listening to the ImageView's layout change instead.
Call addOnLayoutChangeListener(...) on the ImageView.
You can recalculate the points every time onLayoutChange... is called.
Actually, I found the solution and it was quite obvious...
Exactly for this reason, view.post(...) exists and this works quite good... This way, I don't need the OnGlobalLayoutListener at all...

How to fill the drawable region in an imageView with another drawable?

so I'm trying to find the region of the current image in the ImageView and fill that region with a different image. Here is the original image Empty Circle inside an imageView. The imageView has a drawable of a circle inside. Then I'm trying to make it into something like this Circle filled with image inside an ImageView when a user chooses an image. I don't want to manually Photoshop a circle image. I am just hoping to fill the region with another image. I have tried SRC_IN method from AlphaComposite, but for android, I can't convert from BitMap to graphics2D. If anyone knows how to solve this using the BitmapFactory in android, I would really appreciate your help. Thank you.
The other solution besides Bitmaps, may be too simple for whatever you are trying to achieve otherwise I think it would have occurred to you. I'm just pointing it out in case you have "code blindness" and are trying to over-engineer the solution because you've worked on it for too long (we've all done it)
It is to have that circle/shape image saved as a png with the area you want filled being transparent then set it as the drawable for an ImageView (etc.) then in a RelativeLayout lay this view over the image you want to fill the area and apply a transparent background to the shape view OR simply set the fill image as the background for the shape view.

Is there a listener for when ImageView renders its image?

I want to measure the performance of my image loading, and so I'd like to know exactly when the image bitmap has finally been rendered on screen. Is there a listener for this?
You should consider using profiler for this: http://developer.android.com/tools/debugging/debugging-tracing.html

Categories

Resources