編集:画像をblitする必要がある(WriteableBitmapの一部を別のものにコピーする)人は、Buffer.BlockCopyを使用してWriteableBitmapsのPixels int []配列を引数として取ります。Windows Phone 7.1:分割バイト[]イメージとBitmapImageに変換
前に、私はこの質問をした:私は今、数時間のために、この問題に取り組んできたと私はいくつかのことを試してみたImage won't load completely on Windows Phone 7.5
。私は画像の種類などに精通していないので、基本的な理論が欠けている可能性があります(私はバイト画像を分割してBitmapImageに変換できません)。私がやろうとしている何
は次のとおりです。
- は、Webクライアントを使用して、Webからの画像(JPEG)をダウンロードしてください。
- デコードJPEGのWebClientはPictureDecoder.DecodeJpegを使用して、私に戻り、[] []
- スプリットいくつかにバイト[]配列をバイトをint型からWriteableBitmapオブジェクト
- 変換WriteableBitmap.Pixels配列を取得することをストリームから個数は2000x2000サイズ制限を超えません
- 各作品をBitmapImageに変換して、WP7.1 Silverlightアプリで使用できるようにします。
しかし、私はそれらの線にSystem.Windows.dllで予期しないエラーとのSystem.Exceptionを得る:
firstImg.SetSource(ms);
newImg.SetSource(ms2);
ところで、私はダウンロードだJPEGが有効なJPEGがあり、私はそれを表示することができますそれを分割しようとすることなく。
編集:ダウンロードしたJpegの幅が2000より小さく、高さが2000よりも大きい。
はここに私のコードです:あなたはMemoryStream
に書き込みをした後
private void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
WriteableBitmap rawImg = PictureDecoder.DecodeJpeg(e.Result);
byte[] arr;
int height = rawImg.PixelHeight;
int count = 0;
if (height < 2000)
images.Add(new MyImage(rawImg));
else
{
arr = ConvertToByte(rawImg);
MemoryStream ms = new MemoryStream();
ms.Write(arr, 0, 4 * rawImg.PixelWidth * 2000);
count++;
BitmapImage firstImg = new BitmapImage();
firstImg.SetSource(ms);
images.Add(new MyImage(firstImg));
while (height > 2000)
{
MemoryStream ms2 = new MemoryStream();
ms2.Write(arr, count*2000, 4 * rawImg.PixelWidth * Math.Min(arr.Length - count*2000, 2000));
count++;
height -= 2000;
BitmapImage newImg = new BitmapImage();
newImg.SetSource(ms2);
images.Add(new MyImage(newImg));
}
}
}
private byte[] ConvertToByte(WriteableBitmap wb)
{
int w = wb.PixelWidth;
int h = wb.PixelHeight;
int[] p = wb.Pixels;
int len = p.Length;
byte[] result = new byte[4 * w * h];
for (int i = 0, j = 0; i < len; i++, j += 4)
{
int color = p[i];
result[j + 0] = (byte)(color >> 24);
result[j + 1] = (byte)(color >> 16);
result[j + 2] = (byte)(color >> 8);
result[j + 3] = (byte)(color);
}
return result;
}
まだ同じ例外が発生します。 – mostruash
WriteableBitmapExライブラリを調べることができました。 – keyboardP
ありがとうございます。 WriteableBitmapExは、1つのWriteableBitmapから別のWriteableBitmapにピクセルをコピーできます。私のニーズに正確に合っている。 – mostruash