Convert Image into byte array in Xamarin.Forms

后端 未结 7 991
春和景丽
春和景丽 2020-12-20 21:47

I need to pass an image (Image _thresholdedImage) like byte array... I don\'t know how I can do this. Any idea? Thank you!

_thresholdedImage.Sou         


        
7条回答
  •  情深已故
    2020-12-20 22:01

    I was unable to convert it in X.Forms, instead I use the following code with a dependency service. Thank you to all.

        public async Task GetBytesFromImage(string filePath)
        {
            ConvertImageToBW(filePath);
    
            // Create another bitmap that will hold the results of the filter.
            Bitmap thresholdedBitmap = Bitmap.CreateBitmap (BitmapFactory.DecodeFile(filePath));
    
            thresholdedBitmap = BitmapFactory.DecodeFile (thresholdedImagePath);
    
            byte[] bitmapData;
            using (var stream = new MemoryStream())
            {
                thresholdedBitmap.Compress(Bitmap.CompressFormat.Png, 0, stream);
                bitmapData = stream.ToArray();
            }
    
            return bitmapData;
        }
    

提交回复
热议问题