我对这种东西很陌生。我正在尝试创建一个等效于图像直方图函数的函数。我正在使用 Windows 窗体应用程序来显示直方图(并加载图像)和 CUDA/c++ 来制作直方图。我从一开始就提到我没有使用 openCV、glut、OpenGL 或任何其他第三方库。进行中...我正在尝试将位图传递给非托管 C++ DLL。这里的问题是我现在不知道如何在 c++ 代码中引用该位图。(甚至如何从中获得RGB)。代码片段:
C# :
private void calculateHistogram(object sender, EventArgs e)
{
Bitmap bmp = (Bitmap)pictureBox1.Image;
unsafe {
int** matrixAcumulated;
var date = bmp.LockBits(new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
matrixAcumulated=NativeMethods.GenerateHistogram(date.Scan0, pictureBox1.Width);
bmp.UnlockBits(date);
// Write the string to a file.
System.Console.WriteLine(matrixAcumulated[0][0]);
}
}
DLL导入:
using System;
using System.Runtime.InteropServices;
namespace HistogramProcessingCs
{
class NativeMethods
{
[DllImport("HistogramProcessingCpp.dll", CallingConvention = CallingConvention.StdCall)]
public static extern unsafe int** GenerateHistogram(IntPtr bmp, int dimensionImage);
}
}
c++:
extern "C" __declspec(dllexport) int** __stdcall GenerateHistogram(unsigned char *bmp, int dimensionImage)
{
//How to refere the bitmap from the bmp pointer?
//dimensionImage is Width = Height
}