Results 1 to 7 of 7

Thread: how to load png image into memory

  1. #1

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    how to load png image into memory

    I am currently loading bmp pictures in my program, but they are big files, how can I load png into the program for bitbliting?

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: how to load png image into memory

    Re-save the images as PNG's instead then use the same method to load them as you did before.
    I don't live here any more.

  3. #3

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Unhappy Re: how to load png image into memory

    i did that but it dosent load them in the memory, i get no picture. Uh better advice would be nice, this is what i have
    VB Code:
    1. '
    2. 'Chapter 1
    3. 'Memory Device Context
    4. '
    5.  
    6. Option Explicit
    7.  
    8. Public Declare Function TimeGetTime Lib "winmm.dll" () As Long
    9. Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    10. Public 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
    11. Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    12. Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    13. Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    14. Public Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
    15. Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    16.  
    17. 'Constants for the GenerateDC function
    18. '**LoadImage Constants**
    19. Global Const IMAGE_BITMAP As Long = 0
    20. Global Const LR_LOADFROMFILE As Long = &H10
    21. Global Const LR_CREATEDIBSECTION As Long = &H2000
    22. Global Const LR_DEFAULTSIZE As Long = &H40
    23. Global Const KEY_TOGGLED As Integer = &H1
    24. Global Const KEY_DOWN As Integer = &H1000
    25.  
    26. '****************************************
    27. Global Const SpriteWidth As Long = 50
    28. Global Const SpriteHeight As Long = 50
    29. Global time
    30. Global endmap, i
    31. Global nextmapright, mapright, looploop
    32. Global error
    33. Global DC As Long
    34. Global hBitmap As Long
    35.  
    36. Public Sub spriteload()
    37. sprnum = 4
    38.  
    39.  iFileNo = FreeFile
    40.      'open the file for reading
    41.  
    42.  
    43.     For z = 1 To 5 'reads all maps and saves them into array
    44.         Open "x:\mygame\map(" & z & ").txt" For Input As #iFileNo
    45.     For y = 1 To 11
    46.     For x = 1 To 15
    47.         Input #iFileNo, map0(z, x, y) 'reads map information
    48.     Next
    49.     Next
    50.         Close #iFileNo  'close the file (if you dont do this, you wont be able to open it again!)
    51.     Next
    52.   z = 0
    53. DeleteGeneratedDC grass(0) 'Generate the two DCs, one for the mask and one for the sprite
    54. DeleteGeneratedDC grass(1)
    55. 'generates all sprites (one line!!!)
    56.  
    57. 66
    58.     For i = 0 To sprnum
    59.         grass(i) = GenerateDC("x:\mygame\grass(" & i & ").bmp") 'png dosent work
    60.     Next
    61. 'checks for errors and loads up to 10 times
    62.     For i = 0 To sprnum
    63.         If grass(i) <= 0 Then
    64.         error = error + 1
    65.     If error = 200 Then Exit Sub
    66.         GoTo 66
    67.     End If
    68.     Next
    69.  
    70.     End Sub
    71. 'Deletes a generated DC
    72. Public Function DeleteGeneratedDC(DC As Long) As Long
    73.  
    74. If DC > 0 Then
    75.     DeleteGeneratedDC = DeleteDC(DC)
    76. Else
    77.     DeleteGeneratedDC = 0
    78. End If
    79.  
    80. End Function
    81. 'IN: FileName: The file name of the graphics
    82. 'OUT: The Generated DC
    83. Public Function GenerateDC(FileName As String) As Long
    84.  
    85.  
    86. 'Create a Device Context, compatible with the screen
    87. DC = CreateCompatibleDC(0)
    88.  
    89. If DC < 1 Then
    90.     GenerateDC = 0
    91.     Exit Function
    92. End If
    93.  
    94. 'Load the image....BIG NOTE: This function is not supported under NT, there you can not
    95. 'specify the LR_LOADFROMFILE flag
    96. hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE Or LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
    97.  
    98. If hBitmap = 0 Then 'Failure in loading bitmap
    99.     DeleteDC DC
    100.     GenerateDC = 0
    101.     Exit Function
    102. End If
    103.  
    104. 'Throw the Bitmap into the Device Context
    105. SelectObject DC, hBitmap
    106.  
    107. 'Return the device context
    108. GenerateDC = DC
    109.  
    110. 'Delte the bitmap handle object
    111. DeleteObject hBitmap
    112.  
    113. End Function

    thats what i have i dont know if that helps? I dont know how to do it
    Last edited by damasterjo; Nov 18th, 2005 at 08:22 AM.

  4. #4
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: how to load png image into memory

    Quote Originally Posted by damasterjo
    Uh better advice would be nice
    Yes, it would be, wouldn't it? What a shame you're not getting it from me. If you are going to be so vague with your questions then you could at least be polite when some help is offered.
    I don't live here any more.

  5. #5

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: how to load png image into memory

    im sorry i am not very tactful. I guess the question was vague and I did not specify that i was loading the images to the memory. But whatever if you dont want to help i understand. Anybody else have any idea?

  6. #6
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: how to load png image into memory

    It should also be said that the vbcode tags around your code would be nice, to help read it.

    Perhaps IMAGE_BITMAP isn't what you require. Forgotten the values of the others, but it should be on these forums or the internet somewhere.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  7. #7

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: how to load png image into memory

    that is probably the problem but im not sure what it is sopost to be.?

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