URLから画像をストリーミングする 質問する

URLから画像をストリーミングする 質問する

URL から画像を取得しています:

BitmapImage image = new BitmapImage(new Uri(article.ImageURL));
NLBI.Thumbnail.Source = image;

これは完璧に動作します。今度は、これをストリームに入れてバイト配列にする必要があります。私はこれをやっています:

WriteableBitmap wb = new WriteableBitmap(image);
MemoryStream ms = new MemoryStream();
wb.SaveJpeg(ms, image.PixelWidth, image.PixelHeight, 0, 100);
byte[] imageBytes = ms.ToArray();

NullReference でコードが失敗します。どうすれば修正できますか?

ベストアンサー1

var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData(article.ImageURL);

おすすめ記事