ImageSave Method |
Namespace: Aspose.Imaging
[C#] string dir = "c:\\temp\\"; using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(dir + "sample.bmp")) { Aspose.Imaging.FileFormats.Bmp.BmpImage bmpImage = (Aspose.Imaging.FileFormats.Bmp.BmpImage)image; // Convert to a black-white image bmpImage.BinarizeOtsu(); // Save to the same location with default options. image.Save(); Aspose.Imaging.ImageOptions.BmpOptions saveOptions = new Aspose.Imaging.ImageOptions.BmpOptions(); // A palette contains only two colors: Black and White in this case. saveOptions.Palette = Aspose.Imaging.ColorPaletteHelper.CreateMonochrome(); // For all monochrome images (including black-white ones) it is enough to allocate 1 bit per pixel. saveOptions.BitsPerPixel = 1; // Save to another location with the specified options. image.Save(dir + "sample.bw.palettized.bmp", saveOptions); // Save only the central part of the image. Aspose.Imaging.Rectangle bounds = new Aspose.Imaging.Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); image.Save(dir + "sample.bw.palettized.part.bmp", saveOptions, bounds); // Save the entire image to a memory stream using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { image.Save(stream, saveOptions); System.Console.WriteLine("The size of the whole image in bytes: {0}", stream.Length); } // Save the central part of the image to a memory stream using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { image.Save(stream, saveOptions, bounds); System.Console.WriteLine("The size of the central part of the image in bytes: {0}", stream.Length); } } //The output may look like this: //The size of the whole image in bytes: 24062 //The size of the central part of the image in bytes: 6046