LoadNewImage
ImageIndex = LoadNewImage(Filename$, [Format =1])
 
Parameters:

    Filename$ = The Filename and path of the Image you wish to load
    [Format =1] = Format of loaded image, format defaults to Video (1), use 2 for FX and 8 for AFX
Returns:

    ImageIndex = The Image Index where this picture data was load to
 

     LoadNewImage reads an Image file from disc into your computers memory. Unlike LoadImage all you need to provide LoadNewImage is the path and filename of the Image, It will return the ImageIndex for you.



Image Types:


      PlayBASIC has various types of Image types, each one suited for different uses.

           1 = Video - Image is created in Video Memory
           2 = FX - System Memory Image
           8 = AFX - System Memory Image With Alpha Channel


      To learn more about images, we recommend you read the CreateImage and Images tutorials




FACTS:


      * LoadNewImage supports various popular image formats including BMP, TGA JPEG, PNG as well PlayBASIC very own Image Format called PBI

      * LoadNewImage does not change PlayBASIC current graphics output. So if you want to redirect drawing operations to an Image, you'll have to do this manually with RenderToImage.

      * Note: We highly recommended you read the Images tutorials also!

      * LoadNewImage (and variants) can now load PBI / BMP / TGA + PNG's files directly from memory. To do so, the address of the data is given as a String in place of the filename with an & symbol prefix. eg Index=LoadNewImage( "&"+Str$(Ptr)) - They can also be automatically loaded from the resource buffer. See #AddResource and Example #2 bellow





Mini Tutorial #1:


      This examples loads an Image from disc into a free Image index, displays it to the screen at 100x,100y then waits for the user to press a key before ending


  
; Load an Image into Image slot #1
  MyImage=LoadNewImage("ThePictureYouWishToLoad.bmp")
  
; Draw the Loaded Image to the screen
  DrawImage MyImage,100,100,0
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  



Sample Output







Mini Tutorial #2: LoadNewImage From Memory


      This example shows how we can use the LoadNewImage command to load from memory and not just disc. To demonstrate this, we first need to store an image in memory to load. The image load from memory routines expect a pointer to a the size of the image (stored as an integer) followed by the the image data. So an images that's 10000 bytes long, requires an integer header making it 10004 bytes in memory. In order to load it, we would give the loader the address of the size integer and as long as the image data is after in, it should load ok.

      Loading images from memory is normally used for data security purposes, which is where a programmer would store first pre-process their media files and store them in an encrypted/scrambled state. The program/game then loads the encrypted media files into memory, decrypts/descrambles the data in memory and then loads that media from memory directly. This saves ever having to store the decrypted media data in a temporary state on disc.


  
  
  // compute the location of a known image in
  // the help file folder
  Path$=ProgramDir$()+"Help\Commands/Media/"
  file$=path$+"ship.bmp"
  
  
  // Check if this file exists
  If FileExist(file$)
     
     // Get the size of this file in bytes
     Size=FileSize(File$)
     
     
     // Create a memory bank the size of the
     // file plus and extra 4 bytes for the length
     // header
     ThisBank= NewBank(Size + 4)
     
     // Get a pointer to the bank
     Ptr=GetBankPtr(ThisBank)
     
     
     // store the size of this image before the
     // image data
     PokeInt Ptr,Size
     
     
     // Open the file and read it into a bank
     fh=ReadNewFile(file$)
     If fh
        // Read the file into our memory bank
        ReadMemory fh,Ptr+4,Size
        CloseFile fh
        
        
        // Load IMage from Memory
        ThisImage=LoadNewImage("&"+Str$(ptr))
        
        
        // Display the image
        DrawImage ThisImage,100,100,false
        
        
     EndIf
     
  EndIf
  
  Sync
  WaitKey
  
  





 
Example Source: Download This Example
; Init a variable FileName$ to store the
; location and name of the image we wish to load
  FileName$="..\../Media/bubble_64x64.bmp"
  
; Load this file into PBs Image Bank and return a handle to it
  MyImage=LoadNewImage(Filename$)
  
; draw this image to the screen
  DrawImage MyImage,350,200,false
  
; Display the screen and wait for a key press
  Sync
  WaitKey
  
  
  
  
 
Related Info: CreateImage | DeleteImage | DrawImage | LoadAFxImage | LoadFxImage | LoadImage | LoadNewAFxImage | LoadNewFXImage | NewImage | RenderToImage | SaveBitmap :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com