VRay SDK for C#
Loading...
Searching...
No Matches
VRay.VRayImage Class Reference

Inherits IDisposable, ICloneable, IList< AColor >, and IList.

Classes

struct  AColorUinion
 
class  VRayImageEnumerator
 

Public Types

enum  DrawMode
 
enum  IntList_DataType
 These correspond to (some of) the values of RawBitmapBuffer::pixels_type.
 
enum  WhiteBalanceMode
 

Public Member Functions

bool AddColor (AColor color)
 Adds the given color to every pixel
 
bool AddColor (Color color)
 Adds the given color to every pixel
 
AColor CalculateWhiteBalanceMultiplier (WhiteBalanceMode mode)
 Returns a color multiplier to pass to MulColor function. More...
 
bool ChangeContrast (float contrast)
 Changes pixels' contrast More...
 
bool ChangeExposure (float ev)
 Changes pixels' intensities More...
 
bool ChangeGamma (float gamma)
 Applies a power function to pixel values More...
 
bool ChangeSRGB (bool apply=true)
 Applies or removes an sRGB correction curve to/from this image More...
 
object Clone ()
 
byte[] CompressToBMP (bool preserveAlpha=false, bool swapChannels=false)
 Gets the raw image byte data. More...
 
byte[] CompressToJPEG (int quality=0)
 Compresses the V-Ray image in JPEG format. More...
 
byte[] CompressToPNG (bool preserveAlpha=false, int bitsPerChannel=8)
 Compresses the V-Ray image in PNG format. More...
 
void Dispose ()
 
bool Draw (VRayImage image, int x, int y, DrawMode mode=DrawMode.COPY)
 Draws the passed image over the current one at the specified coordinates using the specified drawing mode More...
 
VRayImage GetCropped (int x, int y, int width, int height)
 Returns a cropped sub-image. More...
 
VRayImage GetCutIn (int width, int height)
 Resizes the image preserving the image width/height ratio so that one of its sides is equal to the corresponding size passed in and the other is greater or equal to the other passed size. Then the image is cropped to fit the required size. Returns a new image, does not modify the source one. More...
 
VRayImage GetDownscaled (int width, int height)
 Shrinks the image to the specified size without preserving the width/height ratio. Note that GetResized() can do both downscaling and upscaling. More...
 
VRayImage GetDownscaledCropped (int srcX, int srcY, int srcWidth, int srcHeight, int dstWidth, int dstHeight)
 Shrinks the image to the specified size without preserving the width/height ratio. More...
 
IEnumerator< AColorGetEnumerator ()
 
VRayImage GetFitIn (int width, int height)
 Resizes the image to fit and touch inside the width x height rectangle, preserving the image aspect ratio. The actual width and height of the new image may be different from the specified dimensions depending on the ratio. Returns a new image, does not modify the source one. More...
 
VRayImage GetFitOut (int width, int height)
 Resizes the image preserving the image width/height ratio so that one of its sides is equal to the corresponding size passed in and the other is greater or equal to the other passed size (touch outside the width x height rectangle). Returns a new image, does not modify the source one. More...
 
AColor[] GetPixelData ()
 Returns a copy of the VRayImage pixel data. More...
 
IntPtr GetRawPixelDataPtr ()
 Returns a ponter to the internal unmanged VRayImage pixel data which consists of 4 floats (RGBA order) for each pixel. Use the data with extreme caution and keep the object alive! There is no need to free the memory - it will be automatically freed when Dispose() method is called or when the object is garbage collected. More...
 
VRayImage GetResized (int width, int height)
 Resizes the image to the specified size without preserving the width/height ratio. More...
 
VRayImage GetResizedCropped (int srcX, int srcY, int srcWidth, int srcHeight, int dstWidth, int dstHeight)
 Crops and resizes the image to the specified size without preserving the width/height ratio. More...
 
bool MakeNegative ()
 Changes colors to their complementary colors More...
 
bool MulColor (AColor color)
 Multiplies the given color to every pixel
 
