I'm displaying big images in my app and want to crop them. The user can rotate and scale the images and select a region he wants to crop.
How can I crop out a 10000x10000 region, starting at point (1000, 1000) for example from a 20000x20000 image? For loading parts of an image I would use BitmapRegionDecoder but I don't know how to combine them to a new image again. Any ideas?
Rotation is another problem, this won't work with the BitmapRegionDecoder , but I would already be glad to have a solution without rotation...
I would need a memory friendly way that is more than just following:
Bitmap bitmap = loadFullBitmapIntoMemory();
Bitmap cropped = Bitmap.createBitmap(bitmap, 1000, 1000, 10000, 10000);
I want to avoid to load the full image into memory...
Related
I'm using library which takes bitmap.
At first I'm showing bitmap in ZoomableImageView. But after scale, zoom I need to send to the library only visible part of image view.
Here is my code to create scaled bitmap with matrix:
Bitmap result = Bitmap.createBitmap(originalBitmap, 0, 0, originalBitmap.getWidth(), originalBitmap.getHeight(), matrix, true);
However, the user may be constantly zooming in on the image, and what happens is that this code is executed frequently and my application freezes. Is there any way to prevent this or is there a better way to create scaled bitmap ?
Please help me.
Hi so I need a user to be able to upload a profile picture that I have to re-size and put in their profile. The "area" for the profile picture is a 100x100 square since its on an android device. Lets assum someone posted a 300 x 600 or 600 x 300 how would I convert / crop an image to fit a 100 x 100 square and look good as a profile image? I feel like this is more of a conventional question.
I do know how to resize and crop bitmaps just can't figure out how would I go about it.
for instance
android.graphics.Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
Well if you are not against wasting some of the space, I recommend just doing basic scaling. Divide the larger size by 100 gives the scale factor. Then divide by that on each dimension and you have a picture with the right aspect ratio that fits your area.
I have created a frame animation comprised of 12 images in an XML file. Do I need to scale each image before adding to the animation, to avoid the Out of Memory error? If I make the images smaller, I do not get the out of error. How can I scale the images to build the animation or is that necessary? I also tried to set scaling in the imageview.
//Firstly add Scale Bitmap code and after that use animation.
photoBitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, true);
imageView.setImageBitmap(photoBitmap);
// Animation code
It seems that setting a wallpaper on Android just doesn't work in any useful way.
If you get an image from your phone and set it as the wallpaper, it's way too big for the screen
If you resize it (either using a createBitmap() function that allows you to specify size, or the ridiculously useless createScaledBitmap()) it goes all jaggy and out of focus
If you use some freaky hacks to fix the quality of the image, it's better, but still not perfectly clear by any stretch.
If you attempt to get the current wallpaper and set that, it still seems to make it too big. It appears to give you the original image file, forcing you to resize it, which doesn't work.
Now, the phone's internal software is perfectly capable of resizing an image to be smaller with no reduction of quality. Why does it not share this functionality?
WallpaperManager wallpaperManager = WallpaperManager.getInstance(Spinnerz.this);
// gets the image from file, inexplicably upside down.
Bitmap bitmap = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "DCIM/Camera/Zedz.jpg");
// use some rotation to get it on an angle that matches the screen.
Matrix bitmapTransforms = new Matrix();
bitmapTransforms.setRotate(90); // flip back upright
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),bitmapTransforms, false); // create bitmap from bitmap from file, using the rotate matrix
// lets set it exactly to the resolution of my Samsung Galaxy S2: 480x800 pixels.
// This function appears to exist specifically to scale a bitmap object - should do a good job of it!
bitmap = Bitmap.createScaledBitmap(bitmap, 480, 800, false);
wallpaperManager.setBitmap(bitmap);
// result is quite a jaggy image - not suitable as a wallpaper.
PIC:
Try this ,
Display d = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = d.getWidth();
int height = d.getHeight();
I'm making a game, while a friend of mine is designing all the graphics. All graphics are PNG files, and drawn and animated using Bitmaps and Canvas in SurfaceView.
One piece of animation involves the main character moving around during the menu, which uses 35 large PNG files. It's too big to have it all loaded in memory, and loading each file when needed is too slow for what he wants. So, what can I do to make this work?
OPTIONS THAT DON'T WORK
Making the image smaller. Making the image smaller than what he wanted won't fly. Anything less than original quality won't fly either.
OPTIONS WE'RE LOOKING INTO
Making the animation a video. However, I don't know how to take a video and turn it into an interface.
My code:
Matrix matrix = new Matrix();
matrix.postScale(scaleFactorX, scaleFactorY);
penguin = BitmapFactory.decodeResource(getResources(), R.drawable.fish_01);
penguin = Bitmap.createBitmap(penguin, 0, 0, penguin.getWidth(), penguin.getHeight(), matrix, true);
canvas.drawBitmap(penguin, canvasWidth - penguin.getWidth(), canvasHeight*0.02f, null);