/// <summary> /// Opens the file, assuming that the fileName has already been specified using a Dot Net Image object. /// </summary> public override void Open() { _myImage?.Dispose(); using (var stream = File.OpenRead(Filename)) using (var temp = Image.FromStream(stream)) { _myImage = new Bitmap(temp.Width, temp.Height, PixelFormat.Format32bppArgb); Width = temp.Width; Height = temp.Height; using var g = Graphics.FromImage(_myImage); g.DrawImage(temp, 0, 0, temp.Width, temp.Height); // don't draw unscaled because then nothing is shown } WorldFile = new WorldFile(Filename); if (WorldFile.Affine == null) { WorldFile.Affine = new[] { .5, 1.0, 0, Height - .5, 0, -1.0 } } ; Bounds = new RasterBounds(Height, Width, WorldFile.Affine); NumBands = 4; BytesPerPixel = 4; CopyBitmapToValues(); }
/// <summary> /// Opens the file, assuming that the fileName has already been specified using a Dot Net Image object /// </summary> public override void Open() { if (_myImage != null) { _myImage.Dispose(); } using (FileStream stream = new FileStream(Filename, FileMode.Open)) { using (Image temp = Image.FromStream(stream)) { _myImage = new Bitmap(temp.Width, temp.Height, PixelFormat.Format32bppArgb); Width = temp.Width; Height = temp.Height; using (Graphics g = Graphics.FromImage(_myImage)) { g.DrawImage(temp, new Rectangle(0, 0, temp.Width, temp.Height)); } } } WorldFile = new WorldFile(Filename); if (WorldFile.Affine == null) { WorldFile.Affine = new[] { .5, 1.0, 0, _myImage.Height - .5, 0, -1.0 } } ; Bounds = new RasterBounds(_myImage.Height, _myImage.Width, WorldFile.Affine); NumBands = 4; BytesPerPixel = 4; CopyBitmapToValues(); }
/// <summary> /// Creates a new image and world file, placing the default bounds at the origin, with one pixel per unit. /// </summary> /// <param name="fileName">The string fileName.</param> /// <param name="width">The integer width.</param> /// <param name="height">The integer height.</param> /// <param name="bandType">The ImageBandType that clarifies how the separate bands are layered in the image.</param> /// <returns>The create image.</returns> public override IImageData Create(string fileName, int width, int height, ImageBandType bandType) { Filename = fileName; WorldFile = new WorldFile(); double[] aff = { 1.0, 0, 0, -1.0, 0, height }; Bounds = new RasterBounds(height, width, aff); WorldFile.Filename = WorldFile.GenerateFilename(fileName); Width = width; Height = height; _myImage = new Bitmap(width, height); string ext = Path.GetExtension(fileName); ImageFormat imageFormat = ext switch { ".bmp" => ImageFormat.Bmp, ".emf" => ImageFormat.Emf, ".exf" => ImageFormat.Exif, ".gif" => ImageFormat.Gif, ".ico" => ImageFormat.Icon, ".jpg" => ImageFormat.Jpeg, ".mbp" => ImageFormat.MemoryBmp, ".png" => ImageFormat.Png, ".tif" => ImageFormat.Tiff, ".wmf" => ImageFormat.Wmf, _ => throw new ArgumentOutOfRangeException(nameof(fileName), DataStrings.FileTypeNotSupported), }; _myImage.Save(fileName, imageFormat); NumBands = 4; BytesPerPixel = 4; CopyBitmapToValues(); return(this); }
/// <summary> /// Saves the image to the specified fileName /// </summary> /// <param name="fileName"> /// The string fileName to save this as /// </param> public override void SaveAs(string fileName) { Filename = fileName; if (WorldFile != null) { WorldFile.Filename = WorldFile.GenerateFilename(fileName); } Save(); }
/// <summary> /// Initializes a new instance of the <see cref="InRamImageData"/> class. /// Constructs a new ImageData of the specified width and height. /// </summary> /// <param name="width"> /// The integer width in pixels. /// </param> /// <param name="height"> /// The integer height in pixels. /// </param> public InRamImageData(int width, int height) { WorldFile = new WorldFile(); double[] aff = new[] { .5, 1.0, 0, _myImage.Height - .5, 0, -1.0 }; Bounds = new RasterBounds(height, width, aff); _myImage = new Bitmap(width, height); Width = width; Height = height; MemorySetup(); }
/// <summary> /// Initializes a new instance of the <see cref="InRamImageData"/> class. /// Creates the bitmap from the raw image specified. The bounds should be set on this later. /// </summary> /// <param name="rawImage">The raw image.</param> public InRamImageData(Image rawImage) { _myImage = new Bitmap(rawImage.Width, rawImage.Height); Width = rawImage.Width; Height = rawImage.Height; using (var g = Graphics.FromImage(_myImage)) g.DrawImageUnscaled(rawImage, 0, 0); WorldFile = new WorldFile(); double[] aff = { .5, 1.0, 0, rawImage.Height - .5, 0, -1.0 }; Bounds = new RasterBounds(rawImage.Height, rawImage.Width, aff); MemorySetup(); }
/// <summary> /// Initializes a new instance of the <see cref="InRamImageData"/> class. /// Creates the bitmap from the raw image specified. The bounds should be set on this later. /// </summary> /// <param name="rawImage"> /// The raw image. /// </param> public InRamImageData(Image rawImage) { _myImage = new Bitmap(rawImage.Width, rawImage.Height); Width = rawImage.Width; Height = rawImage.Height; Graphics g = Graphics.FromImage(_myImage); g.DrawImageUnscaled(rawImage, 0, 0); g.Dispose(); WorldFile = new WorldFile(); double[] aff = new[] { .5, 1.0, 0, _myImage.Height - .5, 0, -1.0 }; Bounds = new RasterBounds(_myImage.Height, _myImage.Width, aff); MemorySetup(); }
/// <summary> /// Opens the file, assuming that the fileName has already been specified using a Dot Net Image object /// </summary> public override void Open() { if (_myImage != null) { _myImage.Dispose(); } using (FileStream stream = new FileStream(Filename, FileMode.Open)) { using (Image temp = Image.FromStream(stream)) { _myImage = new Bitmap(temp.Width, temp.Height, PixelFormat.Format32bppArgb); Width = temp.Width; Height = temp.Height; using (Graphics g = Graphics.FromImage(_myImage)) { g.DrawImage(temp, new Rectangle(0, 0, temp.Width, temp.Height)); } } } WorldFile = new WorldFile(Filename); if (WorldFile.Affine == null) WorldFile.Affine = new[] { .5, 1.0, 0, _myImage.Height - .5, 0, -1.0 }; Bounds = new RasterBounds(_myImage.Height, _myImage.Width, WorldFile.Affine); NumBands = 4; BytesPerPixel = 4; CopyBitmapToValues(); }
/// <summary> /// Creates a new image and world file, placing the default bounds at the origin, with one pixel per unit. /// </summary> /// <param name="fileName"> /// The string fileName /// </param> /// <param name="width"> /// The integer width /// </param> /// <param name="height"> /// The integer height /// </param> /// <param name="bandType">The ImageBandType that clarifies how the separate bands are layered in the image.</param> public override IImageData Create(string fileName, int width, int height, ImageBandType bandType) { Filename = fileName; WorldFile = new WorldFile(); double[] aff = new[] { 1.0, 0, 0, -1.0, 0, height }; Bounds = new RasterBounds(height, width, aff); WorldFile.Filename = WorldFile.GenerateFilename(fileName); Width = width; Height = height; _myImage = new Bitmap(width, height); string ext = Path.GetExtension(fileName); switch (ext) { case ".bmp": _myImage.Save(fileName, ImageFormat.Bmp); break; case ".emf": _myImage.Save(fileName, ImageFormat.Emf); break; case ".exf": _myImage.Save(fileName, ImageFormat.Exif); break; case ".gif": _myImage.Save(fileName, ImageFormat.Gif); break; case ".ico": _myImage.Save(fileName, ImageFormat.Icon); break; case ".jpg": _myImage.Save(fileName, ImageFormat.Jpeg); break; case ".mbp": _myImage.Save(fileName, ImageFormat.MemoryBmp); break; case ".png": _myImage.Save(fileName, ImageFormat.Png); break; case ".tif": _myImage.Save(fileName, ImageFormat.Tiff); break; case ".wmf": _myImage.Save(fileName, ImageFormat.Wmf); break; } NumBands = 4; BytesPerPixel = 4; CopyBitmapToValues(); return this; }
/// <summary> /// Saves the current image and world file. /// </summary> public override void Save() { _myImage.Save(Filename); WorldFile.Save(); }
/// <summary> /// Creates a new image and world file, placing the default bounds at the origin, with one pixel per unit. /// </summary> /// <param name="fileName"> /// The string fileName /// </param> /// <param name="width"> /// The integer width /// </param> /// <param name="height"> /// The integer height /// </param> /// <param name="bandType">The ImageBandType that clarifies how the separate bands are layered in the image.</param> public override IImageData Create(string fileName, int width, int height, ImageBandType bandType) { Filename = fileName; WorldFile = new WorldFile(); double[] aff = new[] { 1.0, 0, 0, -1.0, 0, height }; Bounds = new RasterBounds(height, width, aff); WorldFile.Filename = WorldFile.GenerateFilename(fileName); Width = width; Height = height; _myImage = new Bitmap(width, height); string ext = Path.GetExtension(fileName); switch (ext) { case ".bmp": _myImage.Save(fileName, ImageFormat.Bmp); break; case ".emf": _myImage.Save(fileName, ImageFormat.Emf); break; case ".exf": _myImage.Save(fileName, ImageFormat.Exif); break; case ".gif": _myImage.Save(fileName, ImageFormat.Gif); break; case ".ico": _myImage.Save(fileName, ImageFormat.Icon); break; case ".jpg": _myImage.Save(fileName, ImageFormat.Jpeg); break; case ".mbp": _myImage.Save(fileName, ImageFormat.MemoryBmp); break; case ".png": _myImage.Save(fileName, ImageFormat.Png); break; case ".tif": _myImage.Save(fileName, ImageFormat.Tiff); break; case ".wmf": _myImage.Save(fileName, ImageFormat.Wmf); break; } NumBands = 4; BytesPerPixel = 4; CopyBitmapToValues(); return(this); }
/// <summary> /// Creates a new instance of ImageData /// </summary> public ImageData() { TypeName = "Image"; WorldFile = new WorldFile(); }
/// <summary> /// Creates a new image and world file, placing the default bounds at the origin, with one pixel per unit. /// </summary> /// <param name="fileName"> The string fileName </param> /// <param name="width"> The integer width </param> /// <param name="height"> The integer height </param> /// <param name="bandType">The ImageBandType that clarifies how the separate bands are layered in the image.</param> public override IImageData Create(string fileName, int width, int height, ImageBandType bandType) { Filename = fileName; WorldFile = new WorldFile(); double[] aff = { 1.0, 0, 0, -1.0, 0, height }; Bounds = new RasterBounds(height, width, aff); WorldFile.Filename = WorldFile.GenerateFilename(fileName); Width = width; Height = height; _myImage = new Bitmap(width, height); string ext = Path.GetExtension(fileName); ImageFormat imageFormat; switch (ext) { case ".bmp": imageFormat = ImageFormat.Bmp; break; case ".emf": imageFormat = ImageFormat.Emf; break; case ".exf": imageFormat = ImageFormat.Exif; break; case ".gif": imageFormat = ImageFormat.Gif; break; case ".ico": imageFormat = ImageFormat.Icon; break; case ".jpg": imageFormat = ImageFormat.Jpeg; break; case ".mbp": imageFormat = ImageFormat.MemoryBmp; break; case ".png": imageFormat = ImageFormat.Png; break; case ".tif": imageFormat = ImageFormat.Tiff; break; case ".wmf": imageFormat = ImageFormat.Wmf; break; default: throw new ArgumentOutOfRangeException("fileName", "File format is unsupported."); } _myImage.Save(fileName, imageFormat); NumBands = 4; BytesPerPixel = 4; CopyBitmapToValues(); return(this); }
/// <summary> /// Creates a new instance of ImageData /// </summary> public ImageData() { WorldFile = new WorldFile(); }