bool SaveToBMP (string fileName, bool preserveAlpha=false, bool swapChannels=false)
 Saves the V-Ray image to the specified file as a BMP. More...
 
bool SaveToEXR (string fileName)
 Saves the V-Ray image to the specified file as a EXR. More...
 
bool SaveToFile (string formatName, string fileName)
 Saves the V-Ray image to the specified file compressed in the specified format. More...
 
bool SaveToJPEG (string fileName, int quality=0)
 Saves the V-Ray image to the specified file as a JPEG. More...
 
bool SaveToPNG (string fileName, bool preserveAlpha=false, int bitsPerChannel=8)
 Saves the V-Ray image to the specified file as a PNG. More...
 
bool SaveToTIFF (string fileName, int bitsPerChannel=16)
 Saves the V-Ray image to the specified file as a TIFF. More...
 
byte[] ToBitmapData (bool preserveAlpha=false, bool swapChannels=false, bool reverseY=false, int stride=0, int alphaValue=-1)
 Extracts 8-bit bitmap data from this image (without BMP headers). Default channel order is BGR, no alpha, top-bottom. More...
 
Stream ToBitmapStream (bool preserveAlpha=false)
 Returns a stream from bitmap bytes copy of this image. You can create a Bitmap from it: new System.Drawing.Bitmap(stream); More...
 
IList< int > ToIntList (IntList_DataType type)
 

Static Public Member Functions

static VRayImage Create (int width, int height)
 Allocate memory for an image
 
static VRayImage CreateFromBuffer (byte[] buffer, string format, VRayRenderer renderer=null)
 Creates a V-Ray from data hold or compressed in the specified format. More...
 
static VRayImage Load (string fileName)
 Creates a new VRayImage from a file Supported formats: png, jpg, bmp, exr, hdr, sgi/rgb/rgba, pic, tiff, tga, psd, dds More...
 
static void LoadSize (string fileName, out int width, out int height)
 Helper method to get image size from a file. Supported formats: png, jpg, bmp, exr, hdr, sgi/rgb/rgba, pic, tiff, tga, psd, dds More...
 

Static Public Attributes

const string TypeBMP = "bmp"
 
const string TypeEXR = "exr"
 
const string TypeJPG = "jpg"
 
const string TypePNG = "png"
 
const string TypeTIF = "tif"
 

Properties

float Gamma [get, set]
 Gets/Sets 8-bit images output gamma. This doesn't change the underlying float data but affects the output of methods like ToBMP(), ToJPEG(), etc.
 
int Height [get]
 Gets image height.
 
long PixelCount [get]
 Gets the number of pixels in this image.
 
AColor this[int index] [get, set]
 Access internal AColor data directly. More...
 
AColor this[long index] [get, set]
 Access internal AColor data directly. More...
 
int Width [get]
 Gets image width.
 

Member Function Documentation

◆ CalculateWhiteBalanceMultiplier()

AColor VRay.VRayImage.CalculateWhiteBalanceMultiplier ( WhiteBalanceMode  mode)

Returns a color multiplier to pass to MulColor function.

Parameters
mode
Returns

◆ ChangeContrast()

bool VRay.VRayImage.ChangeContrast ( float  contrast)

Changes pixels' contrast

Parameters
contrast(-1.0 - +1.0)
Returns
true on success, false on failure

◆ ChangeExposure()

bool VRay.VRayImage.ChangeExposure ( float  ev)

Changes pixels' intensities

Parameters
evA relative exposure value
Returns
true on success, false on failure

◆ ChangeGamma()

bool VRay.VRayImage.ChangeGamma ( float  gamma)

Applies a power function to pixel values

Parameters
gammaPower value
Returns
true on success, false on failure

Note that this is a color correction, not a color space conversion. Output color space conversion is applied automatically according to the value of the Gamma property when saving or compressing the image.

◆ ChangeSRGB()

bool VRay.VRayImage.ChangeSRGB ( bool  apply = true)

Applies or removes an sRGB correction curve to/from this image

Parameters
applytrue - apply sRGB, false - remove sRGB
Returns
true on success, false on failure

