/// <summary> /// Creates a deep clone of the given image and returns it with inverted color. The original image is left untouched. /// </summary> /// <param name="srcImg">The image to invert clone.</param> /// <returns>an inverted <see cref="System.Drawing.Imaging.PixelFormat.Format32bppArgb"/> clone of the given image.</returns> public static Bitmap GetInvertedBitmap(Image srcImg) { Bitmap newBitmap = ImageProcessor.DeepClone(srcImg, PixelFormat.Format32bppArgb); InvertBitmapSafe(newBitmap); return(newBitmap); }
/// <summary> /// Initializes a new instance of the <see cref="GifFrame"/> class. /// </summary> /// <param name="source">The source image to copy into the new frame.</param> /// <param name="delay">The time, in milliseconds, to wait before animating to the next frame.</param> /// <param name="x">The frame left position.</param> /// <param name="y">The frame top position.</param> public GifFrame(Image source, TimeSpan delay, int x, int y) { this.Image = ImageProcessor.DeepClone(source, PixelFormat.Format32bppArgb, false); // DO NOT PRESERVE META OR ELSE GIF CANNOT BE ENCODED this.Delay = delay; this.X = x; this.Y = y; }
/// <summary> /// Saves an image to the given stream. /// <para>Can throw just about any exception and should be used in a try catch</para> /// </summary> /// <param name="stream">The stream to save.</param> /// <param name="image">The image to save.</param> /// <param name="bitDepth">The bit depth of the Tiff.</param> /// <exception cref="Exception"></exception> public void Save(Stream stream, Image image, BitDepth bitDepth) { // Tiffs can be saved with different bit depths but throws if we use 16 bits. if (bitDepth == BitDepth.Bit16) { bitDepth = BitDepth.Bit24; } using (EncoderParameters encoderParameters = GetEncoderParameters(bitDepth)) { switch (bitDepth) { case BitDepth.Bit4: case BitDepth.Bit8: // Save as 8 bit quantized image. //using (Bitmap quantized = this.Quantizer.Quantize(image)) //{ //.CopyMetadata(image, quantized); //quantized.Save(stream, this.GetCodecInfo(), encoderParameters); image.Save(stream, TIFF.imageCodecInfo, encoderParameters); //} return; case BitDepth.Bit24: case BitDepth.Bit32: PixelFormat pixelFormat = ImageHelper.GetPixelFormatForBitDepth(bitDepth); if (pixelFormat != image.PixelFormat) { using (Image copy = ImageProcessor.DeepClone(image, pixelFormat, true)) { copy.Save(stream, TIFF.imageCodecInfo, encoderParameters); } } else { image.Save(stream, TIFF.imageCodecInfo, encoderParameters); } break; default: // Encoding is handled by the encoding parameters. image.Save(stream, TIFF.imageCodecInfo, encoderParameters); break; } } }
/// <summary> /// Makes a copy of the image and returns a <see cref="Bitmap"/>. /// </summary> /// <returns>A <see cref="Bitmap"/> copy of the image.</returns> public virtual Bitmap DeepClone() { if (this.Image == null) { return(null); } Bitmap copy = ImageProcessor.DeepClone(this.Image, this.Image.PixelFormat, true); /*if (ImageHelper.IsIndexed(targetFormat)) * { * Bitmap quantized = this.Quantizer.Quantize(copy); * copy.Dispose(); * copy = quantized; * }*/ return(copy); }
public static Bitmap Copy(this Image image) { return(ImageProcessor.DeepClone(image, PixelFormat.Format32bppArgb)); }