Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A couple of loadimage questions.
#1
Replace temp14fe78.png with any handy image you have.

Code: (Select All)
Img& = _LoadImage("temp14fe78.png", 32) ' If , 32 is not used the screen must be created, first.
If Img& >= -1 Then Print "Image not found.": End
Screen _NewImage(640, 400, 32): Cls , _RGB32(255, 255, 255)
_Source Img&
clr~& = Point(0, 0) ' Get background color from image source.
_Dest 0
a& = 0: d% = 1
Do
    _Limit 120
    a& = a& + d%
    If a& = 255 Or a& = 0 Then d% = -d%
    If a& = 0 Then cc` = Not cc` ' Switches ClearColor on and off.
    _SetAlpha a&, , Img&
    If cc` Then _ClearColor clr~&, Img&
    Cls ' Required to apply alpha transparency.
    _PutImage (0, 0), Img&
    Locate 1, 1: Print "Alpha:"; a&; "| ClearColor: ";: If cc` Then Print "ON "; Else Print "OFF ";
    _Display
Loop Until _KeyHit
System

So I noticed that if I could measure the image dimensions, I could use those to make the screen the image size.

1) Is there a way to measure the image size when _loadimage is used?

2) I also noticed that using the format: _LoadImage("ImageName", 32) compared to using _LoadImage("ImageName") without the 32-bit image optional mode added, the program will fail unless the screen is created BEFORE the image is loaded. Why is that?

Pete
Reply
#2
X = _Width(img)
Y = _Height(img)
Reply
#3
COOL! +1

Earn another point if you can answer question #2 in that post.

Pete
Reply
#4
Quote:So I noticed that if I could measure the image dimensions, I could use those to make the screen the image size.
Well, it works perfectly for me!  Tongue

[Image: Franziska2025-04-12.jpg]

PS: What I can't find in the Wiki is how can I find out the size of the image to be loaded?
Reply
#5
(04-12-2025, 04:58 PM)Pete Wrote: 2) I also noticed that using the format: _LoadImage("ImageName", 32) compared to using _LoadImage("ImageName") without the 32-bit image optional mode added, the program will fail unless the screen is created BEFORE the image is loaded. Why is that?

Pete

Sorry.  I was in town earlier on only had my phone for typing.  Needless to say, you're not going to get any detailed explanation from old Steve and his poor knuckles on that damn thing!  Big Grin

This answer is very simple:

Code: (Select All)
Screen 12
Img& = _LoadImage("temp14fe78.png") ' If , 32 is not used the screen must be created, first.
If Img& >= -1 Then Print "Image not found.": End
Print _PixelSize(Img&); " <-- a 1 here indicates that we're loaded in 256 color mode."
_FreeImage Img&
Sleep 'so you can see that first result before we swap screens.

Screen _NewImage(640, 480, 32)
Img& = _LoadImage("temp14fe78.png") ' If , 32 is not used the screen must be created, first.
If Img& >= -1 Then Print "Image not found.": End
Print _PixelSize(Img&); " <-- a 4 here indicates that we're loaded in 32 color mode."

Run the above; you'll see what's going on quickly.  Without a specified screen mode, the image tries to load and match the one you currently have, matching palettes, blah, blah, blah.   Without having a screen mode set, QB64 defaults to SCREEN 0.  Of course, you can't load a graphical image onto SCREEN 0, so it... explodes and tosses you that error.

Specify:
_LoadImage("foo", 32) to force 32-bit image to load.
_LoadImage("foo", 256) to force 256 color image to load.
_LoadImage("foo", 257) to force 256 adaptive palette image to load.

But _LoadImage("foo"), with no specification, tries to default to the same as the current screen, and that's not going to work in this case, so it screams and shouts and yells, "PETE IS A BIG ZERO!!!" 

Big Grin

Now, where's my point for pointing out, "PETE IS A BIG ZERO!!!"   Big Grin Big Grin Big Grin Big Grin Big Grin Big Grin Big Grin
Reply
#6
(04-12-2025, 07:25 PM)Kernelpanic Wrote: What I can't find in the Wiki is how can I find out the size of the image to be loaded?

