Fork me on GitHub

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组织。


posted @ 2007-03-28 16:06  桂素伟  阅读(556)  评论(1编辑  收藏  举报