Results 1 to 6 of 6

Thread: A couple graphics questions...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Post

    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.

  2. #2
    Lively Member
    Join Date
    Jun 1999
    Location
    Ireland
    Posts
    96

    Post

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Post

    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?

  4. #4
    Lively Member
    Join Date
    Jun 1999
    Location
    Ireland
    Posts
    96

    Post

    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Cleveland, Ohio
    Posts
    263

    Post

    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?

  6. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width