简体   繁体   English

C#图像到字节数组的巨大尺寸

[英]c# image to byte array huge size

im just using a faster method to convert image to byte array it's not new i found it in some places over the internet. 即时通讯只是使用一种更快的方法将图像转换为字节数组,这并不是什么新鲜事,我在互联网上的某些地方发现了它。

this is the send code 这是发送代码

private  int SendVarData(Socket s, byte[] data)
    {
       total = 0;
        int size = data.Length;
        int dataleft = size;
        int sent;


        datasize = BitConverter.GetBytes(size);
        sent = s.Send(datasize);


            sent = s.Send(data, total, dataleft, SocketFlags.None);
            total += sent;
            dataleft -= sent;
          //  MessageBox.Show("D");

        return total;
    }

and i call it : 我称之为:

    SendVarData(handler, bmpBytes);

where handler is a socket and bmpbytes is the image converted to byte array. 其中handler是一个套接字, bmpbytes是将图像转换为字节数组。 do u have any better solution? 您有更好的解决方案吗? @xanatos @xanatos

It's not weird at all. 一点也不奇怪。 In your first sample, you're copying the image as it is stored in memory, ie uncompressed. 在第一个示例中,您正在复制图像,因为它存储在内存中,即未压缩。

In your second sample you're getting the data as it would have been stored on disk, ie compressed as GIF in this case. 在第二个示例中,您将获取数据,因为它们将存储在磁盘上,即在这种情况下压缩为GIF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM