C#   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了如何在C#中将位图图像转换为IntPtr?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我从我看到的@L_674_0@例子中做到了这一点,它从未抛出任何错误,但图像显示为灰色.

有@L_674_0@更好的方法吗?

@H_404_13@private unsafe void menuItem7_Click(object sender,EventArgs E) { var setTings = Utility.GatherLocalSetTings(); openFileDialog1.InitialDirectory = setTings.SavePath; openFileDialog1.Filter = "Scan Files (*.jpg)|*.jpg"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.oK) { byte[] openFile = File.ReadAllBytes(openFileDialog1.FileName); fixed (byte* p = openFilE) { IntPtr img = (IntPtr)p; frmContainer newScan = new frmContainer(img); newScan.MdiParent = this; newScan.Text = Path.GetFilename(openFileDialog1.FileName) + " [Saved]"; newScan.Show(); } } }

PS:我检查了csproj以允许构建中的不安全代码.

解决方法

试试这个,

@H_404_13@IntPtr pval = IntPtr.Zero; System.Drawing.Imaging.bitmaPDAta bd = bmp.LockBits(new Rectangle(0,bmp.Width,bmp.Height),ImageLockmode.ReadWrite,PixelFormat.Format24bppRgb); try { pval=bd.Scan0; ... } finally { bmp.UnlockBits(bd); }

大佬总结

以上是大佬教程为你收集整理的如何在C#中将位图图像转换为IntPtr?全部内容,希望文章能够帮你解决如何在C#中将位图图像转换为IntPtr?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。