Easiest thing here is just to load the image, then use _WIDTH and _HEIGHT to get those dimensions, then free it.

If that seems unacceptable, then next simplest is to just do a powershell script for the info:

Code: (Select All)
image$ = _CWD$ + "temp14fe78.png"

Open "getinfo.ps1" For Output As #1
Print #1, "# Specify the path to your images"
Print #1, "$Path = '" + image$ + "' # Adjust the path and file type as needed"

Print #1, "# Retrieve image dimensions"
Print #1, "Get-ChildItem -Path $Path | ForEach-Object {"
Print #1, " $image = New-Object -ComObject Wia.ImageFile"
Print #1, " $image.LoadFile($_.FullName) # Load the image"

Print #1, " # Output the filename and dimensions"
Print #1, " [PSCustomObject]@{"
Print #1, " FileName = $_.FullName"
Print #1, " Width = $image.Width"
Print #1, " Height = $image.Height"
Print #1, " }"
Print #1, "} | Export-Csv -Path 'temp.txt' -NoTypeInformation"
Close

$Console:Only
Shell _Hide "powershell ./getinfo"
Open "temp.txt" For Input As #1
Do Until EOF(1)
Line Input #1, info$
Print info$
Loop
Close

The above writes the info for you into a CSV file so you can just INPUT the fields directly without having to parse anything. I used LINE INPUT here just to show the output in its raw form for you. Wink
Reply
#7
If an A is 4pts, and an F is 0 points... a C must be worse than an F because it's only half a O... The left half.

Thanks Lucy. +1 for the esplanin' 

Pete Big Grin
Reply
#8
Quote:Easiest thing here is just to load the image, then use _WIDTH and _HEIGHT to get those dimensions, then free it.
Thanks for the tip. I had the same idea last night, but I didn't feel like trying it anymore. It works. I've now implemented it with a procedure. Can it be simplified even further? We'll see. - The images are in the 7z file if anyone wants to try it out.

Code: (Select All)

'Bildanzeigen mit Prozedur - 13. April 2025

Option _Explicit

Declare Sub Bildanzeigen(bild As Long)

Dim As Long bild

bild = _LoadImage("Franziska.jpg", 32)
If bild >= -1 Then Print "Image not found.": End
Call Bildanzeigen(bild)
Sleep 5

bild = _LoadImage("Lady.jpg", 32)
Call Bildanzeigen(bild)
Sleep 5

bild = _LoadImage("Alexandra.jpg", 32)
Call Bildanzeigen(bild)
Sleep 5

bild = _LoadImage("Kyffhaeuserdenkmal.jpg", 32)
Call Bildanzeigen(bild)
Sleep 5

End 'Hauptprogramm

Sub Bildanzeigen (bild As Long)

  Dim As Long BH, BW

  'BH = bild1Hoehe, BW = bild1Weite(Breite)
  BH = _Height(bild)
  BW = _Width(bild)

  Screen _NewImage(BW + 20, BH + 20, 32)
  
  _PutImage (10, 10), bild
End Sub


Attached Files
.7z   Bildanzeigen.7z (Size: 392.99 KB / Downloads: 87)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Hardware images questions Dav 5 462 12-04-2025, 04:18 PM
Last Post: Pete
  loadimage show pcx error macalwen 12 3,257 06-27-2024, 09:05 PM
Last Post: grymmjack
  $RESIZE questions TerryRitchie 8 2,015 06-07-2024, 03:38 PM
Last Post: TerryRitchie
  A couple questions about the dialogs.... Dav 20 4,265 10-14-2023, 04:00 PM
Last Post: TerryRitchie
  API Questions TerryRitchie 24 4,715 08-20-2023, 11:10 PM
Last Post: SpriggsySpriggs

Forum Jump:


Users browsing this thread: 1 Guest(s)