2013-09-30 2 views
0

저는 초보자입니다. Windows phone dev. 내 응용 프로그램에서 나는 XOR 알고리즘에 의해 암호화 된 "A.img"파일을 가지고 있는데, 그 파일 (A.img)을 어떻게 해독을 위해 byte [] 배열로 변환 할 수 있습니까? 나는 시도했지만 성공하지 못했습니다.Windows에서 파일을 바이트로 변환 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(); 
    } 
}