Aug 6th, 2002, 01:24 PM
#1
Thread Starter
Fanatic Member
Pics not fully loading
The cod i am using to load pictures into memory is not
fully working.
Its seem spuratic.... loading some ..sometimes.. then others..other times.
Heres the code
Im module mBitmap
VB Code:
Function LoadBitmap(iFileName As String) As Long
Dim A As Long
If Dir(iFileName) = "" Then
'Error: File not found
LoadBitmap = -1
Exit Function
End If
'Check if already loaded
For A = 0 To BitmapCount
If Bitmap(A).FileName = LCase(iFileName) Then
'Bitmap already loaded
LoadBitmap = A
Exit Function
End If
Next
'Allocate memory
BitmapCount = BitmapCount + 1
ReDim Preserve Bitmap(BitmapCount)
'Load file
LoadDC iFileName, Bitmap(BitmapCount)
'Return index
If Bitmap(BitmapCount).DC > -1 Then
LoadBitmap = BitmapCount
Else
LoadBitmap = -1
End If
End Function
Function LoadDC(iFileName As String, iBitmap As tBitmap) As Long
Dim DC As Long
Dim Temp As IPictureDisp
'Create compatible DC
DC = CreateCompatibleDC(MainWindow.hdc)
If DC < 1 Then
'Error: Can't create compatible DC
LoadDC = -1
Exit Function
End If
'Load bitmap
Set Temp = LoadPicture(iFileName)
SelectObject DC, Temp
'Apply values
With iBitmap
.FileName = LCase(iFileName)
.DC = DC
LoadDC = DC
.W = MainWindow.ScaleX(Temp.Width)
.H = MainWindow.ScaleY(Temp.Height)
End With
'Release memory
DeleteObject Temp
Set Temp = Nothing
End Function
in form
VB Code:
mBitmap.Initialize Me
For A = 0 To 8
mBitmap.LoadBitmap App.Path & "\" & A & ".jpg"
Next
Dim i As Integer
For i = 0 To UBound(Bitmap)
List1.AddItem Bitmap(i).FileName
Next
Any suggestions why this does not werk?
Screen shot
Attached Images
Aug 7th, 2002, 02:54 PM
#2
Addicted Member
Have you tried stepping through the code to see where it's failing?
Aug 7th, 2002, 03:00 PM
#3
Thread Starter
Fanatic Member
I know whats doing it..
its this part..
VB Code:
DC = CreateCompatibleDC(MainWindow.hdc)
If DC < 1 Then
'Error: Can't create compatible DC
LoadDC = -1
Exit Function
End If
Problem is I dont know what i am doing ...
I see this code in alot of examples..
The number is -dc .. so function exits.
if i comment out End Function it work ok..
Myabe the question should be why is it in there ?
Seahag
Aug 7th, 2002, 03:07 PM
#4
Addicted Member
Is the graphics that's not loaded a different color depth than the others? Is there anything different about it that would be causing it to fail?
Aug 7th, 2002, 04:12 PM
#5
Thread Starter
Fanatic Member
No.
Because if i start the program again..
Different pictures load//dont load.
Confusing..
Still works though.. should i leave it at that?
seahag
Aug 7th, 2002, 10:39 PM
#6
Addicted Member
I would try to figure out what the problem is. That's not the kind of thing you want to leave hanging around I would think. Try calling the GetLastError API function to see exactly what the problem is.
Aug 8th, 2002, 05:53 AM
#7
Lively Member
try this
DC = CreateCompatibleDC(0)
Aug 8th, 2002, 07:17 AM
#8
Thread Starter
Fanatic Member
golgo13sf that doesnt work either.
?
Machaira, i dont know API very well at all..
Kinda learning that right now
Thanks for your replies..
Seahag
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width