CImage:SetPixelType (replaces SetDatatype)


The SetPixelType method sets or changes the pixel type of image pixels.

Syntax

CImage:SetPixelType( pixel_type )

bullet.gif    wherepixel_type is a number or string code for the pixel type (see Remarks).

Remarks

The pixel_type argument is either a numeric code or a string representing the target pixel type as defined in the Pixel Types table. For example, the code 1 corresponds to pixel type string "byte". if a string is passed as the pixel_type argument, Mira tries to interpret it as a pixel_type name, rather than a number code.

If you want to retrieve the pixel type of the image, use PixelType to get the numeric code or PixelTypeStr to get the string name.

Example

The following script loads an image, changes its pixel type to "float" (32 bit real) using a pixel type code number, and then saves the image:

I = new_image()

-- Create a CImage

I:Open( sPath )

-- Open the image from file path sPath.

I:SetPixelType( 5 )

-- change pixel type to 32 bit real (code 5)

I:Save()

-- save the image

I:delete()

-- delete the CImage from memory

Alternatively, you can achieve the same result by specifying the pixel type string "float" as follows:   

I = new_image()

-- Create a CImage

I:Open( sPath )

-- Open the image from file path sPath.

I:SetPixelType( "float" )

-- change pixel type to 32 bit real (code 5)

I:Save()

-- save the image

I:delete()

-- delete the CImage from memory

Related Topics

CImage class, Pixel Types, PixelType, PixelTypeStr


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2024 Mirametrics, Inc. All Rights Reserved.