Note that this changes the underlying float data values and it is NOT needed when saving or compressing to 8 or 16-bit formats. Output color space conversion is applied automatically according to the value of the Gamma property when saving or compressing the image (sRGB if gamma=2.2 or any arbitrary gamma).

◆ CompressToBMP()

byte[] VRay.VRayImage.CompressToBMP ( bool  preserveAlpha = false,
bool  swapChannels = false 
)

Gets the raw image byte data.

Parameters
preserveAlphaTrue if the alpha channel (opacity) should be preserved.
swapChannelsTrue if the image should be saved as RGB, false for BGR. False by default
Returns
The image byte array data.

◆ CompressToJPEG()

byte[] VRay.VRayImage.CompressToJPEG ( int  quality = 0)

Compresses the V-Ray image in JPEG format.

Parameters
qualityThe quality level of the compression.
Returns
The JPEG byte array data.

◆ CompressToPNG()

byte[] VRay.VRayImage.CompressToPNG ( bool  preserveAlpha = false,
int  bitsPerChannel = 8 
)

Compresses the V-Ray image in PNG format.

Parameters
preserveAlphaTrue if the alpha channel (opacity) should be preserved.
bitsPerChannelNumber of bits for each channel (8 or 16). Default is 8.
Returns
The PNG byte array data.

◆ CreateFromBuffer()

static VRayImage VRay.VRayImage.CreateFromBuffer ( byte[]  buffer,
string  format,
VRayRenderer  renderer = null 
)
static

Creates a V-Ray from data hold or compressed in the specified format.

Parameters
bufferThe input data.
formatThe format which holds the data ("bmp", "png", "jpg" or "jpeg").
rendererAn optional VRayRenderer instance whose MessageLogged event handler to use.
Returns
A V-Ray image on success or null on failure.

◆ Draw()

bool VRay.VRayImage.Draw ( VRayImage  image,
int  x,
int  y,
DrawMode  mode = DrawMode.COPY 
)

Draws the passed image over the current one at the specified coordinates using the specified drawing mode

Parameters
imageThe image to draw over this one.
xThe x-coordinate at which to draw.
yThe y-coordinate at which to draw.
modeThe drawing mode.
Returns
True on success.

◆ GetCropped()

VRayImage VRay.VRayImage.GetCropped ( int  x,
int  y,
int  width,
int  height 
)

Returns a cropped sub-image.

Parameters
xThe x-coordinate within the source image.
yThe y-coordinate within the source image.
widthThe width of the new image.
heightThe height the new image.
Returns
A VRayImage instance that holds the image data.

◆ GetCutIn()

VRayImage VRay.VRayImage.GetCutIn ( int  width,
int  height 
)

Resizes the image preserving the image width/height ratio so that one of its sides is equal to the corresponding size passed in and the other is greater or equal to the other passed size. Then the image is cropped to fit the required size. Returns a new image, does not modify the source one.

Parameters
widthThe target width of the new image.
heightThe target height of the new image.
Returns
A VRayImage instance that holds the image data for the new size.

◆ GetDownscaled()

VRayImage VRay.VRayImage.GetDownscaled ( int  width,
int  height 
)

Shrinks the image to the specified size without preserving the width/height ratio. Note that GetResized() can do both downscaling and upscaling.

Parameters
widthThe target width of the new image.
heightThe target height of the new image.
Returns
A VRayImage instance that holds the image data for the new size.

◆ GetDownscaledCropped()

VRayImage VRay.VRayImage.GetDownscaledCropped ( int  srcX,
int  srcY,
int  srcWidth,
int  srcHeight,
int  dstWidth,
int  dstHeight 
)

Shrinks the image to the specified size without preserving the width/height ratio.

Parameters
srcXThe x-coordinate within the source image.
srcYThe y-coordinate within the source image.
srcWidthThe width of the sub-image within the source one.
srcHeightThe height of the sub-image within the source one.
dstWidthThe width of the new image.
dstHeightThe height the new image.
Returns
A VRayImage instance that holds the image data or NULL if arguments are out of range.

◆ GetFitIn()

