Image
这是一个图形控件,结果共有两个图片, CS代码的构造函数动态加入的,它的DestinationFormat=属性为Gray32Float
CS代码:
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"d:\1.jpg", UriKind.Relative);
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
FormatConvertedBitmap newFormatedBitmapSource = new FormatConvertedBitmap();
newFormatedBitmapSource.BeginInit();
newFormatedBitmapSource.Source = myBitmapImage;
newFormatedBitmapSource.DestinationFormat = PixelFormats.Gray32Float;
newFormatedBitmapSource.EndInit();
Image myImage = new Image();
myImage.Width = 200;
myImage.Source = newFormatedBitmapSource;
StackPanel myStackPanel = new StackPanel();
myStackPanel.Children.Add(myImage);
this.Content = myStackPanel;
关于PixelFormats的取值,可见下面连接。
http://msdn2.microsoft.com/en-us/library/system.windows.media.pixelformats_members.aspx
效果如下图:
本文参考MSDN组织。
《asp.net core精要讲解》 https://ke.qq.com/course/265696
《asp.net core 3.0》 https://ke.qq.com/course/437517
《asp.net core项目实战》 https://ke.qq.com/course/291868
《基于.net core微服务》 https://ke.qq.com/course/299524