0

我是初学者 Windows 手机开发者。在我的应用程序中,我有一个已通过 XOR 算法加密的文件“A.img”,我如何将该文件(A.img)转换为字节 [] 数组进行解密。我试过但没有成功。

4

2 回答 2

1
public static byte[] ConvertToBytes(this BitmapImage bitmapImage)
{
    using (MemoryStream ms = new MemoryStream())
    {
        WriteableBitmap btmMap = new WriteableBitmap
            (bitmapImage.PixelWidth, bitmapImage.PixelHeight);

        // write an image into the stream
        Extensions.SaveJpeg(btmMap, ms,
            bitmapImage.PixelWidth, bitmapImage.PixelHeight, 0, 100);

        return ms.ToArray();
    }
}
于 2013-09-30T08:53:59.110 回答
0

尝试这个

 public static byte[] ToByteArray(this WriteableBitmap bmp) 
 { 
    // Init buffer 
    int w = bmp.PixelWidth; 
    int h = bmp.PixelHeight;
    int[] p = bmp.Pixels; 
    int len = p.Length; 
    byte[] result = new byte[4 * w * h];     

   // Copy pixels to buffer 

   for (int i = 0, j = 0; i < len; i++, j += 4) 
   { 
       int color = p[i]; 
       result[j + 0] = (byte)(color >> 24); // A 
       result[j + 1] = (byte)(color >> 16); // R 
       result[j + 2] = (byte)(color >> 8);  // G 
       result[j + 3] = (byte)(color);       // B 
   } 
   return result; 
 } 
于 2013-09-30T09:07:44.470 回答