/// <summary> /// Initializes a new instance of the <c>ImageDef</c> class. /// </summary> /// <param name="fileName">Image file name with full or relative path.</param> /// <param name="width">Image width in pixels.</param> /// <param name="horizontalResolution">Image horizontal resolution in pixels.</param> /// <param name="height">Image height in pixels.</param> /// <param name="verticalResolution">Image vertical resolution in pixels.</param> /// <param name="name">Image definition name, if null or empty the file name without the extension will be used.</param> /// <param name="units">Image resolution units.</param> /// <remarks> /// <para> /// The name assigned to the image definition must be unique. /// </para> /// <para> /// This is a generic constructor for all image formats supported by AutoCAD, note that not all AutoCAD versions support the same image formats. /// </para> /// <para> /// Note (this is from the ACAD docs): AutoCAD 2000, AutoCAD LT 2000, and later releases do not support LZW-compressed TIFF files, /// with the exception of English language versions sold in the US and Canada.<br /> /// If you have TIFF files that were created using LZW compression and want to insert them into a drawing /// you must resave the TIFF files with LZW compression disabled. /// </para> /// </remarks> public ImageDef(string fileName, int width, float horizontalResolution, int height, float verticalResolution, string name, ResolutionUnits units) : base(name, DxfObjectCode.ImageDef) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName", "The image file name cannot be empty or null."); } FileInfo info = new FileInfo(fileName); if (!info.Exists) { throw new FileNotFoundException("Image file not found", fileName); } this.fileName = fileName; this.width = width; this.height = height; this.horizontalResolution = horizontalResolution; this.verticalResolution = verticalResolution; this.resolutionUnits = units; // pixel size use the units defined in the document, it is controlled by the header variable $INSUNITS and the RasterVariables units this.onePixelSize = new Vector2(25.4 / horizontalResolution, 25.4 / verticalResolution); this.reactors = new Dictionary <string, ImageDefReactor>(); }
///<summary> /// Serves as a hash of this type. ///</summary> public override int GetHashCode() { return (ColorSpace.GetHashCode() ^ CompressionMethod.GetHashCode() ^ Format.GetHashCode() ^ Height.GetHashCode() ^ Interlace.GetHashCode() ^ ResolutionUnits.GetHashCode() ^ ResolutionX.GetHashCode() ^ ResolutionY.GetHashCode() ^ Width.GetHashCode()); }
public override void CopyFrom(DxfHandledObject from, CloneContext cloneContext) { base.CopyFrom(from, cloneContext); DxfImageDef dxfImageDef = (DxfImageDef)from; this.string_0 = dxfImageDef.string_0; this.size2D_0 = dxfImageDef.size2D_0; this.size2D_1 = dxfImageDef.size2D_1; this.resolutionUnits_0 = dxfImageDef.resolutionUnits_0; this.bool_0 = dxfImageDef.bool_0; this.int_0 = dxfImageDef.int_0; this.ibitmap_0 = dxfImageDef.ibitmap_0; }
/// <summary> /// Initializes a new instance of the <c>ImageDef</c> class. /// </summary> /// <param name="fileName">Image file name with full or relative path.</param> /// <param name="name">Image definition name, if null or empty the file name without the extension will be used.</param> /// <param name="units">Image resolution units, by defult centimeters will be used.</param> /// <remarks> /// <para> /// The name assigned to the image definition must be unique. /// </para> /// <para> /// Supported image formats: BMP, JPG, PNG, TIFF.<br /> /// Eventhought AutoCAD supports more image formats, this constructor is restricted to the ones the .net library supports in common with AutoCAD. /// Use the generic constructor instead. /// </para> /// <para> /// Note (this is from the ACAD docs): AutoCAD 2000, AutoCAD LT 2000, and later releases do not support LZW-compressed TIFF files, /// with the exception of English language versions sold in the US and Canada.<br /> /// If you have TIFF files that were created using LZW compression and want to insert them into a drawing /// you must resave the TIFF files with LZW compression disabled. /// </para> /// </remarks> public ImageDef(string fileName, string name, ResolutionUnits units = ResolutionUnits.Centimeters) : base(DxfObjectCode.ImageDef) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName", "The image file name cannot be empty or null."); } FileInfo info = new FileInfo(fileName); if (!info.Exists) { throw new FileNotFoundException("Image file not found", fileName); } this.name = string.IsNullOrEmpty(name) ? Path.GetFileNameWithoutExtension(fileName) : name; this.fileName = fileName; try { using (Image bitmap = Image.FromFile(fileName)) { this.width = bitmap.Width; this.height = bitmap.Height; if (units == ResolutionUnits.Centimeters) { // the System.Drawing.Image stores the image resolution in inches this.horizontalResolution = bitmap.HorizontalResolution / 2.54f; this.verticalResolution = bitmap.VerticalResolution / 2.54f; } else { this.horizontalResolution = bitmap.HorizontalResolution; this.verticalResolution = bitmap.VerticalResolution; } this.resolutionUnits = units; // pixel size use the units defined in the document, it is controlled by the header variable $INSUNITS this.onePixelSize = new Vector2(25.4 / bitmap.HorizontalResolution, 25.4 / bitmap.VerticalResolution); } } catch (Exception) { throw new ArgumentException("Image file not supported.", fileName); } this.reactors = new Dictionary <string, ImageDefReactor>(); }
/// <summary> /// Initializes a new instance of the <c>ImageDef</c> class. /// </summary> /// <param name="fileName">Image file name with full or relative path.</param> /// <param name="units">Image resolution units, by defult centimeters will be used.</param> /// <remarks> /// <para> /// The name of the file without extension will be used as the name of the image definition. /// </para> /// <para> /// Supported image formats: BMP, JPG, PNG, TIFF.<br /> /// Eventhought AutoCAD supports more image formats, this constructor is restricted to the ones the net framework supports in common with AutoCAD. /// Use the generic constructor instead. /// </para> /// <para> /// Note (this is from the ACAD docs): AutoCAD 2000, AutoCAD LT 2000, and later releases do not support LZW-compressed TIFF files, /// with the exception of English language versions sold in the US and Canada.<br /> /// If you have TIFF files that were created using LZW compression and want to insert them into a drawing /// you must resave the TIFF files with LZW compression disabled. /// </para> /// </remarks> public ImageDef(string fileName, ResolutionUnits units = ResolutionUnits.Centimeters) : this(fileName, Path.GetFileNameWithoutExtension(fileName), units) { }
/// <summary> /// Initializes a new instance of the <c>ImageDef</c> class. /// </summary> /// <param name="fileName">Image file name with full or relative path.</param> /// <param name="width">Image width in pixels.</param> /// <param name="horizontalResolution">Image horizontal resolution in pixels.</param> /// <param name="height">Image height in pixels.</param> /// <param name="verticalResolution">Image vetical resolution in pixels.</param> /// <param name="units">Image resolution units.</param> /// <remarks> /// <para> /// The name of the file without extension will be used as the name of the image definition. /// </para> /// <para> /// This is a generic constructor for all image formats supported by AutoCAD, note that not all AutoCAD versions support the same image formats. /// </para> /// <para> /// Note (this is from the ACAD docs): AutoCAD 2000, AutoCAD LT 2000, and later releases do not support LZW-compressed TIFF files, /// with the exception of English language versions sold in the US and Canada.<br /> /// If you have TIFF files that were created using LZW compression and want to insert them into a drawing /// you must resave the TIFF files with LZW compression disabled. /// </para> /// </remarks> public ImageDef(string fileName, int width, float horizontalResolution, int height, float verticalResolution, ResolutionUnits units) : this(fileName, width, horizontalResolution, height, verticalResolution, Path.GetFileNameWithoutExtension(fileName), units) { }
/// <summary> /// Initializes a new instance of the <c>ImageDef</c> class. /// </summary> /// <param name="fileName">Image file name with full or relative path.</param> /// <param name="units">Image resolution units, by defult centimeters will be used.</param> /// <remarks> /// <para> /// The name of the file without extension will be used as the name of the image definition. /// </para> /// <para> /// Supported image formats: BMP, JPG, PNG, TIFF.<br /> /// Eventhought AutoCAD supports more image formats, this constructor is restricted to the ones the net framework supports in common with AutoCAD. /// Use the generic constructor instead. /// </para> /// <para> /// Note (this is from the ACAD docs): AutoCAD 2000, AutoCAD LT 2000, and later releases do not support LZW-compressed TIFF files, /// with the exception of English language versions sold in the US and Canada.<br /> /// If you have TIFF files that were created using LZW compression and want to insert them into a drawing /// you must resave the TIFF files with LZW compression disabled. /// </para> /// </remarks> public ImageDef(string fileName, ResolutionUnits units = ResolutionUnits.Centimeters) : this(fileName, null, units) { }
/// <summary> /// Initializes a new instance of the <c>ImageDef</c> class. /// </summary> /// <param name="fileName">Image file name with full or relative path.</param> /// <param name="width">Image width in pixels.</param> /// <param name="horizontalResolution">Image horizontal resolution in pixels.</param> /// <param name="height">Image height in pixels.</param> /// <param name="verticalResolution">Image vetical resolution in pixels.</param> /// <param name="units">Image resolution units.</param> /// <remarks> /// <para> /// The name of the file without extension will be used as the name of the image definition. /// </para> /// <para> /// This is a generic constructor for all image formats supported by AutoCAD, note that not all AutoCAD versions support the same image formats. /// </para> /// <para> /// Note (this is from the ACAD docs): AutoCAD 2000, AutoCAD LT 2000, and later releases do not support LZW-compressed TIFF files, /// with the exception of English language versions sold in the US and Canada.<br /> /// If you have TIFF files that were created using LZW compression and want to insert them into a drawing /// you must resave the TIFF files with LZW compression disabled. /// </para> /// </remarks> public ImageDef(string fileName, int width, float horizontalResolution, int height, float verticalResolution, ResolutionUnits units) : this(fileName, width, horizontalResolution, height, verticalResolution, null, units) { }