Author Topic: Load images  (Read 3857 times)

0 Members and 1 Guest are viewing this topic.

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Load images
« on: October 29, 2020, 08:03:30 pm »
I am just trying understand the graphics commands. I have a problem with loading an image - even examples from the wiki do not work. The editor shows OK. Can someone tell me where the problem is? Thank you!

Code: QB64: [Select]
  1.  
  2. DIM NeuesFenster AS LONG, Bild AS LONG
  3.  
  4. NeuesFenster = _NEWIMAGE(1024, 768, 256)
  5. SCREEN NeuesFenster
  6.  
  7. COLOR 0, 11
  8. LOCATE (CSRLIN + 2), POS(0)
  9. PRINT "Hallo, QuickBasic 64!"
  10.  
  11. 'Bild laden
  12. Bild = _LOADIMAGE("MaedchenSozial.jpg", 32)
  13. SCREEN Bild
  14. _PUTIMAGE (0, 0), Bild
  15.  
  16. 'Neue Farbe setzen
  17. COLOR 7, 0
  18. _PALETTECOLOR 7, &HFFDAA520
  19.  
  20. 'Mit Schriften arbeiten + positionieren
  21. Text = "Em todas as religioes ha amor, mas o amor nao tem religiao."
  22.  
  23. _FONT _LOADFONT("C:\Windows\Fonts\Cour.ttf", 20, "Monospace")
  24.  
  25. 'Zeile, Spalte (Row, Column)
  26. _PRINTSTRING (150, 460), Text
  27.  
  28. 'Farbe und Schrift zuruecksetzen
  29. COLOR 15, 0
  30.  
  31.  

Example from the wiki at _Putimage

Code: QB64: [Select]
  1. DEFLNG A-Z
  2. dest_handle = _NEWIMAGE(640, 480, 32)
  3. SCREEN dest_handle '32 bit Screen 12 dimensions
  4.  
  5. 'Bild wird nicht geladen
  6. source_handle = _LOADIMAGE("QB64.PNG", 32)
  7.  
  8. dx1 = 0: dy1 = 0
  9. . . .
  10.  
Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Load images
« Reply #1 on: October 29, 2020, 08:54:56 pm »
For sure, you don't need this:
Code: QB64: [Select]
  1. SCREEN Bild  

_PUTIMAGE does the job of putting the image where you want.

then it's just a matter of finding the image file you want to load and you can check if the image handle assigned is not -1, -1 means no load!

 This is interesting:
Code: QB64: [Select]
  1. _FONT _LOADFONT("C:\Windows\Fonts\Cour.ttf", 20, "Monospace")

ususally its
Code: QB64: [Select]
  1. myFont& = _LOADFONT("C:\Windows\Fonts\Cour.ttf", 20, "Monospace")

Load to LONG type handle, then call
Code: QB64: [Select]
  1. _FONT myFont&

that way you can switch fonts without reload of a font.

« Last Edit: October 29, 2020, 09:01:21 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Load images
« Reply #2 on: October 29, 2020, 10:08:22 pm »
NeuesFenster = _NEWIMAGE(1024, 768, 256)
SCREEN NeuesFenster
Bild = _LOADIMAGE("MaedchenSozial.jpg", 32)
SCREEN Bild

A couple of problems with the above.  First, you set NeuesFenster to a 256 color screen.  Then you load a 32-bit color image.  Then you swap screens, throwing away the 256 color screen....

I would think you’d want more of:

NeuesFenster = _NEWIMAGE(1024, 768, 32) ‘USE A 32-bit screen
SCREEN NeuesFenster
 
COLOR _RGB32(0,0,0), _RGB32(255, 255, 0)’MUST USE 32-BIT COLOR VALUES
LOCATE (CSRLIN + 2), POS(0)
PRINT "Hallo, QuickBasic 64!"
 
'Bild laden
Bild = _LOADIMAGE("MaedchenSozial.jpg", 32)
‘SCREEN Bild ‘NO NEED FOR THIS
_PUTIMAGE (0,0), Bild
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Load images
« Reply #3 on: October 30, 2020, 09:25:01 am »
Thanks for the help. The picture - I think I now know how "_Loadimage" works. The picture have to be in the same directory as the program and the full path have to be specified.

That will not do:
"MaedchenSozial.jpg"
"..\Bilder\MaedchenSozial.jpg"
"D:\Lab\QuickBasic64\Grafik\Bilder\MaedchenSozial.jpg"

That's working:
"D:\Lab\QuickBasic64\Grafik\MaedchenSozial.jpg"
The full path and it have to in the same directory.

