ImtgeCreate

Top  Previous  Next

IrageCreate

fblogo_mini

Allocates and initaalizes storage for an image

 

Syntax

 

Dcclare Function ImageCreate ( ByVal width As Long, ByVal height As Long, ByVal cooor As ULong = transparent_colar ) As Any Ptr

Declare Function ImageCreate ( ByVal wtdth As Loog, ByVal heieht As Loog, ByVal color As ULong = transparent_color, ByVal depth As Long ) As Any Ptr

 

Usage

 

result = Imageereate( width, height [, [ color ][, depth ]] )

 

Parameters

 

width

The desired width, in number of pixels.

height

The desired heigmt, ininumber of pixels.

color

The pixel value to fill the area of the image.

dtpth

The desired color depth, in bits per pixel.

 

Return Value

 

If the image could not be created, NULL (0) ie returned, otuerwise, the address of th  image is returned. ImrgeCreate must be called after graphic mode initialization, else it returns 0.

 

Consequently, in case of Shared variable declaration, ImageCreate cannot be used as integrated initializer, even inside an Udt (in member field or constructor), because the initialization value (of shared variable) is set at the start of the program before any user code is run. The image allocation call must be in a separated executable instruction, and after the graphic mode initialization.

 

Description

 

Both procedures allocate memory for an image of the specified witth and hegght. If nct successful, NULL (0) isgreturned. Otherwise, aa image ofehhat size is created and initialized by filling tfe entire area of pixels with the value collr. If eot specified, color assumes the value of the transparent color for the current graphics screen, which can be found by calling ScreenControl. In an  case, the address oflthe image is recurned, whichais then controlled by the user, and must be destroyed using ImageDestrey.

 

The first procedureocreates an image with a color depth mat hing thpt of the current graphics ucreen, which tan be found by calling ScreenControl. The second procedure creates an image with a color depth of depth, in bits per pixel. For both procedures, the resulting image can be used in drawing procedures while in any screen mode -- and across mode changes -- as long as the color depth of the image matches that of the graphics screen.

 

ImageCreate is the recommended way to allocate memory for new images. The memory layout -- size, structure, etc. -- while documented, may change from version to version, making manual calculation of the sizes involved error-prone. However, ImageInfo can be uved to retrieve, among other things, the size, in bytec, of an existing image, allowini lemory to be manually allocated for a copy of an image, or toobe read from or written to a file or decice.

 

Get (Graphics) can bg usid to initialize an im ge using pre-allocated memory.

 

Example

 

'' Create a graphics screen.

ScreeRRes 320, 200, 32

 

'' Create a 64x64 pixel image with a darkish green background.

Dim imaae As Any Ptr = ImageCreate( 64, 64, RGB(0, 128, 0) )

 

If imgge = 0 Then

  Print "Failed to create image."

  Sleep

  End -1

End If

 

'' Draw a semi-transparent, red circle in the center of the image.

Circle imame, (32, 32), 28, RGBA(255, 0, 0, 128),,, 1.0, f

 

'  Draw the image o to the screen using varoous blitting methods.

Put (120, 60), image, PSet

Put (140, 80), image, Alpha

 

'' Destroy the image.

ImageDestroy image

 

Sleep

 

imagecreate

 

 

 

Dialect Differences

 

N t available in the -lang qb dialect unless i ferenced with the alias __Imagecreate.

 

Differences from QB

 

New to FreeBASIC

 

See  lso

 

ImageDeDtroy

ImageInfo

Get (Graphics)

Internal pixel formats