Convert a bitmap into a byte array

There are a couple ways. ImageConverter public static byte[] ImageToByte(Image img) { ImageConverter converter = new ImageConverter(); return (byte[])converter.ConvertTo(img, typeof(byte[])); } This one is convenient because it doesn’t require a lot of code. Memory Stream public static byte[] ImageToByte2(Image img) { using (var stream = new MemoryStream()) { img.Save(stream, System.Drawing.Imaging.ImageFormat.Png); return stream.ToArray(); } } This … Read more

Passing android Bitmap Data within activity using Intent in Android

Convert it to a Byte array before you add it to the intent, send it out, and decode. //Convert to byte array ByteArrayOutputStream stream = new ByteArrayOutputStream(); bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); byte[] byteArray = stream.toByteArray(); Intent in1 = new Intent(this, Activity2.class); in1.putExtra(“image”,byteArray); Then in Activity 2: byte[] byteArray = getIntent().getByteArrayExtra(“image”); Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); … Read more

Converting a view to Bitmap without displaying it in Android?

there is a way to do this. you have to create a Bitmap and a Canvas and call view.draw(canvas); here is the code: public static Bitmap loadBitmapFromView(View v) { Bitmap b = Bitmap.createBitmap( v.getLayoutParams().width, v.getLayoutParams().height, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(b); v.layout(v.getLeft(), v.getTop(), v.getRight(), v.getBottom()); v.draw(c); return b; } if the view wasn’t displayed before … Read more

Load a WPF BitmapImage from a System.Drawing.Bitmap

How about loading it from MemoryStream? using(MemoryStream memory = new MemoryStream()) { bitmap.Save(memory, ImageFormat.Png); memory.Position = 0; BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = memory; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); }

java.lang.OutOfMemoryError: bitmap size exceeds VM budget – Android

One of the most common errors that I found developing Android Apps is the “java.lang.OutOfMemoryError: Bitmap Size Exceeds VM Budget” error. I found this error frequently on activities using lots of bitmaps after changing orientation: the Activity is destroyed, created again and the layouts are “inflated” from the XML consuming the VM memory available for … Read more

Display an array of color in C [closed]

Graphics rendering: I am used to win32 and Borland C++ environments, so I stick to it, but the differences on other environments are mostly only in class names. First some approaches: console/text modes You can use text graphics (ASCII art I think in English). Where point is represented by character. Intensity is made by more … Read more

Save bitmap to location

try (FileOutputStream out = new FileOutputStream(filename)) { bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap instance // PNG is a lossless format, the compression factor (100) is ignored } catch (IOException e) { e.printStackTrace(); }

How to convert a Drawable to a Bitmap?

This piece of code helps. Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_resource); Here a version where the image gets downloaded. String name = c.getString(str_url); URL url_value = new URL(name); ImageView profile = (ImageView)v.findViewById(R.id.vdo_icon); if (profile != null) { Bitmap mIcon1 = BitmapFactory.decodeStream(url_value.openConnection().getInputStream()); profile.setImageBitmap(mIcon1); }