如何显示在WPF图像位图 [英] How to Display a Bitmap in a WPF Image

查看:199
本文介绍了如何显示在WPF图像位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个图像编辑程序,但我不能在我的WPF显示位图。
对于一般的编辑,我需要一个位图。但我不能显示的图像。

I want to implement a image editing program, but I can not display the Bitmap in my WPF. For the general editing I need a Bitmap. But I can not display that in a Image.

private void MenuItemOpen_Click(object sender, RoutedEventArgs e)
{
    OpenFileDialog openfiledialog = new OpenFileDialog();

    openfiledialog.Title = "Open Image";
    openfiledialog.Filter = "Image File|*.bmp; *.gif; *.jpg; *.jpeg; *.png;";

    if (openfiledialog.ShowDialog() == true)
    {
        image = new Bitmap(openfiledialog.FileName);
    }
}

我打开了的OpenFileDialog图像到位图。现在,我想设置的画面在我的WPF。像这样:

I load the Image with a OpenFileDialog into the Bitmap. Now I want to set the picture in my WPF. Like so:

Image.Source = image;

我真的需要一个位图来获得一个特殊的像素的颜色!我需要一个简单的code剪断。

I really need a Bitmap to get the color of a special pixel! I need a simple code snipped.

谢谢您的帮助!

推荐答案

我用现在这个剪断的位图转换为ImageSource的:

I have used this snipped now to convert the Bitmap to a ImageSource:

BitmapImage BitmapToImageSource(Bitmap bitmap)
{
    using (MemoryStream memory = new MemoryStream())
    {
        bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
        memory.Position = 0;
        BitmapImage bitmapimage = new BitmapImage();
        bitmapimage.BeginInit();
        bitmapimage.StreamSource = memory;
        bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
        bitmapimage.EndInit();

        return bitmapimage;
    }
}

这篇关于如何显示在WPF图像位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