Immutable bitmap crash error

You have to convert your workingBitmap to Mutable Bitmap for drawing on Canvas. (Note: this method does not help save memory, it will use extra memory) Bitmap workingBitmap = Bitmap.createBitmap(chosenFrame); Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true); Canvas canvas = new Canvas(mutableBitmap); This answer helps don’t waste memory Convert immutable bitmap to a mutable bitmap

Android: How to rotate a bitmap on a center point

I hope the following sequence of code will help you: Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config); Canvas canvas = new Canvas(targetBitmap); Matrix matrix = new Matrix(); matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2); canvas.drawBitmap(source, matrix, new Paint()); If you check the following method from ~frameworks\base\graphics\java\android\graphics\Bitmap.java public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean … Read more

Use Picasso to get a callback with a Bitmap

Found the answer on github in case anyone is wondering: private Target target = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } } private void someMethod() { Picasso.with(this).load(“url”).into(target); } @Override public void onDestroy() { // could be … Read more

Android bitmap image size in XML

Only API 23 or later Just use <item android:width=”200dp” android:height=”200dp” android:drawable=”@drawable/splash_background” android:gravity=”center” /> instead <item android:left=”200dp” android:right=”200dp”> <bitmap android:src=”@drawable/splash_background” android:gravity=”center” /> </item>

How to create bitmap from byte array?

You’ll need to get those bytes into a MemoryStream: Bitmap bmp; using (var ms = new MemoryStream(imageData)) { bmp = new Bitmap(ms); } That uses the Bitmap(Stream stream) constructor overload. UPDATE: keep in mind that according to the documentation, and the source code I’ve been reading through, an ArgumentException will be thrown on these conditions: … Read more

BitmapFactory.decodeStream returning null when options are set

The problem was that once you’ve used an InputStream from a HttpUrlConnection to fetch image metadata, you can’t rewind and use the same InputStream again. Therefore you have to create a new InputStream for the actual sampling of the image. Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(is, null, options); Boolean scaleByHeight = Math.abs(options.outHeight … Read more

Android: How does Bitmap recycle() work?

The first bitmap is not garbage collected when you decode the second one. Garbage Collector will do it later whenever it decides. If you want to free memory ASAP you should call recycle() just before decoding the second bitmap. If you want to load really big image you should resample it. Here’s an example: Strange … Read more

Fastest way to convert Image to Byte array

There is a RawFormat property of Image parameter which returns the file format of the image. You might try the following: // extension method public static byte[] imageToByteArray(this System.Drawing.Image image) { using(var ms = new MemoryStream()) { image.Save(ms, image.RawFormat); return ms.ToArray(); } }

android: create circular image with picasso

Research a bit before as there are answers available. Anyhow, follow This Link and read it carefully to know how to use it. try this: import com.squareup.picasso.Transformation; public class CircleTransform implements Transformation { @Override public Bitmap transform(Bitmap source) { int size = Math.min(source.getWidth(), source.getHeight()); int x = (source.getWidth() – size) / 2; int y = … Read more