|
-
Feb 18th, 2024, 07:48 AM
#11
Re: how convert VB6 to VB2010 code?
 Originally Posted by joaquim
ok... creating DIB's:
Code:
Public Sub NewImage(ByVal ImageWidth As Integer, ByVal ImageHeight As Integer)
bmpInfoHeader.biSize = CUInt(Marshal.SizeOf(bmpInfoHeader))
bmpInfoHeader.biWidth = ImageWidth
bmpInfoHeader.biHeight = ImageHeight
bmpInfoHeader.biPlanes = 1
bmpInfoHeader.biBitCount = 32
bmpInfoHeader.biCompression = BI_RGB
Width = ImageWidth
Height = ImageHeight
hdc = CreateCompatibleDC(IntPtr.Zero)
pbmi = Marshal.AllocHGlobal(Marshal.SizeOf(bmpInfoHeader))
Marshal.StructureToPtr(bmpInfoHeader, pbmi, False)
If hdc = IntPtr.Zero Then Debug.Print("error")
hBitmap = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, lpvBits, IntPtr.Zero, 0)
oldBitmap = SelectObject(hdc, hBitmap)
g = Graphics.FromHdc(hdc)
g.Clear(Color.FromArgb(255, 255, 255, 255))
g.DrawLine(New Pen(Brushes.Red, 2), New Point(0, 50), New Point(20, 50))
to be honest these code is working normaly.. the line is drawed too...
now i'm trying getting the array pixels and changing directly on memory:
Code:
With tSA
.Initialize()
.fFeatures = FADF_FIXEDSIZE Or FADF_AUTO
.cbElements = 4
.cDims = 1
.Bounds(0).lLbound = 0 'erro
.Bounds(0).cElements = bmpInfoHeader.biHeight * bmpInfoHeader.biWidth
.pvData = pbmi
End With
'CopyMemory(VarPtrArray(bDib), VarPtr(tSA), 4)
'CopyMemory(VarPtrArray(bDibBGRA), VarPtr(tSA), 4)
Marshal.Copy(tSA, bDib, 0, 4)
Marshal.Copy(tSA, bDibBGRA, 0, 4)
i even tryied use 'Marshal.Copy()' but i get several errors 
If you are trying to create a bitmap and then draw on it you can get a graphics object with something like
Code:
Dim bmp As New Bitmap(100, 100, PixelFormat.Format32bppRgb)
Dim g = Graphics.FromImage(bmp)
and avoid all the interop stuff.
What is the end result of what you want your code to do? Is I t just create and draw on a bitmap, or something more?
Last edited by PlausiblyDamp; Feb 18th, 2024 at 08:03 AM.
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
|