Author Topic: How to show an Image  (Read 3778 times)

LinesOfCodes

  • Newbie
  • *
  • Posts: 10
  • ?
    • S Universal Group - website
How to show an Image
« on: October 01, 2020, 12:34:18 PM »
Hello, I want to know how to show an Image in my program.
But I don't know I should use Sprite or Canvas and I didn't know what script I have to use?
I already looked in Script reference but I'm still don't know what script I have to use to show an Image.
Please help me!
I will ask the thing I doesn't know.

Malkom

  • Administrator
  • Newbie
  • *****
  • Posts: 463
  • Here to help you
Re: How to show an Image
« Reply #1 on: October 01, 2020, 06:42:51 PM »
Hello, I want to know how to show an Image in my program.
But I don't know I should use Sprite or Canvas and I didn't know what script I have to use?
I already looked in Script reference but I'm still don't know what script I have to use to show an Image.
Please help me!
Personally I would use the Canvas over the Sprite because in most situations the canvas is more flexible and has more events.
Sprites worked best in HN 3.x but in HN 4.x there were some issues, especially with sprite movement on OS X.
By the way, HN5, will have fully working canvases before its sprite engine is finished.


CanvasImages

To load an image into a canvas from the project folder just use the CanvasLoad(canvas,filename,scaleflag) as below.

Setting the scaleflag to 1 will cause the canvas to fit the whole image into the canvas.  Otherwise it will be displayed at pixel to pixel scale so larger images will be hidden off canvas.

Code: [Select]
Local fname

Put 'Chrysanthemum.jpg' into fname
CanvasLoad(1,fname,1)

Also there is the CanvasLoadAbs(canvas,filename,scaleflag) command that expects a full file path to the image.

There is also the CanvasLoadAsk(canvas,filename,scaleflag) command that presents a dialog box so the user can locate the image file.


For more details see the Help section Files  - Graphics.




Canvas Drop Image

Its possible to drop an image onto a canvas but the canvas must have its image drop event enabled.
It can be enabled/disabled using the CanvasSetDrop(canvas,modeflag)
Modeflag 0 disables, while 1 enables.
By default canvas image drop is disabled.

Usually the CanvasSetDrop command is placed in the Card's opening event but could equally be placed in a button's script etc.

Code: [Select]
CanvasSetDrop(1,1)



Image Banks
HyperNext has a set of image banks allowing images to be stored, retrieved and loaded/saved to and from files. The images can also be used in sprite animations and copied to/from canvases. Each bank holds one image and the number of banks allowed is dicated by the memory available.

Images within the banks can be rotated and flipped. These commands are particularly useful for preparing output for the printer and for canvases.

Files used by image banks can be either local or absolute.  Usually it is best to use local files.

There are also two sets of commands for saving/loading images. One is for cross-platform use and the other for standard image formats such as jpegs, picts etc.
 
« Last Edit: October 01, 2020, 06:45:34 PM by Malkom »
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.