Saving a bitmap into a MemoryStream

.NET is a managed environment: specifically, memory allocation is usually managed on your behalf by the .NET runtime. You don’t typically need to allocate the memory yourself. Sometimes, however, you do need to inform the runtime when you’ve finished with memory by using Close() or Dispose(). The using statement can be used to wrap a …

Read more

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

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