carlajasminelewis
asked on
Convert C function to VB for me
I need this function to convert a graphic to a 1bpp. Can anyone rewite this one function to VB. I've got a little, but I'm a little lost as well.
protected unsafe void SetIndexedPixel(int x,int y,BitmapData bmd, bool pixel)
{
byte* p=(byte*)bmd.Scan0.ToPoint er();
int index=y*bmd.Stride+(x>>3);
byte mask=(byte)(0x80>>(x&0x7)) ;
if(pixel)
p[index]|=mask;
else
p[index]&=(byte)(mas k^0xff);
}
My VB version wouldstart out something like:
Sub setIndexedPixel(ByVal x as Integer, ByVal y as Integer, ByRef bmd as BitmapData, ByVal pixel As Boolean)
Dim p As IntPtr=bmd.Scan0
...and there you go - wow I suck. Need soon. Any takers?
Original code found at http://www.bobpowell.net/onebit.htm.
protected unsafe void SetIndexedPixel(int x,int y,BitmapData bmd, bool pixel)
{
byte* p=(byte*)bmd.Scan0.ToPoint
int index=y*bmd.Stride+(x>>3);
byte mask=(byte)(0x80>>(x&0x7))
if(pixel)
p[index]|=mask;
else
p[index]&=(byte)(mas
}
My VB version wouldstart out something like:
Sub setIndexedPixel(ByVal x as Integer, ByVal y as Integer, ByRef bmd as BitmapData, ByVal pixel As Boolean)
Dim p As IntPtr=bmd.Scan0
...and there you go - wow I suck. Need soon. Any takers?
Original code found at http://www.bobpowell.net/onebit.htm.
also there are no shift operations in vb.net which would make this code kind of fun :) I guess you could use mult/divs by power of 2 ...
I agree with alex though, compile it in C# and add the reference to your vb app
I agree with alex though, compile it in C# and add the reference to your vb app
Use BitArray and BitConverter classes for bitwise operations.
Use Marshal.Copy Method (IntPtr, Byte[], Int32, Int32) for copying from IntPtr to Byte()
Also take a look at ms-help://MS.MSDNQTR.2004J UL.1033/vb ls7/html/v blrfVBSpec 11_11.htm
Visual Basic Language Specification - 11.18 Shift Operators
Use Marshal.Copy Method (IntPtr, Byte[], Int32, Int32) for copying from IntPtr to Byte()
Also take a look at ms-help://MS.MSDNQTR.2004J
Visual Basic Language Specification - 11.18 Shift Operators
ASKER
Alex or Greggory:
Would one of you care to compile the function as a DLL that I can call from a VB.Net program?
Would one of you care to compile the function as a DLL that I can call from a VB.Net program?
ASKER
Gregory: there are shift operators in VB
sure email me ... this name at experts-exchange ill email it back.
but ill need a dll with the things it references to build it
ASKER
Really, it is only this one function. You see, I'm trying to save a 24bpp image as a 1bpp image. I have thermal printer that will only display 1bpp images. It's a long story. Someone forwarded me this link: http://www.bobpowell.net/onebit.htm . In two functions, this guy does exactly what I need, except his is in C#. The other function is easily migratable.
I belive the only reference it would need would be: "using System.Drawing;"
It might be worth it to take a look at the code in the link above. It is a very simple program.
I belive the only reference it would need would be: "using System.Drawing;"
It might be worth it to take a look at the code in the link above. It is a very simple program.
ah ok
drop me an email ill send it back.
drop me an email ill send it back.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This shift operators << and >> are only in VB.NET 2003.
Bob
Bob
Hopefully, we will hear what the solution was, right?
Bob
Bob
maybe ... I emailed it ..
ASKER
I realized I could do that myself as well. Thanks for all your help.
this should at the least go to Bob as well.
If you like I would be happy to reopen the question.
If you like I would be happy to reopen the question.
No, it should go to everyone that reads this question. Emails are against E-E guidelines.
Bob
Bob
the email was just the code here compiled not further info, you are the one who actually answerred the question therefor you should get the points as stated above.
Compile this function to C# Dll and call it from VB .NET application.