SavePBIex
SavePBIex Filename$, ImageIndex, ChunkWidth, ChunkHeight
 
Parameters:

    Filename$ = The name and path of the file you wish to save
    ImageIndex = The Index of the image you wish to save.
    ChunkWidth = The width of the compression chunk
    ChunkHeight= The height of the compression chunk
Returns: NONE
 

      The SavePBIex saves an Image in memory to disc in PlayBASIC Image Format (PBI). The SavePBIex version of the saver gives the user the ability to select the compressor chunk size. The chunk size relates to how the image is going to be broken up internally. Each chunk then passes through a colour reduction process and ultimately through various duplication scans to detect matching areas. So if you know that your image contains a lot of similar areas that are 64 * 64 pixels say, then that would a good chunk size for the saver.




FACTS:


      * The PlayBASIC Image Format is a lossless 32bit (ARGB) image format designed for use with PlayBASIC.

      * The smallest compression chunk size is 4 by 4 pixels. Generally the smaller the chunk size the slower compression pass is going to be, but it all depends upon the make up of the image. Images with very few colours tend to compress slower than bigger images with 1000's of colours. For small to medium sized images we recommend a chunk sizes of around 16*16, 32*32, 64*64 pixels. For bigger images, larger chunk sizes tend to work better in terms of speed / file size, so chunks 256*256 pixels, 512*512 pixels. In fact, you can use the images size as the chunk size if you wish. The size of output file will vary greatly though, which is why picking a size is important.


      * Read the 'SavePBI' for more general facts about PBI and check the forums for the FAQ's.





Mini Tutorial:


      This example includes the library, locates an image file that should be found in the Help files (but might not be), saves the image out to your windows temp folder, reloads it and displays it.


  
  
; include the PlayBASIC Image Format library
  #Include "PBI"
  
  
; Try and locate a image from the help files
  path$=ProgramDir$()+"\Help\Commands/Media/"
  
; Get the location of the star animation from in the help files
  Filename$=Path$+"Load-Map-Example-Small.png"
  
  
  
; check if the file exists
  If FileExist(Filename$)
     
   ; Load the image into memory using FreeImage.
     ThisImage=LoadNewImage(Filename$,2)
     
   ; draw this new image image to the screen
     DrawImage ThisImage,450,50,false
     
   ; Save this image as using a bunch of different chunk sizes
     For ChunkHeight = 8 To 64 Step 8
        For ChunkWidth = 16 To 64 Step 16
           
           
         ; Create the save name for this image
         ; the file will be saved into the windows temp folder
         ; Save this Image out to disc
           SaveName$=TempDir$()+GetFileName$(Filename$)
           
         ; dimensions
           s$="-"+Digits$(ChunkWidth,2)+"by"+Digits$(ChunkHeight,2)
           
         ; Replace the BMP extensions with .PBI
           SaveName$=Replace$(SaveName$,".PNG",s$+".PBI")
           
         ; Save the image as PBI with a variable chunk size
           SavePBIex SAveName$,ThisIMage,ChunkWidth,ChunkHeight
           
         ; check the saved file exists
           If FileExist(SaveName$)
              
            ; if it does, display the name and size
              s$ = GetFileName$(SaveName$)
              s$+= " Size="
              s$+= Str$(FileSize(SaveName$))
              s$+= " bytes"
              Print s$
              
            ; remove the old file
              DeleteFile SaveName$
              
           Else
              
              Print "Couldn't save file"
              
           EndIf
           
           Sync
           
        Next
     Next
     
     
     
  Else
     
     Print "Couldn't find file:"
     Print Filename$
     
  EndIf
  
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  
  




 
Related Info: FreeImage_SaveBMP | FreeImage_SaveJPG | LoadImage | SaveBitmap | SavePBI :
 


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