您可以将System.Windows.Control.Image转换为System.Drawing.Icon? [英] Can you convert a System.Windows.Control.Image to a System.Drawing.Icon?

查看:849
本文介绍了您可以将System.Windows.Control.Image转换为System.Drawing.Icon?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题非常态问题的称号。这可能吗?

The title of the question pretty much states the problem. Is it possible?

推荐答案

我从修改的此处。这似乎工作就不错了。

I modified an example from here. This seems to work pretty good.

    public static Icon Convert(BitmapImage bitmapImage)
    {
        System.Drawing.Bitmap bitmap = null;
        var width = bitmapImage.PixelWidth;
        var height = bitmapImage.PixelHeight;
        var stride = width * ((bitmapImage.Format.BitsPerPixel + 7) / 8);

        var bits = new byte[height * stride];

        bitmapImage.CopyPixels(bits, stride, 0);

        unsafe
        {
            fixed (byte* pB = bits)
            {
                var ptr = new IntPtr(pB);

                bitmap = new System.Drawing.Bitmap(width, height, stride,
                                                System.Drawing.Imaging.PixelFormat.Format32bppPArgb,
                                                ptr);
            }

        }

        return Icon.FromHandle(bitmap.GetHicon());
    }

这篇关于您可以将System.Windows.Control.Image转换为System.Drawing.Icon?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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