Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xamarin.forms从imagesource获取字节数组_Image_Svg_Xamarin.forms - Fatal编程技术网

xamarin.forms从imagesource获取字节数组

xamarin.forms从imagesource获取字节数组,image,svg,xamarin.forms,Image,Svg,Xamarin.forms,我有svg xml,我可以使用xamarin.forms的PCL项目中的XamSVG库将其转换为ImageSource或FileImageSource 我想将ImageSource/FileImageSource转换为字节数组(以获取位图) 这可能吗?ImageSource不公开任何检索原始图像源的机制。相反,您需要手动保留对用于创建图像的原始源的引用。找到了解决方案 StreamImageSource streamImageSource = (StreamImageSourc

我有svg xml,我可以使用xamarin.forms的PCL项目中的XamSVG库将其转换为ImageSource或FileImageSource

我想将ImageSource/FileImageSource转换为字节数组(以获取位图)


这可能吗?

ImageSource不公开任何检索原始图像源的机制。相反,您需要手动保留对用于创建图像的原始源的引用。

找到了解决方案

        StreamImageSource streamImageSource  = (StreamImageSource) some image source...
        System.Threading.CancellationToken cancellationToken = System.Threading.CancellationToken.None;
        Task<Stream> task = streamImageSource.Stream(cancellationToken);
        Stream stream = task.Result;
StreamImageSource StreamImageSource=(StreamImageSource)某些图像源。。。
System.Threading.CancellationToken CancellationToken=System.Threading.CancellationToken.None;
Task Task=streamImageSource.Stream(cancellationToken);
Stream=task.Result;
其他解决方案:

 public static byte[] ReadFully(Stream input)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            input.CopyTo(ms);
            return ms.ToArray();
        }

    }
Stream和MemoryStream是System.IO类

然后像这样使用它:

            byte[] TargetImageByte = ReadFully(_data.Source);

_data.source是MediaFile类型

只是参考这个链接不是我需要的,因为我没有使用相机。我所拥有的是图像和图像源,我想从itI获取位图(字节数组),我没有原始源-我有转换为图像文件的svg xml文件,我需要位图的字节数组…您需要查看XamSVG库,看看它是否生成您可以访问的中间位图,或者修改它以生成一个位图。这是什么“a”?(第3行)a是StreamImageSource,我尝试了一下,得到:“无法将'Xamarin.Forms.FileImageSource'类型的对象强制转换为'Xamarin.Forms.StreamImageSource'。“这不是一个解决方案-它仅在
ImageSource
类型为
StreamImageSource
时有效。创建任何
ImageSource