Solved

Loading Transparent Gif and Use WINAPI to Blit it out

Posted on 2002-05-30
14
439 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now