Windows phone 7 在windows phone 7中将文件转换为字节
我是Windows phone初学者。在我的应用程序中,我有一个文件“a.img”,它已通过XOR算法加密,我如何将该文件(a.img)转换为字节[]数组进行解密。我试过了,但没有成功 试试这个Windows phone 7 在windows phone 7中将文件转换为字节,windows-phone-7,Windows Phone 7,我是Windows phone初学者。在我的应用程序中,我有一个文件“a.img”,它已通过XOR算法加密,我如何将该文件(a.img)转换为字节[]数组进行解密。我试过了,但没有成功 试试这个 public static byte[] ConvertToBytes(this BitmapImage bitmapImage) { using (MemoryStream ms = new MemoryStream()) { WriteableBitmap btmMa
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();
}
}
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;
}
publicstaticbyte[]ToByteArray(此可写bitmap bmp)
{
//初始化缓冲区
int w=bmp.PixelWidth;
int h=bmp.PixelHeight;
int[]p=bmp.像素;
int len=p.长度;
字节[]结果=新字节[4*w*h];
//将像素复制到缓冲区
对于(int i=0,j=0;i>24);//A
结果[j+1]=(字节)(颜色>>16);//R
结果[j+2]=(字节)(颜色>>8);//G
结果[j+3]=(字节)(颜色);//B
}
返回结果;
}