由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DotNet版 - 如何从memory里提出image?
相关主题
那个Control可以做这个事情?关于graphics.drawstring 的问题
image with RadioButtonList c#那位VB.NET 的大侠帮个忙。
vb.net如何显示缩小后窗口消失的程序(已解决)Help , a entry level question about C#
C# on JVM?C#环境下调用C++函数的问题。
Windows, freeBSD, Mac OS X support CLI这里有没有AJAX.NET高手?
a question about C++.net class libraryweb chart的选择?
[转载] C++ how to convert string to bitmap or graphic, iasp.net/IIS configuration problem
Re: [转载] C++ how to convert string to bitmap or graphic, ihow to use ctrl+z?
相关话题的讨论汇总
话题: intptr话题: barray话题: byte话题: bitmap话题: short
进入DotNet版参与讨论
1 (共1页)
s***r
发帖数: 2604
1
在用一个third party的dll, 原来是c++写的, 现在wrap好了. 接口反回值应该是个
image, 但现在的三个可见返回值是 short* img, int w, int h
用这三个怎么在c#下把bitmap弄出来呢, 谢谢. 这个short* 是不是可以直接转成
IntPtr用啊, 谢谢
s***r
发帖数: 2604
2
so, basically without image structure info I can not fetch the image out?
even I already have theaddress, width and height of it?
can u give some marshall related link about this. I tried some marshall.copy
(), but not work. I am worry about something wrong in my code.
L******e
发帖数: 136
3
it is possible to do
Bitmap^ bmp = Bitmap::FromHbitmap((IntPtr)hBmp);
from your short* and size (w,h) you should be able to get IntPtr for the
bitmap..
L******e
发帖数: 136
4
see this link:
http://stackoverflow.com/questions/2238049/it-is-possible-to-ge
you should be able to do this without unsafe code using GCHandle. Here is a
sample:
GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
try
{
IntPtr pointer = handle.AddrOfPinnedObject();
}
finally
{
if (handle.IsAllocated)
{
handle.Free();
}
}
L******e
发帖数: 136
s***r
发帖数: 2604
6
thank u, I will try each of them

【在 L******e 的大作中提到】
: http://msdn.microsoft.com/en-us/library/k061we7x.aspx
: Image.FromHbitmap Method (IntPtr)

s***r
发帖数: 2604
7
how should I get the "array" in the example code. what is the way to read it
from memory? Something like this?
short* img;
int w;
int h;
Byte[] barray = new Byte[w*h*3];
Marshal.copy(IntPtr(img), barray, 0, w*h*3);

a

【在 L******e 的大作中提到】
: see this link:
: http://stackoverflow.com/questions/2238049/it-is-possible-to-ge
: you should be able to do this without unsafe code using GCHandle. Here is a
: sample:
: GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
: try
: {
: IntPtr pointer = handle.AddrOfPinnedObject();
: }
: finally

s***r
发帖数: 2604
8
this dose no work
here basically is the code:
Byte[w*h] barray = new byte[w*h];
Mashal.copy((intptr)(img), barray, 0,w*h);
GChandle hd = GChandle.Alloc(barray, Gchandletype.Pinned);
try
{IntPtr p = hd.AddrofPinnedObject();
Bitmap b = Bitmap.FromHbitmap(p);}
finally
{;}
the line bitmap.fromhbitmap(p), will throw an error

it

【在 s***r 的大作中提到】
: how should I get the "array" in the example code. what is the way to read it
: from memory? Something like this?
: short* img;
: int w;
: int h;
: Byte[] barray = new Byte[w*h*3];
: Marshal.copy(IntPtr(img), barray, 0, w*h*3);
:
: a

L******e
发帖数: 136
9
You need to get IntPtr from that short* right? did you try the code below
the one I quoted, in the same stackoverflow link?
unsafe
{
fixed (int* pArray = array)
{
IntPtr intPtr = new IntPtr((void *) pArray);
}
}
once you get this IntPtr you can do the rest I think..
s***r
发帖数: 2604
10
Yes, I did with following code
Byte[w*h] barray = new byte[w*h]; Mashal.copy((intptr)(img), barray, 0,w*h);
unsafe{fixed(byte* parray=barray)
{InrPtr p= new IntPtr((void* parray));
Bitmap bmp = Bitmap.FromHbitmap(p);}}
same error, on lastline give me "A generic error occured in GDI+"
Is there anything wrong with the code?
do u think the size w,h matters, cz in the run time they are 1066,782 which
is weird to me.
thank u.
在 Leyunque (Le yunque) 的大作中提到: 】
L******e
发帖数: 136
11
it is a short[w x h] array, why do you need to convert it to byte?
s***r
发帖数: 2604
12
I tried short, byte and int, none of them work

【在 L******e 的大作中提到】
: it is a short[w x h] array, why do you need to convert it to byte?
1 (共1页)
进入DotNet版参与讨论
相关主题
how to use ctrl+z?Windows, freeBSD, Mac OS X support CLI
Need Help: a very wierd Managed C++ interop problema question about C++.net class library
Size limit on HttpResponse.BinaryWrite?[转载] C++ how to convert string to bitmap or graphic, i
新手问个问题哈,关于C#的Re: [转载] C++ how to convert string to bitmap or graphic, i
那个Control可以做这个事情?关于graphics.drawstring 的问题
image with RadioButtonList c#那位VB.NET 的大侠帮个忙。
vb.net如何显示缩小后窗口消失的程序(已解决)Help , a entry level question about C#
C# on JVM?C#环境下调用C++函数的问题。
相关话题的讨论汇总
话题: intptr话题: barray话题: byte话题: bitmap话题: short