public abstract class Image extends com.aspose.cad.DataStreamSupporter implements IObjectWithBounds
The image is the base class for all type of drawings.
Modifier and Type | Method and Description |
---|---|
static boolean |
canLoad(InputStream stream)
Determines whether image can be loaded from the specified stream.
|
static boolean |
canLoad(InputStream stream,
LoadOptions loadOptions)
Determines whether image can be loaded from the specified stream and optionally using the specified
loadOptions . |
static boolean |
canLoad(String filePath)
Determines whether image can be loaded from the specified file path.
|
static boolean |
canLoad(String filePath,
LoadOptions loadOptions)
Determines whether an image can be loaded from the specified file path and optionally using the specified open options
|
boolean |
canSave(ImageOptionsBase options)
Determines whether image can be saved to the specified file format represented by the passed save options.
|
com.aspose.cad.Color |
getBackgroundColor()
Deprecated.
|
com.aspose.cad.Rectangle |
getBounds()
Gets the image bounds.
|
Image |
getContainer()
Gets the
Image container. |
static long |
getFileFormat(InputStream stream)
Gets the file format.
|
static long |
getFileFormat(String filePath)
Gets the file format.
|
abstract int |
getHeight()
Gets the image height.
|
com.aspose.cad.IColorPalette |
getPalette()
Gets or sets the color palette.
|
com.aspose.cad.Size |
getSize()
Gets the image size.
|
String[] |
getStrings()
Gets all string values from image.
|
int |
getUnitlessDefaultUnitType()
Assumed unit type when UnitType is set to Unitless
|
int |
getUnitType()
Gets current unit type.
|
abstract int |
getWidth()
Gets the image width.
|
boolean |
hasBackgroundColor()
Deprecated.
|
static Image |
load(InputStream stream)
Loads a new image from the specified stream.
|
static Image |
load(InputStream stream,
LoadOptions loadOptions)
Loads a new image from the specified stream.
|
static Image |
load(String filePath)
Loads a new image from the specified file.
|
static Image |
load(String filePath,
LoadOptions loadOptions)
Loads a new image from the specified file.
|
void |
save()
Saves the image data to the underlying stream.
|
void |
save(OutputStream stream,
ImageOptionsBase optionsBase)
Saves the image's data to the specified stream in the specified file format according to save options.
|
void |
save(String filePath,
ImageOptionsBase options)
Saves the object's data to the specified file location in the specified file format according to save options.
|
void |
setBackgroundColor(boolean value)
Deprecated.
|
void |
setBackgroundColor(com.aspose.cad.Color value)
Deprecated.
|
void |
setPalette(com.aspose.cad.IColorPalette value)
Gets or sets the color palette.
|
public com.aspose.cad.Rectangle getBounds()
Gets the image bounds.
Custom processing of a drawing depending on its boundsvar fileName = @"C:\path\drawing.dwg"; using (Aspose.CAD.Image drawing = Aspose.CAD.Image.Load(fileName)) { if (drawing.Bounds.Width > 500) { // ... } }
getBounds
in interface IObjectWithBounds
public Image getContainer()
Gets the Image
container.
Gets root (top-level) drawing where current drawing is nested inImage drawing = ... while (drawing.Container != null) { drawing = drawing.Container; }
Image
container.
public abstract int getHeight()
Gets the image height.
Prints drawing's heightImage drawing = ... System.Console.WriteLine("Drawing's height: " + drawing.Height);
getHeight
in interface IObjectWithBounds
public com.aspose.cad.IColorPalette getPalette()
Gets or sets the color palette.
Asserts DGN drawing contains palettevar fileName = @"C:\path\drawing.dgn"; using (DgnImage drawing = (DgnImage)Image.Load(fileName)) { Assert.IsNotNull(drawing.Palette); }
public void setPalette(com.aspose.cad.IColorPalette value)
Gets or sets the color palette.
Asserts DGN drawing contains palettevar fileName = @"C:\path\drawing.dgn"; using (DgnImage drawing = (DgnImage)Image.Load(fileName)) { Assert.IsNotNull(drawing.Palette); }
value
- The color palette.public com.aspose.cad.Size getSize()
Gets the image size.
Processes a drawing if it is not emptyvar fileName = @"C:\path\drawing.dwg"; using (Aspose.CAD.Image drawing = Aspose.CAD.Image.Load(fileName)) { if (!drawing.Size.IsEmpty) { // ... } }
getSize
in interface IObjectWithBounds
public abstract int getWidth()
Gets the image width.
Prints drawing's widthImage drawing = ... System.Console.WriteLine("Drawing's width: " + drawing.Width);
getWidth
in interface IObjectWithBounds
@Deprecated public boolean hasBackgroundColor()
Gets or sets a value indicating whether image has background color.
@Deprecated public void setBackgroundColor(boolean value)
Gets or sets a value indicating whether image has background color.
@Deprecated public com.aspose.cad.Color getBackgroundColor()
Gets or sets a value for the background color.
@Deprecated public void setBackgroundColor(com.aspose.cad.Color value)
Gets or sets a value for the background color.
public int getUnitType()
Gets current unit type.
Normalize export page size despite of unit type defined on drawingpublic static void ExportPageSizeNormalizationExample() { using (CadImage cadImage = (CadImage)Image.Load("fileName.dwg")) { CadVportList viewPorts = cadImage.ViewPorts; CadVportTableObject table = (CadVportTableObject)viewPorts[0]; Console.WriteLine(table.ViewTwistAngle.Value); bool currentUnitIsMetric = false; double currentUnitCoefficient = 1.0; var values = DefineUnitSystem(cadImage.UnitType); currentUnitIsMetric = values.Item1; currentUnitCoefficient = values.Item2; PngOptions pngOptions = new PngOptions(); var rasterizationOptions = new CadRasterizationOptions(); rasterizationOptions.Layouts = new string[] { "Model" }; if (currentUnitIsMetric) { double metersCoeff = 1 / 1000.0; double scaleFactor = metersCoeff / currentUnitCoefficient; rasterizationOptions.PageWidth = (float)(210 * scaleFactor); rasterizationOptions.PageHeight = (float)(297 * scaleFactor); rasterizationOptions.UnitType = UnitType.Millimeter; } else { rasterizationOptions.PageWidth = (float)(8.27f / currentUnitCoefficient); rasterizationOptions.PageHeight = (float)(11.69f / currentUnitCoefficient); rasterizationOptions.UnitType = UnitType.Inch; } pngOptions.VectorRasterizationOptions = rasterizationOptions; cadImage.Save("fileName.png", pngOptions); } } protected static Tuple<bool, double> DefineUnitSystem(UnitType unitType) { var isMetric = false; var coefficient = 1.0; switch (unitType) { case UnitType.Parsec: coefficient = 3.0857 * 10000000000000000.0; isMetric = true; break; case UnitType.LightYear: coefficient = 9.4607 * 1000000000000000.0; isMetric = true; break; case UnitType.AstronomicalUnit: coefficient = 1.4960 * 100000000000.0; isMetric = true; break; case UnitType.Gigameter: coefficient = 1000000000.0; isMetric = true; break; case UnitType.Kilometer: coefficient = 1000.0; isMetric = true; break; case UnitType.Decameter: isMetric = true; coefficient = 10.0; break; case UnitType.Hectometer: isMetric = true; coefficient = 100.0; break; case UnitType.Meter: isMetric = true; coefficient = 1.0; break; case UnitType.Centimenter: isMetric = true; coefficient = 0.01; break; case UnitType.Decimeter: isMetric = true; coefficient = 0.1; break; case UnitType.Millimeter: isMetric = true; coefficient = 0.001; break; case UnitType.Micrometer: isMetric = true; coefficient = 0.000001; break; case UnitType.Nanometer: isMetric = true; coefficient = 0.000000001; break; case UnitType.Angstrom: isMetric = true; coefficient = 0.0000000001; break; case UnitType.Inch: coefficient = 1.0; break; case UnitType.MicroInch: coefficient = 0.000001; break; case UnitType.Mil: coefficient = 0.001; break; case UnitType.Foot: coefficient = 12.0; break; case UnitType.Yard: coefficient = 36.0; break; case UnitType.Mile: coefficient = 63360.0; break; } return new Tuple<bool, double>(isMetric, coefficient); }
public int getUnitlessDefaultUnitType()
Assumed unit type when UnitType is set to Unitless
public static boolean canLoad(String filePath)
Determines whether image can be loaded from the specified file path.
Checks whether loading of a drawing is possiblevar fileName = @"C:\path\drawing.dwg"; if (Aspose.CAD.Image.CanLoad(fileName)) { using (Aspose.CAD.Image drawing = Aspose.CAD.Image.Load(fileName)) { // process the drawing } }
filePath
- The file path.true
if image can be loaded from the specified file; otherwise, false
.public static boolean canLoad(String filePath, LoadOptions loadOptions)
Determines whether an image can be loaded from the specified file path and optionally using the specified open options
Checks whether loading of a drawing is possible with specified encodingvar fileName = @"C:\path\drawing.dwg"; if (Aspose.CAD.Image.CanLoad(fileName, new LoadOptions { SpecifiedEncoding = CodePages.Japanese })) { using (Aspose.CAD.Image drawing = Aspose.CAD.Image.Load(fileName)) { // process the drawing } }
filePath
- The file path.loadOptions
- The load options.true
if an image can be loaded from the specified file; otherwise, false
.public static boolean canLoad(InputStream stream)
Determines whether image can be loaded from the specified stream.
Checks whether loading of a drawing is possible from the stream specifiedusing (var f = File.OpenRead("file.dxf")) { var currentPosition = f.Position; if (Image.CanLoad(f)) { Assert.AreEqual(currentPosition, f.Position); // process the drawing... } }
stream
- The stream to load from.true
if image can be loaded from the specified stream; otherwise, false
.public static boolean canLoad(InputStream stream, LoadOptions loadOptions)
Determines whether image can be loaded from the specified stream and optionally using the specified loadOptions
.
Checks whether loading of a drawing is possible from the stream specified with a corresponding encodingusing (var f = File.OpenRead("file.dwg", new LoadOptions { SpecifiedEncoding = CodePages.Japanese })) { var currentPosition = f.Position; if (Image.CanLoad(f)) { Assert.AreEqual(currentPosition, f.Position); // process the drawing... } }
stream
- The stream to load from.loadOptions
- The load options.true
if image can be loaded from the specified stream; otherwise, false
.public static long getFileFormat(String filePath)
Gets the file format.
Determines whether file is a DWG drawingvar fileFormat = Image.GetFileFormat("file.dwg"); if (fileFormat >= FileFormat.CadR010 && fileFormat <= FileFormat.CadR2010) { Console.WriteLine("This is a DWG drawing"); }
filePath
- The file path.
public String[] getStrings()
Gets all string values from image.
public static long getFileFormat(InputStream stream)
Gets the file format.
Determines whether a stream contains a DXF drawingusing (var f = File.OpenRead("file.dxf")) { var fileFormat = Image.GetFileFormat(f); if (fileFormat >= FileFormat.DXFCadR010 && fileFormat <= FileFormat.DXFCadR2010) { Console.WriteLine("This is a DXF drawing"); } }
stream
- The stream.
public static Image load(String filePath, LoadOptions loadOptions)
Loads a new image from the specified file.
Loads a drawing to process and unloads all related resources when dispose is calledusing (var image = Aspose.CAD.Image.Load("fileName.dwg", new LoadOptions { UnloadOnDispose = true })) { // process the drawing }
filePath
- The file path to load image from.loadOptions
- The load options.public static Image load(String filePath)
Loads a new image from the specified file.
Loads a drawing to processusing (var image = Aspose.CAD.Image.Load("fileName.dwg")) { // process the drawing }
filePath
- The file path to load image from.public static Image load(InputStream stream, LoadOptions loadOptions)
Loads a new image from the specified stream.
Loads a drawing to process from corresponding stream and unloads all related resources when dispose is calledusing (var image = Aspose.CAD.Image.Load(File.OpenRead("fileName.dwg"), new LoadOptions { UnloadOnDispose = true })) { // process the drawing }
stream
- The stream to load image from.loadOptions
- The load options.public static Image load(InputStream stream)
Loads a new image from the specified stream.
Loads a drawing to process from corresponding streamusing (var image = Aspose.CAD.Image.Load(File.OpenRead("fileName.dwg")) { // process the drawing }
stream
- The stream to load image from.public boolean canSave(ImageOptionsBase options)
Determines whether image can be saved to the specified file format represented by the passed save options.
Checks whether export is possible to BMP with default optionsusing (var image = Aspose.CAD.Image.Load("fileName.dwg")) { if (image.CanSave(new BmpOptions())) { // export to BMP format is possible with this options } }
options
- The save options to use.true
if image can be saved to the specified file format represented by the passed save options; otherwise, false
.public final void save()
Saves the image data to the underlying stream.
Saves all changes made to drawing. Note: Only DXF is currently supportedusing (var image = Aspose.CAD.Image.Load("fileName.dwg")) { image.Save(); }
save
in class com.aspose.cad.DataStreamSupporter
public void save(String filePath, ImageOptionsBase options)
Saves the object's data to the specified file location in the specified file format according to save options.
Exports drawing to BMP with specified sizeusing (var image = Aspose.CAD.Image.Load("fileName.dwg")) { image.Save("targetFile.bmp", new BmpOptions() { VectorRasterizationOptions = new CadRasterizationOptions() { PageWidth = 640, PageHeight = 480 } }); }
filePath
- The file path.options
- The options.public void save(OutputStream stream, ImageOptionsBase optionsBase)
Saves the image's data to the specified stream in the specified file format according to save options.
stream
- The stream to save the image's data to.optionsBase
- The save options.com.aspose.ms.System.ArgumentNullException
- optionsBasecom.aspose.ms.System.ArgumentException
- Cannot save to the specified format as it is not supported at the moment.;optionsBasecom.aspose.cad.cadexceptions.ImageSaveException
- Image export failed.