如何将位图数据类型传递给c ++ dll? [英] how to pass bitmap data type to c++ dll ?

查看:121
本文介绍了如何将位图数据类型传递给c ++ dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该程序没有提示错误,但是没有任何图片显示在c ++表格中,经过测试的简单数据类型,如int,可以正常发货,请给我一个简单的例子,告诉我该怎么办





---------------------------- ----------------------------------------------

C#代码

The program has no tip errors ,But there is no any picture display in c++ form,Tested the simple data types, such as int, can be normal delivery,please give me a simple example ,tell me what to do


--------------------------------------------------------------------------
C# Code

[DllImport("dllTestForm.dll", EntryPoint = "showFormC")]
static extern void testShowFormC(byte[] photo,int len);

private void button6_Click(object sender, EventArgs e)
{
		Bitmap bmp = (Bitmap)Image.FromFile(@"d:\1\1.jpg");

		Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
		System.Drawing.Imaging.BitmapData bmpData =
		bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,bmp.PixelFormat);

		// Get the address of the first line.
		IntPtr ptr = bmpData.Scan0;

		// Declare an array to hold the bytes of the bitmap. 
		int bytes  = Math.Abs(bmpData.Stride) * bmp.Height;
		byte[] rgbValues = new byte[bytes];

		 // Copy the RGB values into the array.
		 System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

		 // Unlock the bits.
		 bmp.UnlockBits(bmpData);

		 testShowFormC(rgbValues, bytes);
}



------------------------------ --------------------------------------------

C ++代码


--------------------------------------------------------------------------
C++ Code

[DllImport("dllTestForm.dll", EntryPoint = "showFormC")]
static extern void testShowFormC(byte[] photo,int len);

void __stdcall showFormC(byte *photo,int len)
{
    ThelloWorld *a=new ThelloWorld(Application);//这是一个winForm测试界面,显示图片用
    a->ImageEnView2->IO->LoadFromBuffer(photo,0,len);  
    a->Show();

}

推荐答案

这根本没有意义,至少是你展示的代码。在C#和C ++中,只从dllTestForm.DLL导入一些函数,但不显示任何实现。无法保证其正确实施甚至存在。更重要的是,不清楚位图应该如何显示,因为你没有将任何可用于渲染图像的功能传递给此函数;没有图形内容,没有处理图像应该显示的控件。很有可能的是,基于具有这种签名的功能可以显示图像。



-SA
This simply makes no sense, at least the code you show. In both C# and C++ pieces, you only import some function from dllTestForm.DLL, but show no implementation. There is no guarantee that it is implemented properly or even exists. More importantly, it's not clear how the bitmap is supposed to be show, as you don't pass to this function anything which could be used to render the image; no graphic content, no handle for some control where the image should be shown. It's quite doubtful that the image can be shown based on the function with such signature.

—SA


这篇关于如何将位图数据类型传递给c ++ dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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