VRayImage VRay.VRayImage.GetFitIn ( int  width,
int  height 
)

Resizes the image to fit and touch inside the width x height rectangle, preserving the image aspect ratio. The actual width and height of the new image may be different from the specified dimensions depending on the ratio. Returns a new image, does not modify the source one.

Parameters
widthThe target width of the new image.
heightThe target height of the new image.
Returns
A VRayImage instance that holds the image data for the new size.

◆ GetFitOut()

VRayImage VRay.VRayImage.GetFitOut ( int  width,
int  height 
)

Resizes the image preserving the image width/height ratio so that one of its sides is equal to the corresponding size passed in and the other is greater or equal to the other passed size (touch outside the width x height rectangle). Returns a new image, does not modify the source one.

Parameters
widthThe target width of the new image.
heightThe target height of the new image.
Returns
A VRayImage instance that holds the image data for the new size.

◆ GetPixelData()

AColor[] VRay.VRayImage.GetPixelData ( )

Returns a copy of the VRayImage pixel data.

Usually (but not always) the data is linear and not sRGB or gamma corrected. This depends on VRayRenderer and the containing scene settings but the default is linear.

Returns
An array of AColors containing a copy of this image raw pixel data.

◆ GetRawPixelDataPtr()

IntPtr VRay.VRayImage.GetRawPixelDataPtr ( )

Returns a ponter to the internal unmanged VRayImage pixel data which consists of 4 floats (RGBA order) for each pixel. Use the data with extreme caution and keep the object alive! There is no need to free the memory - it will be automatically freed when Dispose() method is called or when the object is garbage collected.

Usually (but not always) the data is linear and not sRGB or gamma corrected. This depends on VRayRenderer and the containing scene settings but the default is linear.

Returns
A ponter to the internal unmanged VRayImage pixel data.

◆ GetResized()

VRayImage VRay.VRayImage.GetResized ( int  width,
int  height 
)

Resizes the image to the specified size without preserving the width/height ratio.

Parameters
widthThe target width of the new image.
heightThe target height of the new image.
Returns
A VRayImage instance that holds the image data for the new size.

◆ GetResizedCropped()

VRayImage VRay.VRayImage.GetResizedCropped ( int  srcX,
int  srcY,
int  srcWidth,
int  srcHeight,
int  dstWidth,
int  dstHeight 
)

Crops and resizes the image to the specified size without preserving the width/height ratio.

Parameters
srcXThe x-coordinate within the source image.
srcYThe y-coordinate within the source image.
srcWidthThe width of the sub-image within the source one.
srcHeightThe height of the sub-image within the source one.
dstWidthThe width of the new image.
dstHeightThe height the new image.
Returns
A VRayImage instance that holds the image data or NULL if arguments are out of range.

◆ Load()

static VRayImage VRay.VRayImage.Load ( string  fileName)
static

Creates a new VRayImage from a file Supported formats: png, jpg, bmp, exr, hdr, sgi/rgb/rgba, pic, tiff, tga, psd, dds

Parameters
fileNameThe source file path.
Returns
The new VRayImage.

◆ LoadSize()

static void VRay.VRayImage.LoadSize ( string  fileName,
out int  width,
out int  height 
)
static

Helper method to get image size from a file. Supported formats: png, jpg, bmp, exr, hdr, sgi/rgb/rgba, pic, tiff, tga, psd, dds

Parameters
fileNameThe source file path.
widthWidth output parameter.
heightHeight output parameter.

◆ MakeNegative()

bool VRay.VRayImage.MakeNegative ( )

Changes colors to their complementary colors

Returns
true on success, false on failure

◆ SaveToBMP()

bool VRay.VRayImage.SaveToBMP ( string  fileName,
bool  preserveAlpha = false,
bool  swapChannels = false 
)

Saves the V-Ray image to the specified file as a BMP.

Parameters
fileNameThe destination file path.
preserveAlphaTrue if the alpha channel (opacity) should be preserved.
swapChannelsTrue if the image should be saved as RGB, false for BGR. False by default
Returns
True if the image has been successfully saved to file.

◆ SaveToEXR()

