|
-
Apr 19th, 2007, 05:44 PM
#1
Thread Starter
Fanatic Member
How to dereference a pointer as a structure
I've an IntPtr which points to the location where a Bitmap stores its raw image, i.e. not pointer to the bitmap object, but pointer to the image data itself (which I obtained through BitmapData.Scan0)
Now I've a structure like this
VBCode Code:
Structure RGB
B As Byte
G As Byte
R As Byte
End Structure
I need to be able to access the individual pixels (which I locate using the pointer) on the image as this RGB Structure.
In other words, it's like casting the pointer as a structure type. In C# it may be something like (RGB*) bmpptr;
Anyone know how?
Thanks in advance.
ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
Programming is fun, but only if you're not on a tight deadline 
So I consider all those working engineers sad people
VB FTP class
3 page PHP crash course
Crash Course on DX9 Managed with VB.NET covering basics till terrain creation
-
Apr 19th, 2007, 09:29 PM
#2
Re: How to dereference a pointer as a structure
Doesn't the MSDN help topic for the Scan0 property essentially show you how to do that? The code example it provides gets all the RGB data into a Byte array. You would then create multiple instances of your structure from the elements of that array.
-
Apr 20th, 2007, 06:17 AM
#3
Thread Starter
Fanatic Member
Re: How to dereference a pointer as a structure
Thanks for your reply.
I know that method; that's precisely the method I want to avoid. I want to change it directly, right away, on the spot, with the help of a structure. This is why I want to dereference the pointer as a structure which I've defined. Copying to an array incurs a lot of overhead. My code runs in a tight loop so I hope to be able to change the data as fast as possible.
ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
Programming is fun, but only if you're not on a tight deadline 
So I consider all those working engineers sad people
VB FTP class
3 page PHP crash course
Crash Course on DX9 Managed with VB.NET covering basics till terrain creation
-
Apr 20th, 2007, 06:23 AM
#4
Thread Starter
Fanatic Member
Re: How to dereference a pointer as a structure
I only hope VB.net has a native method to do this, and I would like to know what it is. I dont want to use Marshal class's WriteByte or the WriteInts, nor do I want to use FillMemory API because they incur tiny bits of overheads.
Unless, the JIT inlines the function call, which I'm not sure.
ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
Programming is fun, but only if you're not on a tight deadline 
So I consider all those working engineers sad people
VB FTP class
3 page PHP crash course
Crash Course on DX9 Managed with VB.NET covering basics till terrain creation
-
Apr 20th, 2007, 06:26 AM
#5
Re: How to dereference a pointer as a structure
Sounds to me like VB is the wrong language for this. I'd suggest writing a library in C# using unsafe code and then referencing that from your VB app, if that's an option.
-
Apr 20th, 2007, 06:30 AM
#6
Thread Starter
Fanatic Member
Re: How to dereference a pointer as a structure
thanks jmcilhinney for the advice.
unfortunately I'm not using C#.
The fact that they all are .NET compliant leads me to think VB.NET might have something like that, too.
I guess I'll just drop the idea and look for alternatives.
Speed is still an issue with VB.net, it seems.
ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
Programming is fun, but only if you're not on a tight deadline 
So I consider all those working engineers sad people
VB FTP class
3 page PHP crash course
Crash Course on DX9 Managed with VB.NET covering basics till terrain creation
-
Apr 20th, 2007, 06:47 AM
#7
Re: How to dereference a pointer as a structure
VB.NET was never intended to support pointers. If wanted to do even medium-duty work with pointers in VB the code would get ugly very quickly. The language is simply not designed for it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|