我正在尝试将图像添加到 GridView,但图像从未真正显示。相反,我只是在缩略图外观布局中显示类名。
这是我一直在调整的代码
public async void setImage(string url) {
Byte[] imageBytes = await httpClient.GetByteArrayAsync(url);
MemoryStream stream = new MemoryStream(imageBytes);
var randomAccessStream = new MemoryRandomAccessStream(stream);
BitmapImage image = new BitmapImage();
await image.SetSourceAsync(randomAccessStream);
imagesGrid.Items.Add(image);
}
谢谢您的帮助。我最终得到了以下有效的块。
public void setImage(string url) {
Image img = new Image();
img.Source = new BitmapImage(new Uri(url));
imagesGrid.Items.Add(img);
}