bitmap
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 …
Create Bitmap from a byte array of pixel data
Its safe if you marshal.copy data rather than setting scan0 (directly or via that overload of BitMap()). You don’t want to keep managed objects pinned, this will constrain the garbage collector. If you copy, perfectly safe. The input array is managed and can be moved by the GC, scan0 is an unmanaged pointer that would …
How to make any view to draw to canvas?
Yeah, you can do this. Keep in mind, since you’re not attaching it to a layout, you’ll need to lay it out manually before drawing it: view.layout(0, 0, viewWidth, viewHeight); And unless you just know exactly what you want for those width and height parameters, you may also want to measure it first: int widthSpec …
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 …
Resize Drawable in Android
The following worked for me: private Drawable resize(Drawable image) { Bitmap b = ((BitmapDrawable)image).getBitmap(); Bitmap bitmapResized = Bitmap.createScaledBitmap(b, 50, 50, false); return new BitmapDrawable(getResources(), bitmapResized); }
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 …
Android: how to convert whole ImageView to Bitmap?
You could just use the imageView’s image cache. It will render the entire view as it is layed out (scaled,bordered with a background etc) to a new bitmap. just make sure it built. imageView.buildDrawingCache(); Bitmap bmap = imageView.getDrawingCache(); there’s your bitmap as the screen saw it.
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 …