Saving shapes on top of large images - android

I'm creating somekind of 2D image editor in Android and I have the big problem of big files don't fit in memory.
I need to zoom in/out the image put some shapes and then save it.
My question is:
How can I load the image and save it without getting out of memory?
I've been reading about bitmapregiondecode and the sample technic but there's must be another solution. How can I save the image if I always use regiondecode?
The images need good detail quality because it's architectural images... and the lines must be well defined.
I'm new to this, help me please.

Note two things while dealing with images:
tempBitmap = Bitmap.createBitmap(bit);
clone the bitmap which you are using for zoom and other operations but wont use the original because it looses its clarity when you save;
when done with bitmap give
bit.recycle();
to release the memory space

Related

Image scrolling app - bitmap too large to be uploaded into a texture

I am working on a very simple app that shows one jpg, which is scrollable on vertical axis.
I would like this image to be very large(20000x1000 px), however, when I try to run the app on my device, it says that "bitmap too large to be uploaded into a texture".
Is there a way to display the image of such size in an android app?
If not, would it be possible to divide the image into segments, and after I scrolled to the bottom
of one segment, I would proceed to another?
To quote the answer for your question here:
All rendering is based on OpenGL, so no you can't go over this limit.
Note that this would take a huge amount of memory. With such big
images, if you want to zoom in out, and in a mobile environement with
heavy memory constraints, you should setup a system similar to what
you see in google maps for example. With the image split in several
pieces, and several definitions.
You could split the images into let's say 128x128 chunks. Add them to an array, and loop the array to create and fill an ImageView with the image that is currently served.
some pseudocode would be: (excuse me, I've been programming a PHP application the past few days)
Private BitMap[] imageArray = {your bitmaps from internal or external storage};
For(BitMap bm in imageArray) {
// create a new image view here, use the correct layout params or use a parrent grid view.
imageView.setBitMap(bm)
}
now once again, I am 0% sure about that pseudo code, but it should help you along.

How to save pixels displayed on the screen in mutable Bitmap

I am trying to make an Android aplication, in which you take a foto. You zoom in to a desired region of the foto then you copy this region into a Bitmap for further processing.
I tried to make a new mutable Bitmap to copy the Bitmap from ImageView object that holds the picture but I receive out of memory error.
Another problem is how do I copy only the desired region?
I have the impresion that if you copy one by one each pixel you copy the whole picture.
I am using Android 2.2.1 API level 7.
I need only some tips to search for, till now the search of Bitmap documentation was unsuccesfull.
Thank you in advance.
I copied the data hidden in the cache:
mImageView1.setDrawingCacheEnabled(true);
mImageView1.buildDrawingCache();
mImageView1.getDrawingCache();//this is the data I need it.

setting 3000X2000 pixel image as canvas background without resizing and avoiding outofmemorybound

i was wondering if is it efficient and possible to set 3000X2000px image as canvas background without resizing it and without getting the memory error.
because i want the real size image and pan around it.
using webview is not an option.
Currenty i tried to the set the background by using a folder structure named "Drawable-nodpi" and then assinging the bitmap image with decoderesource method.
Such a huge picture will inevitably cause outofmem exceptions on at least some devices. So I think that you need to dynamically scale and load only parts of the image that needs to be displayed, possibly with a caching mechanism.
Unfortunately, I don't know about any library components for Android that does this for you out of the box, but I'm pretty sure that you can find some nice articles on this topic.

Using BitmapRegionDecoder to load large images

I am trying to load a very large image from the internet in an android tablet application. I know how to load a smaller size sample but have noticed it hampers the resolution of the images. The android docs tell me about the BitmapRegionDecoder to help loading the images in tiles but there does not seem to be much documentation on it.
I am doing something like this:-
BitmapRegionDecoder decoder = BitmapRegionDecoder.newInstance(inputstream, false);
I understand that i have to loop through the below code as many times as required to get the entire image by passing different rect objects
region = decoder.decodeRegion(new Rect(0, 0, 50, 50), null);
But i fail to understand how to put all these bits in the right position in one imageview. Any example would be really helpful
What you are trying to do sounds like you want to defy the purpose of the region decoder. You could as well try to load the whole huge bitmap instead of pieces and joining them together. In the end you would risk an out of memory error either way. The point of the region decoder is getting just a clip from a huge bitmap. One use case could be a map view that can be panned with swipe gestures. You would calculate only the currently visible clip of the bitmap load that with the region decoder and display that in your map view. What you need to do is in fact loading a scaled version.
Yes you can use a BitmapRegionDecoder to view large Images based on Tiles
This guy here implemented a TileBitmapDrawable Class, that you can hook to your imageview:
https://github.com/diegocarloslima/ByakuGallery

Merging multiple picture to form one complete picture in Android

i would like to know whether is it possible to merge several images to form one complete image. For my case, is a floor plan that is split in 18 small images and i would like to merge them into one. I had one idea but not sure whether is it workable. My idea is this:
I would first place the top left most image first, with the x and y coordinates as (0,0).
Next for the subsequent images (right/bottom of this first image), using the width and height of the image, i would find out the coordinates where the next image would be placed. Doing this i presume would required 18 ImageView to achieve that.
Btw, these 18 images are .gif format and so do i need to like convert them to Bitmap or something before i can display them using ImageView?
You could merge the images to a bigger images by drawing the small images to a canvas associated with the resulting big bitmap
Canvas c=new Canvas(result_bitmapenter);
and then draw your small images onto the canvas
c.drawBitmap(small,...);
But that might not be the best way as big images eat lots of memory - perhaps you should concider dynamic loading instead of merging then
Yes its possible create a Bitmap object large enough to hold the whole floor plan and use Canvas to paint them into to the large bitmap. Be sure to cache it or you'll be recreating it every time and you'll have to convert it to png for compatibility with older devices.

Categories

Resources