|
-
Nov 9th, 2002, 12:55 PM
#1
Thread Starter
Frenzied Member
CreateBitmap API
How can I create a Bitmap from an Array of Bytes?
I tried using createBitmap but I couldn't make it work... Could anyone give me an example of how it is used?
VB Code:
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
We miss you, friend...  Rest in Peace, we will take care of the rest of it.
[vbcode]
On Error Me.Fault = False
[/vbcode]
- Silence is the human way to share ignorance
Tec-Nico
-
Nov 11th, 2002, 08:32 PM
#2
Junior Member
Some answers, not all...
VB Code:
Public Type BITMAP ' 14 Bytes
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Public Declare Function GetObject Lib "gdi32" Alias "GetObjectA" _
(ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
That is the code to get information about an image or picture, hObject is the handle to that object.
The code you have offered would appear to create such an object using several of the values listed here.
Namely width, height, planes, bitspixel (nBitCount) and lpBits.
lpBits is a pointer to an array of the appropriate length, make sure you get this right!
In VB you can pass this array by simply entering the first element of that array.
I have gotten the Set/GetBitmapBits to work which works on fundamentally the same principle. Let me know if you get this to work properly, although I will try it when I have a little time!
Oh yea, if it follows the same idea as other API calls, the return value will be a pointer to the object (handle)
-
Nov 12th, 2002, 09:05 AM
#3
Hyperactive Member
hi,
although is now not updated the guide at allapi.net has an example that might help (actually the whole guide is invaluable...)
it create a bitman from a array of 8 bytes (a hatched effect) (then greats a brush and fills a form with....)
works for me..
(the comments within the code acknowledge author.....)
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Integer) As Long
Dim bBytes(1 To 8) As Integer
Private Sub Form_Paint()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim R As RECT, mBrush As Long, hBitmap As Long
For mBrush = 1 To 8 Step 2
bBytes(mBrush) = 170 '170 = 10101010
bBytes(mBrush + 1) = 85 '85 = 01010101
Next
'Create a memory bitmap
hBitmap = CreateBitmap(8, 8, 1, 1, bBytes(1))
'Create the pattern brush
mBrush = CreatePatternBrush(hBitmap)
SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
'Fill the form
FillRect Me.hdc, R, mBrush
'Clean up
DeleteObject mBrush
DeleteObject hBitmap
End Sub
-
Dec 7th, 2014, 01:40 AM
#4
Frenzied Member
Re: CreateBitmap API
Sorry to bump such an old thread, but this is the only thread that already exists on these forums, that has any information about the CreateBitmap API function. And I figured it was better to bump an old thread, than to create a new thread about a topic that already has a thread.
I'm having a problem with this. I've created my own screencap software, using this technique and using the first cell of a byte array as the pointer just like this example you gave. I create a Bitmap, a DC, select the bitmap into the DC, BitBlt the screen's DC to my own DC, and then I'm expecting the raw bytes of image data to be present in the byte array. But it's not. It's full of 0's as if there's no image data, but then I BitBlt it back out of this DC I made, out to my VB6 form's DC, and the screencap appears on my form. It appears to be storing the image data SOMEWHERE, but not in the array that it was SUPPOSED TO store it in.
Has anybody else had this problem?
-
Dec 9th, 2014, 05:35 PM
#5
Re: CreateBitmap API
Feel you should start your own thread. There are several potential problems with the code provided. Information that wasn't provided and maybe should have, specifically Word alignment of bitmap rows. Additionally, we don't have your code that you used, obviously you are not using an 8x8 bitmap at 1 bit per pixel.
But the main reason for your confusions, is that Blting to a DC does not update the byte array. You have to transfer the bitmap bits back into the byte array. In other words, the byte array is no longer referenced by the bitmap, after you call CreateBitmap API.
I and others obviously won't mind responding to a thread of your own. Personally, I don't like continuing with a 'hijacked' thread simply because replies can trigger off emails to people that have subscribed to this one. Don't feel that is appropriate and/or fair to the original poster. Anyway, just my feeling about using others threads...
Last edited by LaVolpe; Dec 9th, 2014 at 05:47 PM.
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
|