JScript RasterImage
From RealWorld Wiki
RealWorld scripting reference
RasterImage is an interface wrapper accessible as a property of the Document object and can be used to access raster images at pixel level and to change the canvas size of an image.
[edit] Methods and properties
- uint GetPixelColor(uint posX, uint posY, uint posZ, uint posW) - returns color of a pixel at the given coordinates in RGB format (8 bits per channel).
- uint GetPixelAlpha(uint posX, uint posY, uint posZ, uint posW)
- uint GetPixelRed(uint posX, uint posY, uint posZ, uint posW)
- uint GetPixelGreen(uint posX, uint posY, uint posZ, uint posW)
- uint GetPixelBlue(uint posX, uint posY, uint posZ, uint posW) - retrieve only a single color channel or alpha value of the pixel at given coordinates.
- uint GetPixel(uint posX, uint posY, uint posZ, uint posW) - return the color channels and alpha of a pixel as a packed ARGB value.
- void SetPixelColor(uint posX, uint posY, uint posZ, uint posW, uint pixelColor)
- void SetPixelAlpha(uint posX, uint posY, uint posZ, uint posW, uint pixelAlpha)
- void SetPixelRed(uint posX, uint posY, uint posZ, uint posW, uint pixelRed)
- void SetPixelGreen(uint posX, uint posY, uint posZ, uint posW, uint pixelGreen)
- void SetPixelBlue(uint posX, uint posY, uint posZ, uint posW, uint pixelBlue)
- void SetPixel(uint posX, uint posY, uint posZ, uint posW, uint packedPixel)
- uint sizeX (get) - width of the image.
- uint sizeY (get) - height of the image.
- uint sizeZ (get) - depth of the image.
- uint sizeW (get) - size of the 4-th dimension of the image.
- void Resize(uint sizeX, uint sizeY, uint sizeZ, uint sizeW, int offsetX, int offsetY, int offsetZ, int offsetW)
- void FillResize(uint sizeX, uint sizeY, uint sizeZ, uint sizeW, int offsetX, int offsetY, int offsetZ, int offsetW, uint fillColor)
- float GetPixelH(uint posX, uint posY, uint posZ, uint posW)
- float GetPixelL(uint posX, uint posY, uint posZ, uint posW)
- float GetPixelS(uint posX, uint posY, uint posZ, uint posW)
- void SetPixelHLS(uint posX, uint posY, uint posZ, uint posW, float pixelH, float pixelL, float pixelS)
- bool HasAlpha()
- void SetAlpha(bool alpha)
- uint resolutionXNum (get)
- uint resolutionXDenom (get)
- uint resolutionYNum (get)
- uint resolutionYDenom (get)
- uint resolutionZNum (get)
- uint resolutionZDenom (get)
- uint resolutionWNum (get)
- uint resolutionWDenom (get)
- void SetResolution(uint resXNum, uint resXDenom, uint resYNum, uint resYDenom, uint resZNum, uint resZDenom, uint resWNum, uint resWDenom)
- uint previewScale (get)
[edit] Example
// cache often used properties in local variables
var image = Document.RasterImage;
var sizeX = image.sizeX;
var sizeY = image.sizeY;
// iterate through pixels and erase those with even sum of X and Y coordinates
for (x=0; x<sizeX; x++)
for (y=0; y<sizeY; y++)
if ((x+y)&1)
image.SetPixel(x, y, 0, 0, 0);