Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.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# 如何将图像转换为字节数组而不将其类型转换为JPEG_C#_Xml Serialization_Windows Phone - Fatal编程技术网

C# 如何将图像转换为字节数组而不将其类型转换为JPEG

C# 如何将图像转换为字节数组而不将其类型转换为JPEG,c#,xml-serialization,windows-phone,C#,Xml Serialization,Windows Phone,我有一个为windows phone平台编写的解密图像的应用程序。为了测试应用程序,我在windows classic(桌面)平台上有一个代码,它通过TCP连接与windows phone应用程序通信。现在,我在windows phone应用程序中有一个已解密的图像,我想验证它是否与原始图像相同(加密前)。使用XMLSerialization,我无法在TCP连接上发送图像类型;因此,我使用以下代码将其转换为字节: BitmapImage bitmapImage = image.Source as

我有一个为windows phone平台编写的解密图像的应用程序。为了测试应用程序,我在windows classic(桌面)平台上有一个代码,它通过TCP连接与windows phone应用程序通信。现在,我在windows phone应用程序中有一个已解密的图像,我想验证它是否与原始图像相同(加密前)。使用XMLSerialization,我无法在TCP连接上发送图像类型;因此,我使用以下代码将其转换为字节:

BitmapImage bitmapImage = image.Source as BitmapImage;
using (MemoryStream ms = new MemoryStream())
{
    WriteableBitmap btmMap = new WriteableBitmap(bitmapImage.PixelWidth, bitmapImage.PixelHeight);

    Extensions.SaveJpeg(btmMap, ms, bitmapImage.PixelWidth, bitmapImage.PixelHeight, 0, 100);

    bytes = ms.ToArray();
}

但是,我得到的字节与原始图像字节不匹配,因为图像已编码为Jpeg格式。即使在测试端,我将原始图像转换为jpeg格式,字节也不匹配。但是,当我将字节发送到WinPhone应用程序并将它们转换为Jpeg时,它们是相等的。如何在不将图像转换为Jpeg格式的情况下获取字节

下面的代码对我来说很好

public static byte[] imageToByteArray(System.Drawing.Image sourceImage)
    {
        System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();

        sourceImage.Save(memoryStream, sourceImage.RawFormat);

        return memoryStream.ToArray();
    }

映像类在Windows Phone平台中没有保存方法。