本文介绍了图像转换成Xamarin.Forms字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要传递的图像(图像_thresholdedImage ),如字节数组...我不知道我能做到这一点。任何想法? !谢谢



  _thresholdedImage.Source = ImageSource.FromStream(()=> photo.Source); 

VAR tessResult =等待_tesseractApi.SetImage(imageBytes);


解决方案

我无法将其转换在X.Forms,而不是我用下面的代码与依存服务。谢谢所有

 公共异步任务<字节[]> GetBytesFromImage(字符串文件路径)
{
ConvertImageToBW(文件路径);

//创建另一个位图,将持有的过滤器的结果。
位图thresholdedBitmap = Bitmap.CreateBitmap(BitmapFactory.DecodeFile(文件路径));

thresholdedBitmap = BitmapFactory.DecodeFile(thresholdedImagePath);

字节[]的位图数据;使用
(VAR流=新的MemoryStream())
{
thresholdedBitmap.Compress(Bitmap.CompressFormat.Png,0,流);
位图数据= stream.ToArray();
}

返回的位图数据;
}


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.Source = ImageSource.FromStream (() => photo.Source);

var tessResult = await _tesseractApi.SetImage(imageBytes);
解决方案

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<byte[]> 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;
    }

这篇关于图像转换成Xamarin.Forms字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:52
查看更多