Click to See Complete Forum and Search --> : A couple graphics questions...
Phobic
Dec 9th, 1999, 09:25 AM
OK, I got the basics on using BitBlt, MaskBlt, etc., but would anyone be able to help me in:[list=1]
Setting the % Transparency when merging to images?
Loading a graphic from file (the API way!)?
Saving a graphic to file (yes, also the API way!)?
[/list=a]
Thanks for your time.
SteveS
Dec 9th, 1999, 09:49 AM
1. What do you mean the % transparency?
2. To load a BitMap using API calls, I assume you mean, storing the BitMap in a memory only area with a hDC property which you can use with BitBlt.
Then load it as normal into an invisible picture box then,
Declare the following
Private Declare Function BitBlt Lib "gdi32" (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 xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
'THEN TO LOAD THE BITMAP
'Display.hDC is needed to create a compatable hDC to the one where you will display the bitmap
'The Forms ScaleMode = 3 (vbPixels)
BitMapName = "C:\MyBitMap.Bmp"
DisplayhDC = Form1.hDC
'Load Picture to Temp. Memory
picLoad.Picture = LoadPicture(BitMapName)
'hDC Declaration (Sprite File)
i = hDC_Obtain(Displayhdc, iDC, iBmp, picture1.Width, picture1.Height)
i = BitBlt(iDC, 0, 0, picture1.Width, picture1.Height, picture1.hdc, 0, 0, vbSrcCopy)
'The hDC Get Routine
Private Function hDC_Obtain(hdc As Long, iDC As Long, iBmp As Long, PWidth As Long, PHeight As Long) As Boolean
Dim i As Long
hDC_Obtain = False
iDC = CreateCompatibleDC(hdc)
If iDC Then
iBmp = CreateCompatibleBitmap(hdc, PWidth, PHeight)
If iBmp Then
iBmp = SelectObject(iDC, iBmp)
hDC_Obtain = True
Else
i = DeleteDC(iDC)
End If
End If
End Function
3. Saving using API, why not just copy back to the picturebox an save it from there.
Hope this helps,
Steve.
Phobic
Dec 9th, 1999, 10:05 AM
By % transparency, I mean, well, have you ever merged to images with BitBlt? It basically takes each pixel color of the same point on both rectangles, and averages them, so that's about 50% transparency. What if I wanted to make it a 25% to 75% ratio between to graphics? I've been able to do it with the SetPixelV and GetPixel... but it's so long! Any ideas?
SteveS
Dec 9th, 1999, 10:12 AM
As far as I know, you use operators like
vbSrcCopy etc..., these have different values that allow the Copy'ing, And'ing, XOr'ing etc... of the bit values of the 2 images colours.
In order to change the degree to which you alter 1 image in relation to the other, I would say you would have to do it on a pixel by pixel basis.
You could try using other values, other that the preassigned ones (eg vbSrcCopy), in the raster operation field in BitBlt and see if that yields the result you want, but I think it will maybe return an error.
In that case I don't think you can use BitBlt.
Sorry,
Steve.
Phobic
Dec 10th, 1999, 06:52 AM
Heh, yes I know I've already done that. And as far as that code to open a picture through API is concerned, I meant by avoiding the LoadPicture function. Can't I load and save file with something like the LoadBitmap or LoadImage API calls? Anyone experienced with those?
Frans C
Dec 10th, 1999, 11:20 AM
For a complete overview on raster operations you can use with bitblt, look in the MSDN library. Search for 'Raster Overview' in the index, and then select 'ternary raster operations'. There should be 256 different ones.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.