public final class DwfImage extends Image
DWF image class. Provides reading of DWF/DWFX format files, their processing and their export to other formats.
Reads an image file in DWG format, changes its contents and saves the image in PNG format.string fileName = "exampleFile"; string file = string.Format("{0}.dwf", fileName); string outFile = string.Format("{0}.png", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (DwfImage image = (DwfImage) Image.Load(inStream)) using (FileStream stream = new FileStream(outFile, FileMode.Create)) { DwfWhipDrawable[] entities = image.Pages[0].Entities; foreach(DwfWhipDrawable drawable in entities) { if(drawable is DwfWhipPolyline) { ((DwfWhipPolyline) drawable).Points[0].X = -50; ((DwfWhipPolyline) drawable).Points[0].Y = -50; break; } } image.UpdateSize(); foreach (DwfWhipDrawable drawable in entities) { if (drawable is DwfWhipText) { ((DwfWhipText)drawable).Font.Name.Value.AsciiString = "Arial"; } } ImageOptionsBase options = new PngOptions(); options.VectorRasterizationOptions = new CadRasterizationOptions { PageWidth = (float)image.Pages[0].PaperWidth, PageHeight = (float)image.Pages[0].PaperHeight, DrawType = CadDrawTypeMode.UseObjectColor, }; image.Save(stream, options); }
| Modifier and Type | Method and Description |
|---|---|
void |
addElement(int pageNumber,
DwfWhipDrawable element)
Adds graphic element to specified page.
|
void |
cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying
DataStreamSupporter.DataStreamContainer(DataStreamSupporter#getDataStreamContainer/DataStreamSupporter). |
int |
getDepth()
Gets the image depth.
|
int |
getElementCount(int pageNumber)
Gets count of graphic elements from specified page.
|
int |
getHeight()
Gets the image height.
|
DwfLayersList |
getLayers()
Gets DWF pages layers.
|
DwfMetadata[] |
getMetadata()
Gets or sets the metadata information.
|
DwfPage[] |
getPages()
Gets the DWF pages.
|
String[] |
getStrings()
Gets all string values from image.
|
UnitType |
getUnitType()
Gets current unit type.
|
int |
getWidth()
Gets the image width.
|
boolean |
isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required.
|
void |
removeElement(int pageNumber,
int elementIndex)
Removes graphic element from specified page.
|
void |
setMetadata(DwfMetadata[] value)
Gets or sets the metadata information.
|
void |
updateSize()
Updates the image size.
|
canLoad, canLoad, canLoad, canLoad, canSave, getAnnotationService, getBounds, getContainer, getCustomProperties, getFileFormat, getFileFormat, getPalette, getSize, getUnitlessDefaultUnitType, getWatermarkGuardService, load, load, load, load, load, save, save, save, setPalettegetDataStreamContainer, save, save, save, saveclose, dispose, getDisposedpublic DwfPage[] getPages()
Gets the DWF pages. Returns an array of all DWF pages that are contained in the DWF image. Each DWF page defines all its available graphical parameters and all the objects that are drawn on it.
Retrieves image pages and changes it properties.string fileName = "exampleFile"; string file = string.Format("{0}.dwf", fileName); string outFile = string.Format("{0}.png", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (DwfImage image = (DwfImage) Image.Load(inStream)) using (FileStream stream = new FileStream(outFile, FileMode.Create)) { DwfWhipDrawable[] entities = image.Pages[0].Entities; foreach(DwfWhipDrawable drawable in entities) { if(drawable is DwfWhipPolyline) { ((DwfWhipPolyline) drawable).Points[0].X = -50; ((DwfWhipPolyline) drawable).Points[0].Y = -50; break; } } image.UpdateSize(); foreach (DwfWhipDrawable drawable in entities) { if (drawable is DwfWhipText) { ((DwfWhipText)drawable).Font.Name.Value.AsciiString = "Arial"; } } ImageOptionsBase options = new PngOptions(); options.VectorRasterizationOptions = new CadRasterizationOptions { PageWidth = (float)image.Pages[0].PaperWidth, PageHeight = (float)image.Pages[0].PaperHeight, DrawType = CadDrawTypeMode.UseObjectColor, }; image.Save(stream, options); }
public UnitType getUnitType()
Gets current unit type.
getUnitType in class Imagepublic DwfMetadata[] getMetadata()
Gets or sets the metadata information. Returns the array of metadata records from manifest and descriptors resources of Dwf/Dwfx package.
Retrieves all metadata records and modifies one of them.string file = "ExampleFile.dwf"; using (DwfImage image = (DwfImage) Aspose.CAD.Image.Load(file)) { string outFile = "ExampleFile_Changed.dwf"; using (FileStream fs = new FileStream(outFile, FileMode.Create)) { DwfMetadata[] metadata = image.Metadata; foreach (DwfMetadata dwfMetadata in metadata) { if (dwfMetadata.Category != "AutoCAD Drawing" || dwfMetadata.Name != "Creator") { continue; } dwfMetadata.Value = "Aspose CAD application"; } image.Metadata = metadata; ImageOptionsBase options = new DwfOptions { OutputMode = CadOutputMode.Convert }; image.Save(fs, jpegOptions); } }
public void setMetadata(DwfMetadata[] value)
Gets or sets the metadata information. Returns the array of metadata records from manifest and descriptors resources of Dwf/Dwfx package.
Retrieves all metadata records and modifies one of them.string file = "ExampleFile.dwf"; using (DwfImage image = (DwfImage) Aspose.CAD.Image.Load(file)) { string outFile = "ExampleFile_Changed.dwf"; using (FileStream fs = new FileStream(outFile, FileMode.Create)) { DwfMetadata[] metadata = image.Metadata; foreach (DwfMetadata dwfMetadata in metadata) { if (dwfMetadata.Category != "AutoCAD Drawing" || dwfMetadata.Name != "Creator") { continue; } dwfMetadata.Value = "Aspose CAD application"; } image.Metadata = metadata; ImageOptionsBase options = new DwfOptions { OutputMode = CadOutputMode.Convert }; image.Save(fs, jpegOptions); } }
public DwfLayersList getLayers()
Gets DWF pages layers. Returns the enumerable collection of DWF layers. The DWF data can be assigned to a specific DWF layer, which is a grouping drawing objects.
Exports specified layers.string file = "ExampleFile.dwf"; using (DwfImage image = (DwfImage) Aspose.CAD.Image.Load(file)) { foreach (var layer in image.Layers) { string outFile = "ExampleFile_" + layer + ".jpg"; using (FileStream fs = new FileStream(outFile, FileMode.Create)) { JpegOptions jpegOptions = new JpegOptions(); CadRasterizationOptions options = new CadRasterizationOptions(); options.Layouts = new string[] { image.Pages[0].Name }; options.Layers = new[] { layer.Name.AsciiString }; options.DrawType = CadDrawTypeMode.UseObjectColor; jpegOptions.VectorRasterizationOptions = options; image.Save(fs, jpegOptions); } } }
public boolean isCached()
Gets a value indicating whether object's data is cached currently and no data reading is required. Depending on the loading options only the necessary part of the data can be loaded into the cache from the image data. In this case, we can use this property to determine that only part of the image data is loaded into the cache.
Value:Checks whether the object's data is currently cached, and if not, caches it.string fileName = "exampleFile"; string file = string.Format("{0}.dwf", fileName); string outFile = string.Format("{0}.png", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (var image = (DwfImage) Image.Load(inStream)) using (FileStream stream = new FileStream(outFile, FileMode.Create)) { if(!image.IsCached) { image.CacheData(); } ImageOptionsBase options = new PngOptions(); options.VectorRasterizationOptions = new CadRasterizationOptions { DrawType = CadDrawTypeMode.UseObjectColor, }; image.Save(stream, options); }
true if object's data is cached; otherwise, false.isCached in class DataStreamSupporterpublic int getWidth()
Gets the image width.
Defines the X-axis distance between the leftmost point of all graphic objects in the image and their rightmost point.
The distance is measured in units corresponding to the value of the property Image.UnitType(Image#getUnitType)
Value: The image width.Uses image width value to set rasterization options.string fileName = "ExampleFile; string file = string.Format("{0}.dwf", fileName); string outPath = string.Format("{0}.pdf", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (DwfImage image = (DwfImage) Image.Load(inStream)) { CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); rasterizationOptions.PageSize = new SizeF(image.Width, image.Height); rasterizationOptions.PageHeight = image.Height; rasterizationOptions.PageWidth = image.Width; rasterizationOptions.UnitType = image.UnitType; PdfOptions pdfOptions = new PdfOptions { VectorRasterizationOptions = rasterizationOptions }; image.Save(outPath, pdfOptions); }
getWidth in interface IObjectWithBoundsgetWidth in class Imagepublic int getHeight()
Gets the image height.
Defines the Y-axis distance between the bottommost point of all graphical objects in the image and their topmost point.
The distance is measured in units corresponding to the value of the property Image.UnitType(Image#getUnitType)
Value: The image height.Uses image height value to set rasterization options.string fileName = "ExampleFile; string file = string.Format("{0}.dwf", fileName); string outPath = string.Format("{0}.pdf", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (DwfImage image = (DwfImage) Image.Load(inStream)) { CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); rasterizationOptions.PageSize = new SizeF(image.Width, image.Height); rasterizationOptions.PageHeight = image.Height; rasterizationOptions.PageWidth = image.Width; rasterizationOptions.UnitType = image.UnitType; PdfOptions pdfOptions = new PdfOptions { VectorRasterizationOptions = rasterizationOptions }; image.Save(outPath, pdfOptions); }
getHeight in interface IObjectWithBoundsgetHeight in class Imagepublic int getDepth()
Gets the image depth.
Value: The image depth.Prints drawing's depthImage drawing = ... System.Console.WriteLine("Drawing's depth: " + drawing.Depth);
public void addElement(int pageNumber,
DwfWhipDrawable element)
Adds graphic element to specified page.
Provides an opportunity to add a new graphic element to the existing ones in the image.
To add it, you need to create a new graphic element and
specify the index of the page in Pages(DwfImage.getPages()) array to which the element should be added.
Adds a new text graphic element to the first page of the image.string fileName = "exampleFile"; string file = string.Format("{0}.dwf", fileName); string outFile = string.Format("{0}.png", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (DwfImage image = (DwfImage) Image.Load(inStream)) using (FileStream stream = new FileStream(outFile, FileMode.Create)) { DwfWhipText text = new DwfWhipText(); text.Text = new DwfString("TEXT"); text.Color = Color.Red; text.Position = new DwfWhipLogicalPoint(4000, 4000); text.Font = new DwfWhipFont(); text.Font.Name = new DwfWhipOptionFontName(); text.Font.Name.Value = new DwfString("times new roman"); text.Font.Height = new DwfWhipOptionFontHeight(); text.Font.Height.Value = 2000; text.IsVisible = true; image.AddElement(0, text); ImageOptionsBase options = new PngOptions(); options.VectorRasterizationOptions = new CadRasterizationOptions { DrawType = CadDrawTypeMode.UseObjectColor, }; image.Save(stream, options); }
pageNumber - Index of the page in Pages(DwfImage.getPages()) array to add element to.element - Element to be added.public void removeElement(int pageNumber,
int elementIndex)
Removes graphic element from specified page.
Provides the ability to remove a graphic element from the image.
To remove it, you need to specify the page index in Pages(DwfImage.getPages()) array from which the element should be removed
and the index of the element in DwfPage.Entities(DwfPage.getEntities()) array.
Removes last graphic element from the first page of the image.string fileName = "exampleFile"; string file = string.Format("{0}.dwf", fileName); string outFile = string.Format("{0}.png", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (DwfImage image = (DwfImage) Image.Load(inStream)) using (FileStream stream = new FileStream(outFile, FileMode.Create)) { image.RemoveElement(0, image.Pages[0].Entities.Length-1); ImageOptionsBase options = new PngOptions(); options.VectorRasterizationOptions = new CadRasterizationOptions { DrawType = CadDrawTypeMode.UseObjectColor, }; image.Save(stream, options); }
pageNumber - Index of page in Pages(DwfImage.getPages()) array to remove element from.elementIndex - Index of element to be removed.public int getElementCount(int pageNumber)
Gets count of graphic elements from specified page.
Provides the ability to determine the number of graphic elements on a specific image page.
To get this value, you need to specify the page index in the array Pages(DwfImage.getPages()), the number of elements of which you want to get.
Removes last graphic element from the first page of the image.string fileName = "exampleFile"; string file = string.Format("{0}.dwf", fileName); string outFile = string.Format("{0}.png", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (DwfImage image = (DwfImage) Image.Load(inStream)) using (FileStream stream = new FileStream(outFile, FileMode.Create)) { image.RemoveElement(0, image.GetElementCount(0)-1); ImageOptionsBase options = new PngOptions(); options.VectorRasterizationOptions = new CadRasterizationOptions { DrawType = CadDrawTypeMode.UseObjectColor, }; image.Save(stream, options); }
pageNumber - Index of page to get count of graphic elements from.public void cacheData()
Caches the data and ensures no additional data loading will be performed from the underlying DataStreamSupporter.DataStreamContainer(DataStreamSupporter#getDataStreamContainer/DataStreamSupporter).
Depending on the loading options only the necessary part of the data can be loaded into the cache from the image data.
In this case, we can use this method to load all image data into the cache.
Checks whether the object's data is currently cached, and if not, caches it.string fileName = "exampleFile"; string file = string.Format("{0}.dwf", fileName); string outFile = string.Format("{0}.png", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (var image = (DwfImage) Image.Load(inStream)) using (FileStream stream = new FileStream(outFile, FileMode.Create)) { if(!image.IsCached) { image.CacheData(); } ImageOptionsBase options = new PngOptions(); options.VectorRasterizationOptions = new CadRasterizationOptions { DrawType = CadDrawTypeMode.UseObjectColor, }; image.Save(stream, options); }
cacheData in class DataStreamSupporterpublic void updateSize()
Updates the image size. Provides forced calculation of image size parameters. This calculation must be performed before using the image size parameters after changing the graphic content of the image that affects the image size parameters.
Retrieves image pages, changes it properties and updates image size parameters.string fileName = "exampleFile"; string file = string.Format("{0}.dwf", fileName); string outFile = string.Format("{0}.png", fileName); using (FileStream inStream = new FileStream(file, FileMode.Open)) using (var image = (DwfImage) Image.Load(inStream)) using (FileStream stream = new FileStream(outFile, FileMode.Create)) { DwfWhipDrawable[] entities = image.Pages[0].Entities; foreach(DwfWhipDrawable drawable in entities) { if(drawable is DwfWhipPolyline) { ((DwfWhipPolyline) drawable).Points[0].X = -50; ((DwfWhipPolyline) drawable).Points[0].Y = -50; break; } } image.UpdateSize(); ImageOptionsBase options = new PngOptions(); options.VectorRasterizationOptions = new CadRasterizationOptions { PageWidth = (float)image.Pages[0].PaperWidth, PageHeight = (float)image.Pages[0].PaperHeight, DrawType = CadDrawTypeMode.UseObjectColor, }; image.Save(stream, options); }
public String[] getStrings()
Gets all string values from image. Provides an opportunity to get the values of all text graphic elements present in the image in the form of an array of strings.
Retrieves values of all text graphic elements an prints it out to the console.string file = "ExampleFile.dwf"; string[] result; using (FileStream inStream = new FileStream(file, FileMode.Open)) using (Image image = Image.Load(inStream)) { result = image.GetStrings(); } foreach (string s in result) { Console.WriteLine(s); }
getStrings in class ImageCopyright (c) 2008-2025 Aspose Pty Ltd. All Rights Reserved.