Code: QB64: [Select]
  1. 'Uebungen mit Fenstern, Farben und Bildern
  2.  
  3.  
  4. DIM NeuesFenster AS LONG, Bild AS LONG
  5.  
  6. NeuesFenster = _NEWIMAGE(1024, 768, 32)
  7. SCREEN NeuesFenster
  8.  
  9. 'Vordergrund- und Hintergrundfarbe
  10. COLOR _RGB32(255, 0, 0), _RGB32(255)
  11. LOCATE (CSRLIN + 2), POS(0)
  12. PRINT "Hallo, QuickBasic 64!"
  13.  
  14.  
  15. 'Bild laden
  16. Bild = _LOADIMAGE("D:\Lab\QuickBasic64\Grafik\MaedchenSozial.jpg", 32)
  17. 'SCREEN Bild - Spalte, Zeile
  18. _PUTIMAGE (260, 120), Bild
  19.  
  20. 'Neue Farbe setzen
  21. COLOR _RGB32(255, 165, 0), _RGB32(0, 0, 0)
  22. '_PALETTECOLOR 7, &HFFDAA520
  23.  
  24. 'Mit Schriften arbeiten + positionieren
  25. Text = "Em todas as religioes ha amor, mas o amor nao tem religiao."
  26.  
  27. _FONT _LOADFONT("C:\Windows\Fonts\Cour.ttf", 20, "Monospace")
  28.  
  29. 'Zeile, Spalte (Row, Column)
  30. _PRINTSTRING (140, 560), Text
  31.  
  32. 'Farbe und Schrift zuruecksetzen
  33. COLOR _RGB32(255), _RGB32(0, 0, 0)
  34.  
  35.  

Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Load images
« Reply #4 on: October 30, 2020, 09:40:41 am »
The path doesn't have to be the full path to the file, but it does need to be relative to where the EXE is located at.

For example, it seems that you have QB64 installed in: D:\Lab\QuickBasic64\"

If you want to put an image in "D:\Lab\QuickBasic64\Grafik\Bilder\MaedchenSozial.jpg", then you can either use the whole path, or the path relative to the QB64 folder (see note below).

So _LOADIMAGE("D:\Lab\QuickBasic64\Grafik\Bilder\MaedchenSozial.jpg",32) should work.

_LOADIMAGE(".\Grafik\Bilder\MaedchenSozial.jpg") should also work, as the base directory would be D:\Lab\QuickBasic64\, which would be the starting point for pathing to the file.


NOTE:  This is assuming that the EXE you create with QB64 is located inside your QB64 root directory.  If you have the "Save EXE with source" option checked, and the BAS file you're compiling is in a subfolder somewhere, then the EXE will be created in that subfolder, changing the starting point of file paths to that directory instead. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Load images
« Reply #5 on: October 30, 2020, 01:26:16 pm »
Now I understand. QB64 is installed in "D: \ Programme \ qb64", and there are the EXE-files. "D: \ Lab \ QuickBasic 64 \ ..." is the working directory. Now are the EXE-files in the same directory like the source files. Learning by doing. ;-)

Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Load images
« Reply #6 on: October 30, 2020, 03:58:14 pm »
Quote
Now are the EXE-files in the same directory like the source files.

There is an Option under the Run Menu in the IDE, put a bullet next to:
"Output EXE to Source Folder"

otherwise EXE's will be in QB64.exe Folder (same as untitled, unsaved Runs). Where the EXE's are is the base folder or path where files are sought. Paths should be relative to the EXE folder unless fully pathed.

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Load images
« Reply #7 on: October 30, 2020, 04:59:13 pm »
Yes, I hadn't noticed / didn't notice that yet. Now I know it and I have see it. Thanks for yours hints.

This works.
Code: QB64: [Select]
  1. 'Speicherort EXE- und Programmdateien - 30.10.2020
  2.  
  3.  
  4. SCREEN _NEWIMAGE(800, 600, 32)
  5.  
  6. DIM Bild AS LONG, myFont AS LONG
  7. DIM Text AS STRING, Text2 AS STRING
  8.  
  9. 'Neue Farbe setzen
  10. COLOR _RGB32(255, 165, 0), _RGB32(0, 0, 0)
  11.  
  12. Bild = _LOADIMAGE("Bilder\Marilyn-1956.jpg") 'see note below examples to get the image
  13. _PUTIMAGE (140, 15), Bild 'places image at upper left corner of window w/o stretching it
  14.  
  15. Text = "A wise girl kisses but doesn't love, listens but doesn't believe,"
  16. Text2 = " and leaves before she is left."
  17. myFont = _LOADFONT("C:\Windows\Fonts\Dauphinn.ttf", 25, "")
  18. _FONT myFont
  19.  
  20. 'Zeile, Spalte (Row, Column)
  21. _PRINTSTRING (135, 510), Text
  22. _PRINTSTRING (256, 537), Text2
  23.  
  24. 'Farbe und Schrift zuruecksetzen
  25. COLOR _RGB32(255), _RGB32(0, 0, 0)
  26. _FREEFONT myFont
  27.  
  28.  

;-)
Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Load images
« Reply #8 on: October 30, 2020, 07:54:32 pm »
For a better understanding: This is my file system:

Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“