Tag Archives: Bitmap

Calculate Gray (Mono) Color From RGBA Color

Calculate Gray (Mono) Color From RGBA Color.This function calculating gray mono color.Importance coefficients of RGBA for gray color:
Msdn Importance coefficients of Rgb

public class Color
{
	public float R { get; set; }
	public float G { get; set; }
	public float B { get; set; }
	public float A { get; set; }
}

/// <summary>
/// This function return Mono(Gray Color)
/// </summary>
/// <param name="rgb">RBGA color</param>
/// <returns>Return 4 byte float data</returns>
public float GetGrayColor(Color rgb)
{
     return (0.299f * rgb.R + 0.587f * rgb.G + 0.114f * rgb.B);
}

Max SDK Save (Write) Image (jpg,png,dds etc.) File with C#

Max SDK Save (Write) Image (jpg,png,dds etc.) File with C#

This function writing Image File.Max SDK.Autodesk.Max.dll must be added to references.

/// <summary>
/// This function writing bitmap File
/// </summary>
/// <param name="bitmap">Bitmap properties</param>
/// <param name="global">Your Global</param>
/// <param name="outputPath">File writing location</param>
public void SaveBitmap(IBitmap bitmap,IGlobal global,string outputPath)
{
	IBitmapInfo bitmapInfo = global.BitmapInfo.Create();
	bitmapInfo.SetName(outputPath);
	
	//Image file format can set using this function
	/*bitmapInfo.SetType(17);
	bitmapInfo.SetDevice("DDS Image File"); */
	
	bitmap.OpenOutput(bitmapInfo);
	bitmap.Write(bitmapInfo, 0);
	bitmap.Close(bitmapInfo, 0);
	global.TheManager.DelBitmap(bitmap);
}

Max SDK Load Bitmap(jpg,png,dds etc.) with .NET(C#)

Max SDK Load Images(jpg,png,dds etc.) with .NET(C#)

This Function is loading textures and showing image height.

/// <summary>
/// This Function is loading textures.
/// </summary>
/// <param name="path">File Location</param>
/// <param name="global">Your IGlobal param.</param>
public void LoadBitmap(IGlobal global,string path)
{
	IBitmap bitmap = global.TheManager.NewBitmap;
	IBitmapInfo bitmapInfo = global.BitmapInfo.Create();
	bitmapInfo.SetName(path);
	global.TheManager.LoadInto(bitmapInfo, bitmap, false);

	MessageBox.Show("Height of image:" + bitmap.Height.ToString());
}