Packages

 

com.aspose.cad

Class Image

  • java.lang.Object
    • com.aspose.cad.DisposableObject
      • com.aspose.cad.DataStreamSupporter
        • com.aspose.cad.Image
    • Method Detail

      • getBounds

        public com.aspose.cad.Rectangle getBounds()

        Gets the image bounds.


         Custom processing of a drawing depending on its bounds
         
         var fileName = @"C:\path\drawing.dwg";
         using (Aspose.CAD.Image drawing = Aspose.CAD.Image.Load(fileName))
         {
             if (drawing.Bounds.Width > 500)
             {
                 // ...
             }
         }
         

        Specified by:
        getBounds in interface IObjectWithBounds
        Returns:
        The image bounds.
      • getContainer

        public Image getContainer()

        Gets the Image container.


         Gets root (top-level) drawing where current drawing is nested in
         
         Image drawing = ...
         while (drawing.Container != null)
         {
             drawing = drawing.Container;
         }
         

        Returns:
        The Image container.


        If this property is not null it indicates the image is contained whithin another image.

      • getHeight

        public abstract int getHeight()

        Gets the image height.


         Prints drawing's height
         
         Image drawing = ...
         System.Console.WriteLine("Drawing's height: " + drawing.Height);
         

        Specified by:
        getHeight in interface IObjectWithBounds
        Returns:
        The image height.
      • getPalette

        public com.aspose.cad.IColorPalette getPalette()

        Gets or sets the color palette.


         Asserts DGN drawing contains palette
         
         var fileName = @"C:\path\drawing.dgn";
         using (DgnImage drawing = (DgnImage)Image.Load(fileName))
         {
             Assert.IsNotNull(drawing.Palette);
         }
         

        Returns:
        The color palette.
      • setPalette

        public void setPalette(com.aspose.cad.IColorPalette value)

        Gets or sets the color palette.


         Asserts DGN drawing contains palette
         
         var fileName = @"C:\path\drawing.dgn";
         using (DgnImage drawing = (DgnImage)Image.Load(fileName))
         {
             Assert.IsNotNull(drawing.Palette);
         }
         

        Parameters:
        value - The color palette.
      • getSize

        public com.aspose.cad.Size getSize()

        Gets the image size.


         Processes a drawing if it is not empty
         
         var fileName = @"C:\path\drawing.dwg";
         using (Aspose.CAD.Image drawing = Aspose.CAD.Image.Load(fileName))
         {
             if (!drawing.Size.IsEmpty)
             {
                 // ...
             }
         }
         

        Specified by:
        getSize in interface IObjectWithBounds
        Returns:
        The image size.
      • getWidth

        public abstract int getWidth()

        Gets the image width.


         Prints drawing's width
         
         Image drawing = ...
         System.Console.WriteLine("Drawing's width: " + drawing.Width);
         

        Specified by:
        getWidth in interface IObjectWithBounds
        Returns:
        The image width.
      • hasBackgroundColor

        @Deprecated
        public boolean hasBackgroundColor()
        Deprecated. 

        Gets or sets a value indicating whether image has background color.

      • setBackgroundColor

        @Deprecated
        public void setBackgroundColor(boolean value)
        Deprecated. 

        Gets or sets a value indicating whether image has background color.

      • getBackgroundColor

        @Deprecated
        public com.aspose.cad.Color getBackgroundColor()
        Deprecated. 

        Gets or sets a value for the background color.

      • setBackgroundColor

        @Deprecated
        public void setBackgroundColor(com.aspose.cad.Color value)
        Deprecated. 

        Gets or sets a value for the background color.

      • getUnitType

        public int getUnitType()

        Gets current unit type.


         Normalize export page size despite of unit type defined on drawing
         
         public 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);
         }
         

      • getAttributes

        public String[] getAttributes()

        Gets the attributes collection.


         Prints attributes defined on drawing
         
         public static void PrintDrawingAttributes()
         {
             using (var ifcImage = Image.Load("drawing.ifc"))
             {
                 foreach (string attr in ifcImage.Attributes)
                 {
                     Console.WriteLine(ifcImage.GetAttributeValue(attr));
                 }
             }
         }
         

      • canLoad

        public static boolean canLoad(String filePath)

        Determines whether image can be loaded from the specified file path.


         Checks whether loading of a drawing is possible
         
         var fileName = @"C:\path\drawing.dwg";
         if (Aspose.CAD.Image.CanLoad(fileName))
         {
             using (Aspose.CAD.Image drawing = Aspose.CAD.Image.Load(fileName))
             {
                 // process the drawing
             }
         }
         

        Parameters:
        filePath - The file path.
        Returns:
        true if image can be loaded from the specified file; otherwise, false.
      • canLoad

        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 encoding
         
         var 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
             }
         }
         

        Parameters:
        filePath - The file path.
        loadOptions - The load options.
        Returns:
        true if an image can be loaded from the specified file; otherwise, false.
      • canLoad

        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 specified
         
         using (var f = File.OpenRead("file.dxf"))
         {
             var currentPosition = f.Position;
             if (Image.CanLoad(f))
             {
                 Assert.AreEqual(currentPosition, f.Position);
                 // process the drawing...
             }
         }
         

        Parameters:
        stream - The stream to load from.
        Returns:
        true if image can be loaded from the specified stream; otherwise, false.
      • canLoad

        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 encoding
         
         using (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...
             }
         }
         

        Parameters:
        stream - The stream to load from.
        loadOptions - The load options.
        Returns:
        true if image can be loaded from the specified stream; otherwise, false.
      • getFileFormat

        public static long getFileFormat(String filePath)

        Gets the file format.


         Determines whether file is a DWG drawing
         
         var fileFormat = Image.GetFileFormat("file.dwg");
         if (fileFormat >= FileFormat.CadR010 && fileFormat <= FileFormat.CadR2010)
         {
             Console.WriteLine("This is a DWG drawing");
         }
         

        Parameters:
        filePath - The file path.


        The file format determined does not mean that the specified image may be loaded. Use one of the CanLoad method overloads to determine whether file may be loaded.

        Returns:
        The determined file format.
      • getFileFormat

        public static long getFileFormat(InputStream stream)

        Gets the file format.


         Determines whether a stream contains a DXF drawing
         
         using (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");
             }
         }
         

        Parameters:
        stream - The stream.


        The file format determined does not mean that the specified image may be loaded. Use one of the CanLoad method overloads to determine whether stream may be loaded.

        Returns:
        The determined file format.
      • load

        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 called
         
         using (var image = Aspose.CAD.Image.Load("fileName.dwg", new LoadOptions
         {
             UnloadOnDispose = true
         }))
         {
             // process the drawing
         }
         

        Parameters:
        filePath - The file path to load image from.
        loadOptions - The load options.
        Returns:
        The loaded drawing.
      • load

        public static Image load(String filePath)

        Loads a new image from the specified file.


         Loads a drawing to process
         
         using (var image = Aspose.CAD.Image.Load("fileName.dwg"))
         {
             // process the drawing
         }
         

        Parameters:
        filePath - The file path to load image from.
        Returns:
        The loaded drawing.
      • load

        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 called
         
         using (var image = Aspose.CAD.Image.Load(File.OpenRead("fileName.dwg"), new LoadOptions
         {
             UnloadOnDispose = true
         }))
         {
             // process the drawing
         }
         

        Parameters:
        stream - The stream to load image from.
        loadOptions - The load options.
        Returns:
        The loaded drawing.
      • load

        public static Image load(InputStream stream)

        Loads a new image from the specified stream.


         Loads a drawing to process from corresponding stream
         
         using (var image = Aspose.CAD.Image.Load(File.OpenRead("fileName.dwg"))
         {
             // process the drawing
         }
         

        Parameters:
        stream - The stream to load image from.
        Returns:
        The loaded drawing.
      • canSave

        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 options
         
         using (var image = Aspose.CAD.Image.Load("fileName.dwg"))
         {
             if (image.CanSave(new BmpOptions()))
             {
                 // export to BMP format is possible with this options
             }
         }
         

        Parameters:
        options - The save options to use.
        Returns:
        true if image can be saved to the specified file format represented by the passed save options; otherwise, false.
      • save

        public final void save()

        Saves the image data to the underlying stream.


         Saves all changes made to drawing. Note: Only DXF is currently supported
         
         using (var image = Aspose.CAD.Image.Load("fileName.dwg"))
         {
             image.Save();
         }
         

        Overrides:
        save in class com.aspose.cad.DataStreamSupporter
      • save

        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 size
         
         using (var image = Aspose.CAD.Image.Load("fileName.dwg"))
         {
             image.Save("targetFile.bmp", new BmpOptions()
             {
                 VectorRasterizationOptions = new CadRasterizationOptions()
                 {
                     PageWidth = 640,
                     PageHeight = 480
                 }
             });
         }
         

        Parameters:
        filePath - The file path.
        options - The options.
      • save

        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.

        Parameters:
        stream - The stream to save the image's data to.
        optionsBase - The save options.
        Throws:
        com.aspose.ms.System.ArgumentNullException - optionsBase
        com.aspose.ms.System.ArgumentException - Cannot save to the specified format as it is not supported at the moment.;optionsBase
        com.aspose.cad.cadexceptions.ImageSaveException - Image export failed.
      • getAttributeValue

        public final String getAttributeValue(String attribute)

        Gets attribute value.


         Prints 'IfcStructure' attribute of an IFC drawing
         
         using (var ifcImage = Image.Load("drawing.ifc"))
         {
             var structure = ifcImage.GetAttributeValue("IfcStructure");
             Console.WriteLine(structure);
         }
         

        Parameters:
        attribute - The attribute.
        Returns:
        The attribute value.