create Bitmap from byteArray in android

You need a mutable Bitmap in order to create the Canvas. Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length); Bitmap mutableBitmap = bmp.copy(Bitmap.Config.ARGB_8888, true); Canvas canvas = new Canvas(mutableBitmap); // now it should work ok Edit: As Noah Seidman said, you can do it without creating a copy. BitmapFactory.Options options = new BitmapFactory.Options(); options.inMutable = true; Bitmap … Read more

view.getDrawingCache() is deprecated in Android API 28

Two ways to get bitmap of view Using Canvas Using Pixel Api Canvas Java Bitmap getBitmapFromView(View view) { Bitmap bitmap = Bitmap.createBitmap( view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888 ); Canvas canvas = new Canvas(bitmap); view.draw(canvas); return bitmap; } Bitmap getBitmapFromView(View view,int defaultColor) { Bitmap bitmap = Bitmap.createBitmap( view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888 ); Canvas canvas = new Canvas(bitmap); canvas.drawColor(defaultColor); view.draw(canvas); … Read more

BitmapFactory.decodeResource returns a mutable Bitmap in Android 2.2 and an immutable Bitmap in Android 1.6

You can convert your immutable bitmap to a mutable bitmap. I found an acceptable solution that uses only the memory of one bitmap. A source bitmap is raw saved (RandomAccessFile) on disk (no ram memory), then source bitmap is released, (now, there’s no bitmap at memory), and after that, the file info is loaded to … Read more

Finding specific pixel colors of a BitmapImage

Here is how I would manipulate pixels in C# using multidimensional arrays: [StructLayout(LayoutKind.Sequential)] public struct PixelColor { public byte Blue; public byte Green; public byte Red; public byte Alpha; } public PixelColor[,] GetPixels(BitmapSource source) { if(source.Format!=PixelFormats.Bgra32) source = new FormatConvertedBitmap(source, PixelFormats.Bgra32, null, 0); int width = source.PixelWidth; int height = source.PixelHeight; PixelColor[,] result = new … Read more

How can I transform a Bitmap into a Uri?

Here is the Colin’s Blog who suggest the simple method to convert bitmap to Uri Click here public Uri getImageUri(Context inContext, Bitmap inImage) { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, “Title”, null); return Uri.parse(path); }

How to Display a Bitmap in a WPF Image [duplicate]

I have used this snipped now to convert the Bitmap to a ImageSource: BitmapImage BitmapToImageSource(Bitmap bitmap) { using (MemoryStream memory = new MemoryStream()) { bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp); memory.Position = 0; BitmapImage bitmapimage = new BitmapImage(); bitmapimage.BeginInit(); bitmapimage.StreamSource = memory; bitmapimage.CacheOption = BitmapCacheOption.OnLoad; bitmapimage.EndInit(); return bitmapimage; } }