Solved

Loading Transparent Gif and Use WINAPI to Blit it out

Posted on 2002-05-30
14
448 Views
Last Modified: 2008-03-10
I would like to use bitblt to blit a gif bitmap...
How can it be done? How can it be opened loaded into device and being
blitted.
Could provide some src code?
Thanks
Jack
0
Comment
Question by:luckie
  • 8
  • 5
14 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7046187
Why do you need to use bitblt?
Could you explain a bit more?
You could load an image in a stdpicture object with a simple LoadPicture function (if you don't want to use an ima/picture box control).
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7046194
Also PaintPicture method of form/picture box/printer objects.
0
 

Author Comment

by:luckie
ID: 7046351
Because LoadPicture was too slow and the screen was flickering.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:luckie
ID: 7046357
here is a bit of code:
Dim objPics(2) As Image





Dim blnStartCapture As Boolean
Dim blnAmCapturing As Boolean
Dim intHandleDisplay As Integer
Dim intStartX As Integer
Dim intStartY As Integer
Dim intMouseX As Integer
Dim intMouseY As Integer
Dim intOldMouseX As Integer
Dim intOldMouseY As Integer



Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, lpInitData As DEVMODE) As Long
Private Declare Function SetROP2 Lib "gdi32" (ByVal hdc As Long, ByVal nDrawMode As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
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 ReleaseCapture Lib "user32" () As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
 

Public i, j, k

Private Sub ActiveXPlugin1_GotFocus()

End Sub

 Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    Debug.Print x, y, Point(x, y)
End Sub




Private Sub Form_Load()
 '  ImageList1.MaskColor = &H595959
 '  Set Picture2.Picture = ImageList1.Overlay(2, 1)
   Dim i As Single, j As Single
   Dim devDevMode As DEVMODE

   
   Set objpic(0) = New Image
   Set objpic(1) = New Image  ' doesn't work
   
   WindowState = 2
  ' Open "C:\images\2tran.gif" For Input As #1
   
    Set objPics(0).Picture = LoadPicture("C:\images\2tran.gif")
    Set objPics(1).Picture = LoadPicture("C:\images\3tran.gif")
   
   
 
'   intHandleDisplay = CreateDC("DISPLAY", 0&, 0&, devDevMode)
   
'   AutoRedraw = True

'   For i = 0 To ScaleWidth Step 15
'        For j = 0 To ScaleHeight Step 15
'            PSet (i, j), QBColor(Int(Rnd(1) * 16))
'        Next j
'    Next i
   
   'Image1.BackColor = QBColor(&H5855577)
   i = 0
   j = 0
   k = 0
   Timer1.Interval = 10
   Timer1.Enabled = True
   Timer2.Interval = 10
   Timer2.Enabled = True
   Timer3.Interval = 10
   Timer3.Enabled = True
   'Set Picture1.Picture = ImageList1.Overlay(2, 1)
   
   'Picture1.ZOrder 0
   
  ' Picture2.ZOrder 1
   
End Sub
 


Private Sub Speed_Click()
    Form2.Show
     
End Sub

Private Sub Timer1_Timer()
   i = i + 10
   If (i >= 0 And i < 1000) Then
      PaintPicture objPics(0), 100, 100, 100, 100, 10, 10, 100, 100, vbSrcPaint
     
     
'     Image1.Left = Image1.Left - 1
   ElseIf (i > 1000 And i < 2000) Then
'        If (i = 1000) Then
'            Image1.Picture = LoadPicture("C:\images\2tran.gif")
'        ElseIf (i = 1100) Then
'            Image1.Picture = LoadPicture("C:\images\3tran.gif")
'        ElseIf (i = 1200) Then
'            Image1.Picture = LoadPicture("C:\images\4tran.gif")
'        ElseIf (i = 1300) Then
'            Image1.Picture = LoadPicture("C:\images\5tran.gif")
'        End If
       
   
'     Image1.Top = Image1.Top - 1
'     Image1.Left = Image1.Left - 1
'  ElseIf (i > 2000 And i < 3000) Then
'     Image1.Picture = LoadPicture("C:\images\6tran.gif")
'     Image1.Top = Image1.Top - 1
'  ElseIf (i > 3000) Then
'     Image1.Picture = LoadPicture("C:\images\7tran.gif")
     
   End If
     
   
   
   
   
End Sub

Private Sub Timer2_Timer()
 j = j + 1
'If (j >= 1 And j < 1000) Then
'     Picture2.Left = Picture2.Left - 1
'   ElseIf (j > 1000 And j < 1500) Then
'     Picture2.Top = Picture2.Top - 1
'     Picture2.Left = Picture2.Left - 1
'   ElseIf (j > 1500) Then
'     Picture2.Top = Picture2.Top - 1
   
'   End If
End Sub

Private Sub Timer3_Timer()
 k = k + 1
 
End Sub
0
 

Author Comment

by:luckie
ID: 7046393
When I continously loading the picture, the image will flicker, do u have the solution for this?
regards
Jack
0
 

Author Comment

by:luckie
ID: 7046467
I tried to use block transfer, but when I loaded the file (transparent gif) into the DC, it became white in the background....any suggestions? Picture objects don't have stretch, but I don't know how to do it with an image object
sob... (hence connecting the DC with the 'IMAGE' Object)


Thanks
Jack
0
 

Author Comment

by:luckie
ID: 7046470
with picture boxes, the image was heaps bigger than the picture box... oh no
Jack
0
 

Author Comment

by:luckie
ID: 7046473
and with picture boxes, it doesn't deal with the transparency of gif's...! any advice
Jack
0
 

Author Comment

by:luckie
ID: 7046478
I beg your pardon, it did support transparency! sorry about it.
Jack
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7046991
you could try using an array of stdpictures and before start the animation, populate that array with all pictures that you need to use.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7047159
Although picture boxes don't support stretch directly, you can stretch using the PaintPicture method.

Also, the image property contains the "working" image of the picturebox and will become the "background" image by assigning it to the picture property.
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 50 total points
ID: 7047338
By the way, re-reading your comment, there is no DC for an Image control.

try to follow this steps and let me know:
sub test
dim arrPics() as stdpicture
dim arrFiles() as string
dim lcount as long,i as long

arrfiles=retenumfiles(lcount,"c:\myimages",vbarchive,"*.gif")

for i= 0 to lcount
    redim preserve arrpics(i)
    arrpics(i)=loadpicture(arrfiles(i))
next i
end sub

Private Function RetEnumFiles(lCount As Long, sPath As String, ftype As VbFileAttribute, Optional sType As String = "*.*") As String()
Dim ff As String, arrfiles() As String
Dim filecount As Long

ff = Dir$(sPath & sType, ftype)
Do While ff <> ""
    If ff <> "." And ff <> ".." Then
      If GetAttr(sPath & ff) = ftype Then
        ReDim Preserve arrfiles(filecount)
        arrfiles(filecount) = sPath & "\" & ff
        filecount = filecount + 1
      End If
    End If
    ff = Dir$()
Loop
lCount = filecount - 1
RetEnumFiles = arrfiles
End Function

'And call your timer, something like...
static i as long

image.picture=arrpics(i)
i=i+1
0
 

Author Comment

by:luckie
ID: 7274084
Great Thanks
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7277466
Glad to help and thanks for "A" grade.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question