【原创】C#读取C++dll资源文件中的BITMAP

【原创】C#读取C++dll资源文件中的BITMAP,第1张

         private void Button_Click(object sender, RoutedEventArgs e)
        {
            string filename = "FiveRes.dll";
            var hDll = NativeLibrary.Load(filename);
            if (hDll != IntPtr.Zero)
            {
                IntPtr hRes =  LoadBitmap(hDll, 2063);
                Bitmap bmp = Bitmap.FromHbitmap(hRes);

                MemoryStream stream = new MemoryStream();
                bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);

                image.Source = (new ImageSourceConverter()).ConvertFrom(stream) as ImageSource;
                image.Width = bmp.Width;
                image.Height = bmp.Height;

                NativeLibrary.Free(hDll);
            }        
        }

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1324158.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-12
下一篇 2022-06-12

发表评论

登录后才能评论

评论列表(0条)

保存