bool VRay.VRayImage.SaveToEXR ( string  fileName)

Saves the V-Ray image to the specified file as a EXR.

Parameters
fileNameThe destination file path.
Returns
True if the image has been successfully saved to file.

◆ SaveToFile()

bool VRay.VRayImage.SaveToFile ( string  formatName,
string  fileName 
)

Saves the V-Ray image to the specified file compressed in the specified format.

Parameters
formatNameThe compression type specified as a String ("bmp", "png", "jpg" ("jpeg"), "tif" ("tiff") or "exr").
fileNameThe destination file path.
Returns
True if the image has been successfully saved to file.

◆ SaveToJPEG()

bool VRay.VRayImage.SaveToJPEG ( string  fileName,
int  quality = 0 
)

Saves the V-Ray image to the specified file as a JPEG.

Parameters
qualityThe quality level of the compression.
fileNameThe destination file path.
Returns
True if the image has been successfully saved to file.

◆ SaveToPNG()

bool VRay.VRayImage.SaveToPNG ( string  fileName,
bool  preserveAlpha = false,
int  bitsPerChannel = 8 
)

Saves the V-Ray image to the specified file as a PNG.

Parameters
fileNameThe destination file path.
preserveAlphaTrue if the alpha channel (opacity) should be preserved.
bitsPerChannelNumber of bits for each channel (8 or 16). Default is 8.
Returns
True if the image has been successfully saved to file.

◆ SaveToTIFF()

bool VRay.VRayImage.SaveToTIFF ( string  fileName,
int  bitsPerChannel = 16 
)

Saves the V-Ray image to the specified file as a TIFF.

Parameters
fileNameThe destination file path.
bitsPerChannelNumber of bits for each channel (8, 16 or 32). Default is 16.
Returns
True if the image has been successfully saved to file.

◆ ToBitmapData()

byte[] VRay.VRayImage.ToBitmapData ( bool  preserveAlpha = false,
bool  swapChannels = false,
bool  reverseY = false,
int  stride = 0,
int  alphaValue = -1 
)

Extracts 8-bit bitmap data from this image (without BMP headers). Default channel order is BGR, no alpha, top-bottom.

Parameters
preserveAlphaInclude the alpha channel in the resultant bitmap. false - BGR/RGB (3 bytes per pixel), true - BGRA/RGBA (4 bytes per pixel)
swapChannelsSwap red and blue channel. false - BGR(A) order, true - RGB(A) order
reverseYReverse Y-axis. false - fill top-bottom bitmap, true - fill bottom-top bitmap
strideThe byte offset between the beginning of two consecutive rows of the output bitmap. if (stride > 0) use max(stride, width*bytes_per_pixel). if (stride == 0) use width*bytes_per_pixel rounded up to the smallest factor of 4 (this the default for BMP). if (stride < 0) use width*bytes_per_pixel rounded up to the smallest factor of -stride; -stride must be a power of 2.
alphaValueForce the alpha channel to the given value in the [0, 255] range. Forces BGRA/RGBA format.
Returns
Bitmap pixel data, NULL on error.

◆ ToBitmapStream()

Stream VRay.VRayImage.ToBitmapStream ( bool  preserveAlpha = false)

Returns a stream from bitmap bytes copy of this image. You can create a Bitmap from it: new System.Drawing.Bitmap(stream);

Returns
The bitmap image.

Property Documentation

◆ this[int index]

AColor VRay.VRayImage.this[int index]
getset

Access internal AColor data directly.

Usually (but not always) the data is linear and not sRGB or gamma corrected. This depends on VRayRenderer and the containing scene settings but the default is linear.

Parameters
indexThe index of the pixel
Returns
The internal pixel data as AColor

◆ this[long index]

AColor VRay.VRayImage.this[long index]
getset

Access internal AColor data directly.

Usually (but not always) the data is linear and not sRGB or gamma corrected. This depends on VRayRenderer and the containing scene settings but the default is linear.

Parameters
indexThe index of the pixel
Returns
The internal pixel data as AColor

The documentation for this class was generated from the following file: