Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.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
C#可移植类库-使用图像_C#_.net - Fatal编程技术网

C#可移植类库-使用图像

C#可移植类库-使用图像,c#,.net,C#,.net,我正在编写一个库,它使用web API下载图像。我需要这个库可以在很多平台上使用,所以我选择了一个可移植类库。通常我会使用System.Drawing中的Bitmap类型将下载的图像存储在内存中,然后传递给方法等 然而,PCL由于其平台独立的方式,无法访问此类。因此,我想简单地将图像下载到byte[]数组中,然后由使用库的应用程序使用。使用字节数组保存下载的图像会有任何潜在问题吗?我认为使用字节[]存储图像不会有任何重大潜在问题 我能想到的唯一一件事是将图像转换为byte[]并返回的一些潜在开销

我正在编写一个库,它使用web API下载图像。我需要这个库可以在很多平台上使用,所以我选择了一个可移植类库。通常我会使用
System.Drawing
中的
Bitmap
类型将下载的图像存储在内存中,然后传递给方法等


然而,PCL由于其平台独立的方式,无法访问此类。因此,我想简单地将图像下载到
byte[]
数组中,然后由使用库的应用程序使用。使用字节数组保存下载的图像会有任何潜在问题吗?

我认为使用
字节[]
存储图像不会有任何重大潜在问题

我能想到的唯一一件事是将图像转换为
byte[]
并返回的一些潜在开销

此外,除了将图像存储在
字节[]
中之外,我想不出任何更好的方法来存储图像

此外,您还可以为数据类编写一个扩展方法,该方法保存
byte[]
以返回
Bitmap
,您可以在其中使用它

public static class DataClassExtensions
{
     public static BitmapImage GetImage(this DataClass data)
     {
         if(data == null || data.ImageArray == null) return null;

         using (var ms = new System.IO.MemoryStream(data.ImageArray))
         {
              Bitmap image = (Bitmap)Image.FromStream(ms);
              return image;
         }
     }
}

public class DataClass
{
     public byte[] ImageArray { get; set; }
}

我看不到将图像存储在
字节[]
中有任何潜在问题。