Can it be done? I want to get a Bitmap object (so I can do the bitmap array manipulations) but I need to get it with the DC that I have. How would this be done?
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Private Declare Function GetCurrentObject Lib "gdi32" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
Private Const OBJ_BITMAP = 7
Private Function GetBmpHandle(hdc As Long)
GetBmpHandle = GetCurrentObject(hdc, OBJ_BITMAP)
End Function
once you retreive the handle of the current bitmap object in your dc, just use the GetObject API to get your BITMAP type. Your code could now look like this :
Code:
dim hBmp as long
dim myBmp as BITMAP
hBmp = GetCurrentObject(myHdc, OBJ_BITMAP)
GetObject hBmp, len(myBmp), myBmp
'You keep creatures in cages and release them to fight? That's sick!'
Just glad I could help... damn, I think I'm getting addicted to this forum Anyway, wanna know my API secret ? http://msdn.microsoft.com/library/de..._reference.asp If you are able to deal with learning from c++ examples, all your API questions will be answered there!
- Valkan
'You keep creatures in cages and release them to fight? That's sick!'
After clicking your link (or any link on the MSDN for that matter), it comes up with a list that contains these links (no formatting, no text formatting, just a white page with these links):
Code:
Welcome to the MSDN Library
Welcome to the MSDN Library
Component Development
Data Access
Development (General)
Enterprise Development
Graphics and Multimedia
Messaging and Collaboration
Mobile and Embedded Development
.NET Development
.NET Development
Networking and Directory Services
Office Solutions Development
Security
Security
Setup and System Administration
User Interface Design and Development
User Interface Design and Development
Visual Tools and Languages
Web Development
Windows Development
XML Web Services
XML Web Services
MSDN Library Archive
Weird, no?
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Hmm.. It's not working... It's retrieving everything correctly, and I'd look to the MSDN for advice, but as I mentioned, it's not working for me >_<. Here's what my function looks like:
VB Code:
Public Function AlphaBltFast(ByVal hDest As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrc As Long, ByVal hAlpha As Long, ByVal xSrc As Long, ByVal ySrc As Long)
I know there's still lots to be done but it would be functional, for now. But it isn't: the arrays are empty (0, 0 is index out of bounds). Do you, or the MSDN, have anything to say to this?
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Hum... ok, by reading your code i didn't see something wrong at first glance so i copied it (and btw... is there a way to copy correctly code posted on this board?) and try to use your function. And something very strange is happenig... after the getobject calls, every member for all the bitmap variable are set correctly... Every members exepted for the bmbits wich is always 0 so no pointer to the data!? Now, unless my computer is in worst shape than i tought and that does this only for me , This would be why you get the out of bound error since copymemory will fail.
So now i'm speechless... i've seen exemple using this technique to change the pixels from a bitamp and even used it myselt with success. So why is it not working now... i really don't know (that's why i brought up the computer being in bad shape thing... i know i've already done this... but now it doesn't work!!! I just don't get it.)
so now i'm gonna go to sleep... i'll probably see things more clearly tomorow. If you get a chance, try to see what are the values for .bmbits when you run your code to see if you have the same problem.
'You keep creatures in cages and release them to fight? That's sick!'
Did I not mention that? D'oh. That's what problem I'm having, that the bmBits are 0, so that it doesn't work. I was thinking it had to do with the fact that the pictureboxes I'm getting the DCs from are autoredraw, but I'm not sure.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Originally posted by Sastraxi Did I not mention that? D'oh. That's what problem I'm having, that the bmBits are 0, so that it doesn't work. I was thinking it had to do with the fact that the pictureboxes I'm getting the DCs from are autoredraw, but I'm not sure.
Well... if that is because of the autoredraw, I would be even more confuse... you see, i've tried almost any way I know of putting a darn bitmap in a dc (by using loadimage for the bitmap and then selecting it in a dc, in a memory dc, creating a bimap with createcompatiblebitmap. I've tried using picutre.image in getobject etc... ) but always to the same result, bmbits is set to 0 all the f'n (sorry it slipped ) time.
Man! this is suppose to work... I guess we will need help from others to for this one.
I have to go to work soon, but i'll try to work something again when i come back.
- Valkan
'You keep creatures in cages and release them to fight? That's sick!'
Just posted this problem in the API forum... perhaps someone will be able to help with the getobject problem. Because as i've said before, i'm pretty sure the rest of your code is good.
BTW, good luck with the alphablend, i've tried implementing it once... was pretty cool, but awfully slow with big pictures. If you manage to do it fast, please send me the code
- Valkan
'You keep creatures in cages and release them to fight? That's sick!'
I've found out to get the pointer to bits in the BITMAP variable set to something else than 0. if you use picturebox.picture in the getobject call, it will work. But i still don't know why it doesn't work with a bitmap object thought...
'You keep creatures in cages and release them to fight? That's sick!'
Well, i'm the one who talked about the msdn being a great source for api info... and I didn't even when to check to description for the getobject function. Here is what i've found out:
If hgdiobj is a handle to a bitmap created by calling CreateDIBSection, and the specified buffer is large enough, the GetObject function returns a DIBSECTION structure. In addition, the bmBits member of the BITMAP structure contained within the DIBSECTION will contain a pointer to the bitmap's bit values.
If hgdiobj is a handle to a bitmap created by any other means, GetObject returns only the width, height, and color format information of the bitmap. You can obtain the bitmap's bit values by calling the GetDIBits or GetBitmapBits function.
this would also clarify for me the diference between the .picture and .image of a picturebox... .picture seems to be a dib (since it works with getobject) and .image is a ddb.
- Valkan
'You keep creatures in cages and release them to fight? That's sick!'
Excellent, my friend. Excellent, excellent, excellent, excellent. I'm really glad you've helped me with all this!
PS. The Get/SetPixel only takes 0.003 seconds, on average, to do a 16x16 alphablend. It takes a bit longer for a 20x25 (0.01 s) but it's pretty sufficient for what I'm using it for. I just wanted to be able to do it just this bit faster, hehe
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
GetDIBits is awesome. This works completely, 100% now. Excellent, man, excellent!
VB Code:
Public Function Morph2D(X As Long, Y As Long, NumRow As Long) As Long
Morph2D = (Y - 1) * NumRow + X
End Function
Public Function AlphaBltFast(ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal hAlphaDC As Long, ByVal xSrc As Long, ByVal ySrc As Long)
Dim I As Long
Dim J As Long
Dim TempR As Long
Dim TempG As Long
Dim TempB As Long
Dim AlphaVal As mRGB
Dim SrcVal As mRGB
Dim DestVal As mRGB
Dim dBitmap As Long
Dim dBMP As BITMAP
Dim dPic() As mRGB
Dim dMem As BITMAPINFO
Dim sBitmap As Long
Dim sBMP As BITMAP
Dim sPic() As mRGB
Dim sMem As BITMAPINFO
Dim aBitmap As Long
Dim aBMP As BITMAP
Dim aPic() As mRGB
Dim aMem As BITMAPINFO
dBitmap = GetCurrentObject(hDestDC, OBJ_BITMAP)
sBitmap = GetCurrentObject(hSrcDC, OBJ_BITMAP)
aBitmap = GetCurrentObject(hAlphaDC, OBJ_BITMAP)
GetObjectAPI dBitmap, Len(dBMP), dBMP
GetObjectAPI sBitmap, Len(sBMP), sBMP
GetObjectAPI aBitmap, Len(aBMP), aBMP
With dMem.bmiHeader
.biBitCount = 32
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(dMem.bmiHeader)
.biWidth = dBMP.bmWidth
.biHeight = dBMP.bmHeight
ReDim Preserve dPic(0 To (.biWidth * .biHeight) - 1) As mRGB
Great man! I'm happy to see you have succeded. Beside it was a pleasure helping you... heck, it made me learn new stuff too . stuff like the GDI can be a real pain in the ... sometime But hey, this was fun! Finally, I have a better understand of how to use the copy memory trick.
- Valkan
'You keep creatures in cages and release them to fight? That's sick!'
Sastraxi, I would like to see your subs in action. I've been programming vb for about 4 years. I made my own very easy to use blit subs. I still don't know what an hDC is, and Bitblt looks like a heap of technical gibberish (I realize that it copies data extremely rapidly). Mostly it's the hDC and 7 other parameters that go with it that make it look more like "loose wires" than a "control panel". That's why I say I would like to see you post an example of your subs in action.
Do you mind running compiled code? The reason I'm hesitant to post the actual code is that I've used some pretty bad coding practices to get this test done...
If you don't trust me, I'll post it, but I hope you do
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
And here's a screenshot Office, Apache, and EAC icons probably won't show up, I have their paths hard-coded. And if you don't have Winamp, it won't show up either. But IE should...
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Originally posted by Sastraxi Do you mind running compiled code? The reason I'm hesitant to post the actual code is that I've used some pretty bad coding practices to get this test done...
If you don't trust me, I'll post it, but I hope you do
I got an error message: "failed to delete C:\" What does that mean?
That's pretty cool, though. What are you planning to do with it/use it for?
intresting.. at first click I got .11s, and second and later i was getting .06 and even .00 (1ghz duron). I got "subscript out of" after clicking about 20 times.
Okay, but let me clean it up first. There's definately some stuff that's draining the memory like crazy, I'll do a test.
[EDIT]I've found the problem, which lies in the SmoothIconBlt function. I think it's the memory DCs I'm creating, let me check it and I'll post![/EDIT]
Last edited by Sastraxi; Nov 16th, 2002 at 01:25 PM.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Okay, DON'T run this program anymore, lol. It has a huge memory leak that eventually destroys all of your memory... lol. Anyway, you might notice that the subscript out of range is in a horrible, Win16-emulation bold font. That shows real trouble, so, like I said, don't use it until I figure out what's wrong with it
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
This was very tricky to find: in win98 that I use, when you double-click to start a file, a mouseup event occurs. It was causing an error in one of my projects.
Public Function SmoothIconBlt(ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal hExeSrc As String, ByVal hIndex As Long, ByVal hSmallIcon As Boolean, Optional SmoothValue As Long = smoothval) As Long
there gotta be some leaks left, cuz my comp gets really slow after using that program for a while, and i've got the error "cant create autoredraw image" or whatever it says...
Index Out of Bounds for SmoothMaskFast, is that your error? Yeah, I'm working on it, it doesn't seem to be fixed [yet]. There is also a MASSIVE memory leak in the TextBlt function (which is called by the CropTextBlt function, so both of them have leaks). If you can fix these, it'd be great.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)