【问题标题】:Convert file to byte in windows phone 7在 windows phone 7 中将文件转换为字节
【发布时间】:2013-09-30 17:07:44
【问题描述】:

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

【问题讨论】:

    标签: windows-phone-7


    【解决方案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();
        }
    }
    

    【讨论】:

      【解决方案2】:

      试试这个

       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; 
       } 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多