- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我根据我看到的一个例子做了这个,它从来没有抛出任何错误,但是图像显示为灰色。
有更好的方法吗?
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 以允许构建中的不安全代码。
最佳答案
试试这个,
IntPtr pval = IntPtr.Zero;
System.Drawing.Imaging.BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
try
{
pval=bd.Scan0;
...
}
finally
{
bmp.UnlockBits(bd);
}
关于c# - 如何在 C# 中将位图图像转换为 IntPtr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1303493/
我正在尝试使用 BitmapData 类?并且在将 IntPtr 值分配给 BitmapData.Scan0 属性时遇到一些问题。这是我的代码: var data = bmp.LockBits(new
我正在尝试使用 BitmapData 类?并且在将 IntPtr 值分配给 BitmapData.Scan0 属性时遇到一些问题。这是我的代码: var data = bmp.LockBits(new
我有两个 IntPtr 值指向一些 length 字节的数据区域。 length 可能有 200k 到 400k 的数量级。 int length = /* ..*/ IntPtr ptrSrc =
我在网上到处都看过,似乎找不到能够解决该问题的特定答案。从字面上看,这是我得到的唯一错误,只有在解决此问题后才能构建可执行文件。 int num3 = new VAMemory(Data.proces
我不知道 Copy(IntPtr[], Int32, IntPtr, Int32) 方法是如何工作的。我虽然它可以将多个 IntPtr 中包含的数据复制到一个 IntPtr 中(如 MSDN 所述),
我有一个类的以下代码。这是一个类的初始化。 第三方动态链接库 [DllImport("gdi32.dll")] public static extern IntPtr CreateCompatib
我刚刚了解到 IntPtr.Zero 无法与 default(IntPtr) 相提并论。谁能告诉我为什么? IntPtr.Zero == new IntPtr(0) -> "could not eva
这两种说法有什么区别吗: IntPtr myPtr = new IntPtr(0); IntPtr myPtr2 = IntPtr.Zero; 我见过许多使用 PInvoke 的示例,如果 myPtr
这个问题已经有答案了: What makes more sense - char* string or char *string? [duplicate] (13 个回答) 已关闭 9 年前。 本能地
我知道 Marshal.SizeOf() 和 sizeof() 有多么根本的不同。但是在 IntPtr 的情况下,无论 CPU 架构如何,它们都不会总是返回完全相同的东西吗? 最佳答案 一方面,有原始
我需要实现一个与找到的解决方案非常相似的解决方案 here ,写于 2009 年,用于检索文件的唯一标识符。具体来说,我正在查看答案的 ApproachB()函数和以下行(重写了一点以反射(refle
是否可以通过 Skype 用户窗口获取处理程序并使用 SendMessage(whdl,BM_CLICK,intptr.zero,intrptr.zero,intptr.zero) 单击发送文件或调用
经过一些研究我翻译了 pHandle = IntPtr.Zero; 到德尔福 var pHandle: Pointer; 当我在 Delphi 中中断调试时,我得到 $314328,当我在 C s
运营商的description on MSDN有一句话: An exception is only thrown if the value of value requires more bits th
这个函数在一个循环中。当我运行程序时,带有 IntPtr 的行给我内存问题,我已经删除 [],但它仍然没有解决内存问题,有人可以帮忙吗?谢谢 void showImage(IplImage *img,
直到最近,我还认为在 P/Invoke 中编码 IntPtr 只会涉及“blitting”操作;即简单地从例如复制指针C++ 到 C#。 然而,我最近与某人交谈时提到,事情远不止于此。他特别提到 In
我目前正在编写一些代码,这些代码反射(reflect)了从对 native dll 的调用中编码返回的结构。一些结构包含指向以 null 结尾的指针数组的 IntPtr* 字段。这些字段需要特殊处理。
我正在尝试在 Ubuntu 14.04 上使用 Mono 执行函数 P/Invoke: [DllImport(@"libRT", CharSet = CharSet.Ansi, CallingConv
我有一个类定义如下: [StructLayout(LayoutKind.Sequential)] public class OUR_MEM_STR {
我遇到了一段C#源码如下 int* ptr = ...; int w = ...; int* ptr3 = ptr + (IntPtr)w; CS0019: Operator '+' cannot
我是一名优秀的程序员,十分优秀!