JScript RasterImage

Log-in or register.

JScript RasterImage

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.

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)

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);

Recent comments

user icon PAEz contributing user on November 7th 2013

You know what would be awesome, if GetPixel could take float for x and y and bilinear interpolate....just so I dont have to add it to my scripts ;-) Would help speed them up a little.

user icon Vlasta site administrator on November 7th 2013

That is an interesting idea, but maybe it would be better if it were a separate method.

Also, this is a very old interface, it has been here since the beginning of scripting in RW tools many years ago and there is some outdated stuff, for example the Z and W coordinates, which are not supported anymore. Perhaps a new interface (RasterImage2 or something better) would be even better. I'll put a proposal on the forum.

user icon Anonymous
Vista & Win 7 icons
Select background