Android. How to get scaled bitmap? - android

I'm using custom zoomable image view. Here is example of such a view: https://github.com/jsibbold/zoomage/blob/master/zoomage/src/main/java/com/jsibbold/zoomage/ZoomageView.java.
Everything works well, but I need to get a new bitmap when changing the scale. That is, I need to get a scaled bitmap.
To do this, I added to the method onScale listener. But I don't understand how to get scaled bitmap.
Please help me.

Related

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.

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: fast image slider with *correctly rotated* images

There are a lot of examples how to use ViewPager as an image slider, but I haven't seen any that handle the problem of correctly rotated images:
Now actually I have a solution for this, but the problem is that the image sliding is painfully slow when the image size is over about 3000*1500 pixel because of the extra rotation step:
The ImageView itself doesn't care about the correct orientation when setting an image via
setImageURI or setImageBitmap.
This means you first have to find out the correct orientation yourself and then eventually do a
matrix.postRotate(rotation)
and create a new bitmap using
Bitmap.createBitmap(srcBitmap, 0, 0, srcBitmap.getWidth(),
srcBitmap.getHeight(), matrix, true);
This additional bitmap creation really slows it down.
If the was a method to load an image "rotated on the fly" ? Sth. like BitmapFactory.decodeStream(stream,matrix) ?
I have also tried to increase the ViewPager.setOffscreenPageLimit value to 3, but with
the result of "java.lang.OutofMemoryError: bitmap size exceeds VM budget" errors.
Somehow it must be possible because with the default "Gallery" app the sliding is really fast even with very large images...But I guess this not a trivial task ?
Finally I found the solution: to get a responsive, fast & fluid image sliding behaviour two things need to be done:
Do the bitmap loading in the background using AsyncTask
https://developer.android.com/training/displaying-bitmaps/process-bitmap.html
Load a downsampled version of the bitmap using BitmapFactory.Options.inSampleSize (calculated using the ratio between ViewPager's and the Bitmap's dimensions)
https://developer.android.com/training/displaying-bitmaps/load-bitmap.html

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

Android: How to save the filtered image as a file?

all
I want to make a filter just like what instagram's. I use an ImageView with colorFilter to accomplish the effect, but I don't know how to save the filtered image as a file. If I savethe bitmap directly, the original bitmap was stored without filter effect. If I store the imageview's pixels, its size is not as the same as the bitmap. And I dont want to calculate pixel by pixel for a new bitmap for effect reason. I was blocked on this problem for days.Would anybody help me ?
Thanks.
BR
QiuPing
I think this might be of help to you. Check out the Saving Internal and Saving External sections.
http://developer.android.com/guide/topics/data/data-storage.html
You're going to want to get your image into a bitmap, like this:
Save bitmap to location
I found a better solution now.
I used a Canvas on the original bitmap, and paint with ColorMatrixColorFilter.
Different ColorMatrixColorFilter take different use. Changing brightness, changing saturation, changing contrast. Make combinations, then filters were created.

Categories

Resources