Convert view into bitmap with modification - android

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.

Related

What does it mean to convert a layout to image in android

I came across the following - How to convert linearlayout to image .
It converts a linear layout to an image. What is it exactly doing?
Is it like I press a button and it saves the screenshot of the app screen as an Image?
Is that what is meant by converting a LinearLayout to Image?
I think Android already convert view to Bitmap for show on screen. You can call view.getDrawingCache() and you can set on your imageview with bitmap.
Bitmap b = Bitmap.createBitmap(view.getDrawingCache());
bmImage.setImageBitmap(b);

upload image and draw rectangles using only one ImageView

Can I upload a picture (in a ImageView) and draw rectangles using the canvas in the same ImageView? all the examples I've seen so far used two. I wonder if you can use only one? if so, how?
If you are new to android.
Open android studio, .
File ->New->import Sample ,
search for image.
Choose basic render script, this will give you basics of image handling.
However for your usage, you can simply create a view with border and add imageview inside it.

How can I make an empty/invisible bitmap?

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,

Android Peformance Optimization - How to draw a cached bitmap back to a textview

Basically, I want to cache a frequently drawn text view to increase the performance of my application.
So, on first-time draw, I cached the text view into a bitmap type buffer, using the methodology in these posts - get bitmap from textview in android & Converting a view to Bitmap without displaying it in Android?
Now, on subsequent draw requests, I want to draw the saved bitmap buffer back to a text view.
But, I am not able to find specimen code for that. There is a lot of discussion on SO for saving a bitmap from the textview, but not much regarding drawing the bitmap back to text view !
Please help me if anybody has worked in this area before.
You can convert the bitmap into a drawable object and then use the setBackroung method.
Bitmap mBitmap;
Drawable mDrawable=new new BitmapDrawable(mBitmap)
textView.setBackground(mDrawable);
But, his method is deprecated. You might save your bitmap into resources as android documention suggests.
The code you need is here:
http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html
When loading a bitmap into an ImageView, the LruCache is checked first. If an entry is found, it is used immediately to update the ImageView, otherwise a background thread is spawned to process the image: ....

How to put other images on a photo Android

I take a photo in my Android app.
I want to put other images in that photo to create effects
like a ballon of conversation, a legend, and others.
After that I want to save this Image in another Bitmap.
I try put my photo as a background image, and put another ImageViews components under that and try to take a printScreen of my screen. But I think it isn't the best way to do what I Want.
Can anybody help me?
Sorry for my english
I think the best bet would be create a Canvas based on your photo (you'll need it as a mutable Bitmap) and then use the drawBitmap() to draw another bitmap onto yours (you'll have to pass it the offset and Xfer mode).
The original mutable bitmap will now contain the combination of of your images
You can try FrameLayout.
Just put the photo in the background, and then put ballon of conversation in front of photo.
If you want to combine photo and ballon effect, you could use Bitmap.
Just record the effect's coordinate.

Categories

Resources