Class WmfSelectObject
Namespace: Aspose.Imaging.FileFormats.Wmf.Objects
Assembly: Aspose.Imaging.dll (25.7.0)
The select object.
public class WmfSelectObject : WmfObject
{
private int _penIndex;
private int _brushIndex;
public WmfSelectObject(int penIndex, int brushIndex)
{
_penIndex = penIndex;
_brushIndex = brushIndex;
}
protected override void DrawCore(Graphics graphics)
{
if (_penIndex >= 0 && _penIndex < Graphics.FromHdc(Hdc).GetHgcs().Length)
{
using (var pen = new Pen(Graphics.FromHdc(Hdc).GetHgcs()[_penIndex]))
graphics.DrawPath(pen, Path);
}
if (_brushIndex >= 0 && _brushIndex < Graphics.FromHdc(Hdc).GetHgcs().Length)
{
using (var brush = new SolidBrush(Graphics.FromHdc(Hdc).GetHgcs()[_brushIndex]))
graphics.FillPath(brush, Path);
}
}
}
Inheritance
object ← MetaObject ← WmfObject ← WmfSelectObject
Inherited Members
object.GetType() , object.MemberwiseClone() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Constructors
WmfSelectObject(WmfGraphicObject)
Initializes a new instance of the Aspose.Imaging.FileFormats.Wmf.Objects.WmfSelectObject class.
public WmfSelectObject(WmfGraphicObject wmfObject)
{
}
Parameters
wmfObject
WmfGraphicObject
The WMF object.
WmfSelectObject()
Initializes a new instance of the Aspose.Imaging.FileFormats.Wmf.Objects.WmfSelectObject class.
public WmfSelectObject()
{
}
Examples
The following example shows how set the background color for WMF. Actually it draws a rectangle of the background color before drawing all other objects.
string dir = "c:\\aspose.imaging\\issues\\net\\3280\\";
string inputFilePath = dir + "image2.wmf";
string outputFilePath = dir + "ChangeBackground_" + "image2.wmf";
using (Aspose.Imaging.FileFormats.Emf.MetaImage image = (Aspose.Imaging.FileFormats.Emf.MetaImage)Aspose.Imaging.Image.Load(inputFilePath))
{
AddBackgroundRectangleWmf((Aspose.Imaging.FileFormats.Wmf.WmfImage)image, Aspose.Imaging.Color.Blue);
image.Save(outputFilePath);
}
public static void AddBackgroundRectangleWmf(Aspose.Imaging.FileFormats.Wmf.WmfImage image, Aspose.Imaging.Color color)
{
image.CacheData();
if (image.Records.Count < 1)
{
return;
}
Aspose.Imaging.FileFormats.Wmf.Objects.WmfRectangle rectangle = new Aspose.Imaging.FileFormats.Wmf.Objects.WmfRectangle();
rectangle.Rectangle = image.FrameBounds;
Aspose.Imaging.FileFormats.Wmf.Objects.WmfCreateBrushInDirect brush = new Aspose.Imaging.FileFormats.Wmf.Objects.WmfCreateBrushInDirect();
brush.LogBrush = new Aspose.Imaging.FileFormats.Emf.Emf.Objects.EmfLogBrushEx();
brush.LogBrush.Argb32ColorRef = color.ToArgb();
Aspose.Imaging.FileFormats.Wmf.Objects.WmfSelectObject selectObject = new Aspose.Imaging.FileFormats.Wmf.Objects.WmfSelectObject(brush);
Aspose.Imaging.FileFormats.Wmf.Objects.WmfDeleteObject deleteObject = new Aspose.Imaging.FileFormats.Wmf.Objects.WmfDeleteObject(brush);
image.Records.Insert(0, brush);
image.Records.Insert(1, selectObject);
image.Records.Insert(2, rectangle);
image.Records.Insert(3, deleteObject);
}
Properties
ObjectIndex
Gets or sets the index of the object.
public int ObjectIndex
{
get;
set;
}