我有一个针对Windows Phone平台编写的应用程序,可以解密图像。为了测试该应用程序,我在Windows Classic(桌面)平台上编写了一段代码,通过TCP连接与Windows Phone应用程序进行通信。现在,我在Windows Phone应用程序中有一张解密后的图像,我想验证它是否与原始图像(加密之前)相同。使用XMLSerialization我无法在TCP连接上发送Image类型;因此,我使用以下代码将其转换为字节:
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格式的情况下获取字节?