Results 1 to 8 of 8

Thread: Pics not fully loading

  1. #1

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901

    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:
    1. Function LoadBitmap(iFileName As String) As Long
    2.     Dim A As Long
    3.    
    4.     If Dir(iFileName) = "" Then
    5.         'Error: File not found
    6.         LoadBitmap = -1
    7.        
    8.         Exit Function
    9.     End If
    10.    
    11.     'Check if already loaded
    12.     For A = 0 To BitmapCount
    13.         If Bitmap(A).FileName = LCase(iFileName) Then
    14.             'Bitmap already loaded
    15.             LoadBitmap = A
    16.                
    17.             Exit Function
    18.         End If
    19.     Next
    20.    
    21.     'Allocate memory
    22.     BitmapCount = BitmapCount + 1
    23.     ReDim Preserve Bitmap(BitmapCount)
    24.    
    25.     'Load file
    26.     LoadDC iFileName, Bitmap(BitmapCount)
    27.    
    28.     'Return index
    29.     If Bitmap(BitmapCount).DC > -1 Then
    30.         LoadBitmap = BitmapCount
    31.     Else
    32.         LoadBitmap = -1
    33.     End If
    34. End Function
    35.  
    36.  
    37.  
    38. Function LoadDC(iFileName As String, iBitmap As tBitmap) As Long
    39.     Dim DC As Long
    40.     Dim Temp As IPictureDisp
    41.    
    42.     'Create compatible DC
    43.     DC = CreateCompatibleDC(MainWindow.hdc)
    44.    
    45.     If DC < 1 Then
    46.         'Error: Can't create compatible DC
    47.         LoadDC = -1
    48.        
    49.         Exit Function
    50.     End If
    51.    
    52.     'Load bitmap
    53.     Set Temp = LoadPicture(iFileName)
    54.     SelectObject DC, Temp
    55.    
    56.     'Apply values
    57.     With iBitmap
    58.         .FileName = LCase(iFileName)
    59.        
    60.         .DC = DC
    61.     LoadDC = DC
    62.        
    63.         .W = MainWindow.ScaleX(Temp.Width)
    64.         .H = MainWindow.ScaleY(Temp.Height)
    65.     End With
    66.  
    67.    
    68.     'Release memory
    69.     DeleteObject Temp
    70.     Set Temp = Nothing
    71. End Function


    in form
    VB Code:
    1. mBitmap.Initialize Me
    2.     For A = 0 To 8
    3.         mBitmap.LoadBitmap App.Path & "\" & A & ".jpg"
    4.     Next
    5.    
    6.    
    7.     Dim i As Integer
    8.     For i = 0 To UBound(Bitmap)
    9.         List1.AddItem Bitmap(i).FileName
    10.     Next
    Any suggestions why this does not werk?


    Screen shot
    Attached Images Attached Images  

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    Have you tried stepping through the code to see where it's failing?

  3. #3

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    I know whats doing it..
    its this part..

    VB Code:
    1. DC = CreateCompatibleDC(MainWindow.hdc)
    2.    
    3.     If DC < 1 Then
    4.         'Error: Can't create compatible DC
    5.         LoadDC = -1
    6.        
    7.         Exit Function
    8.     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

  4. #4
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    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?

  5. #5

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    No.

    Because if i start the program again..
    Different pictures load//dont load.
    Confusing..
    Still works though.. should i leave it at that?

    seahag

  6. #6
    Addicted Member
    Join Date
    Aug 2002
    Location
    Baltimore, MD
    Posts
    230
    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.

  7. #7
    Lively Member
    Join Date
    Mar 2002
    Posts
    110
    try this

    DC = CreateCompatibleDC(0)

  8. #8

    Thread Starter
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    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
  •  



Click Here to Expand Forum to Full Width