Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Why am I getting back the same Bitmap even after compressed?

$
0
0

I have the following code trying to compress a bitmap and use it for uploading.

//1 Bitmap bitmap1 = BitmapFactory.DecodeByteArray(imageFileByte, 0, imageFileByte.Length);
//2 byte[] compressedData = null;
//3 using (var stream = new MemoryStream())
//4 {
//5 bitmap1.Compress(Bitmap.CompressFormat.Jpeg, 50, stream);
//6 compressedData = stream.ToArray();
//7 }

//8 //load compressed bitmap from memory
//9 using (var anotherStream = new MemoryStream(compressedData))
//10 {
//11 var compressedBitmap = BitmapFactory.DecodeStream(anotherStream);
//12 }

When I debug, bitmap1 on line 1 shows 3021330 bytes, when come to the compressedData on line 6, it did shrink to 70128 bytes. Now I want to convert again the compressedData to a bitmap again since it is a byte array but not a bitmap, when it comes to line 11, the compressedBitmap shows exactly same number of byte with the bitmap 1. How can I actually use the bitmap that has already been compressed? Is it possible to compress a bitmap and save the compressed one as a bitmap again? Thanks for any comment.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>