How to save pixels displayed on the screen in mutable Bitmap - android

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.

Related

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: ....

Saving shapes on top of large images

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

Why would android forget some assets?

My Problem: Only one image will actually load from the assets folder. I have all the images there and when I try to access any of them I don't get an error. By actually load I mean it shows the image on the screen. When I load the other images the whole screen comes up white.
In every instance I am loading the whole image to the whole screen.
If I were to put the image as a fourth its size in the middle of the screen then there is a white rectangle there. The image is supposedly in the .apk because I don't get an error for the game trying to find it. However if I were to load this one image then everything words fine.
The one image that works find is a .png image and I tried to load the others as a .png but it does not work.
Any advice on where to start?
I load the images through the AssetManager.readAsset() as an input stream and then use the bitmap factory to get the image as a bitmap. Afterwards I load the bitmap into open gl and draw the region I want. However, the problem is only my first image I ever started using works at the moment. Could there be something wrong with a file that eclipse generates?
Some png bug android.
Just try to open them and save them with gimp. Sometimes it solves the problem.
Finally found the solution.
Turns out that one image that worked had a bit depth of 32 and the other ones only had a 24 bit depth.
The solution is to open up the image in gimp, add an alpha channel (makes it 32 bit), and save it as a .png file. Then read the details and it should say it is 32 bit.
Thanks guy! :)
Also note that images have to be by power of 2. For example it needs to be 1024 by 1024.

Drawing on Canvas with an image on background and save image

I want to open an image from SD card, while image is on display I want to draw on it using touch and motion events and save the image back. Any help or pointer to any sample code would be of great help.
I'm sure there are many ways, and many ways better than this but this is how I would do it:
Basically in my understanding you need to open the image from an SD card to a bitmap to a imageview in your activity. http://www.higherpass.com/Android/Tutorials/Working-With-Images-In-Android/2/
Then you need to go pixel by pixel and get each value for the color so you can change it in an onTouchEvent. http://developer.android.com/reference/android/graphics/Bitmap.html See getPixel() and setPixel()
The user gets to draw stuff on it. You need some way to capture the motion event, and change your data model of the image you just got by getting all of the pixels. You could use a surfaceview or something similar. Android: creating a Bitmap with SurfaceView content
Finally you need to save the picture to the SD card. Android write to sd card folder
Hopefully this helped

Access to separate pixel of JPEG image in Android

In my android project I need to get access for each separate pixel of JPEG image. Image created by built-in photo application. I try to convert JPEG into Bitmap class instance, but OutOfMemoryException was thrown. After searching info about this problem I have found the following solution: resize image! But quality of image is important in my project, and i can't resize it. Is there any way to get each-pixel access?
if your image is too big and the quality is important i suppose the best way is to use or create your own class to cut the image in zone (eg : 50*50 px) , there is several jpeg info class in the internet to help you understand how work jpeg files.
Have you tried BufferedImage ? (it's not in the sdk but maybe usable)
The nature of jpeg makes it very hard to get the value of a single pixel. The main reason is that the data is not byte aligned, another is that everything is encoded in blocks that can be of sizes 8x16, 16x8 and 8x8. Also, you need to handle subsampling of chroma values.
If the image contains restart markers, maybe you can skip into the image so you don't have to decode the whole image before getting the pixel value.

Categories

Resources