silverlight Balder 动态材质(用网上的图片)
园子里,有关于Heightmap的介绍。创建Material时,用的本地的图片,怎么用网上的图片呢?
搞了一天,上代码,不要见笑
图片下载完了,就:
void down_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
System.IO.Stream responseStream = e.Result;
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(responseStream);
WriteableBitmap bitmap = new WriteableBitmap(bitmapImage);
//注意是4哦,我一开始用的3,就显示不正常了
byte[] array = new byte[bitmapImage.PixelHeight * bitmapImage.PixelWidth * 4];
for (int i = 0; i < bitmap.PixelHeight; i++)
{
for (int j = 0; j < bitmap.PixelWidth; j++)
{
int index = bitmap.PixelWidth * i + j;
int pixel = bitmap.Pixels[index];
byte[] bytes = BitConverter.GetBytes(pixel);
//蓝波段(试验过)
array[index * 4] = bytes[0];
//绿波段(试验过)
array[index * 4 + 1] = bytes[1];
//红波段(试验过)
array[index * 4 + 2] = bytes[2];
//透明度(应该是的吧)
array[index * 4 + 3] = bytes[3];
}
}
Balder.Imaging.Image image = new Balder.Imaging.Image();
image.Width = bitmap.PixelWidth;
image.Height = bitmap.PixelWidth;
Balder.Imaging.IImageContext imageContext = image.ImageContext;
imageContext.SetFrame(array);
to3Dview(image);
}
else
{
MessageBox.Show(e.Error.Message);
}
}