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);
Related
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.
enter image description hereI am using Canvas to draw circles and lines. I want to display small circles inside the canvas in particular position. For that, i have created a circular drawable xml file and i have converted that xml into Bitmap and displaying over the Canvas and for that i am using canvas.drawBitmap() method.
But i want to display a textview inside that Bitmap but textview is getting displayed above that Bitmap using canvas.drawText(). I want to display the text inside the Bitmap.
You can use TextDrawable library, and found it to be very useful.This light-weight library provides images with letter/text like the Gmail app.
It extends the Drawable class thus can be used with existing/custom/network ImageView classes. Also included is a fluent interface for creating drawables and a customizable ColorGenerator.
Click here for example on github
Forget Canvas, draw an xml.
First convert text in svg on line i.e :
_ https://framavectoriel.org/ (only 4 police)
_ https://www.janvas.com/v6.1/janvas_app_6.1_public/index.html (not free)
Secondly, convert svg in xml here :
http://a-student.github.io/SvgToVectorDrawableConverter.Web/
And then, you have your text in a bitmap
*If you don't know how to save the svg on framavectoriel.org, click on the button, copy the lines and save it with svg extension.
Is there any way to get an image being pointed by an android layout and modify it before it is receceived by the requester?
For example if I have an image view like:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/myimage.png"
/>
Is it possible to register to any hook (or any other way) where I could modify the image before the ImageView receives it?.
Trying to clarify a bit more the question:
1) The ussual way android works:
The app runs, and reads a layout with an imageview requesting #drawable/myimage.png
The image is loaded and provided to the imageview to show it
2) What I would like to try or accomplish:
The app runs, and reads a layout with an imageview requesting #drawable/myimage.png
I previously, somehow, told android to send me the image/stream before
providing it to the imageview. I modify it
I return the modified image and it is shown in the imageview.
Do anybody know if this is possilbe? I have seen offuscators like dexguard that can do this. Any tip would be really helpful because I haven't found any way to do it after some days of investigation.
Cheers.
You will need to extract bitmap from resources
Modify the bitmap
Apply modified bitmap to imageview through java code
These snippets might help
//extract bitmap from drawable resources
Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.drawable.icon_resource);
//modify bitmap code here
//apply modified bitmap to image view
imageview.setBitmap(icon);
Here is an example of what I need to do:
First of all I convert the image into bitmap and then set it as background to a relative layout. And i know these four coordinates.
Then how can I get the image inside the box and set it to another layout as background?
Try to use Picasso when you are dealing with Images.
This is the link
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.