2013-09-30 37 views
0

我是初學者Windows手機開發者。在我的應用程序中,我有一個文件「A.img」,它已被XOR算法加密,如何將該文件(A.img)轉換爲byte []數組進行解密。我嘗試過但沒有成功。將文件轉換爲windows phone 7中的字節

回答

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; 
} 
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(); 
    } 
} 
相關問題