public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:BinarizationWithOtsuThreshold String sourceFile = dataDir + @"sample.psd"; string destName = dataDir + @"BinarizationWithOtsuThreshold_out.jpg"; // Load an image using (Image image = Image.Load(sourceFile)) { // Cast the image to RasterCachedImage and Check if image is cached RasterCachedImage rasterCachedImage = (RasterCachedImage)image; if (!rasterCachedImage.IsCached) { // Cache image if not already cached rasterCachedImage.CacheData(); } // Binarize image with Otsu Thresholding and Save the resultant image rasterCachedImage.BinarizeOtsu(); rasterCachedImage.Save(destName, new JpegOptions()); } //ExEnd:BinarizationWithOtsuThreshold }
public static void Run() { // To get proper output please apply a valid Aspose.Imaging License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); // ExStart:BinarizationWithOtsuThreshold // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an image in an instance of Image using (Image image = Image.Load(dataDir + "aspose-logo.jpg")) { // Cast the image to RasterCachedImage RasterCachedImage rasterCachedImage = (RasterCachedImage)image; // Check if image is cached if (!rasterCachedImage.IsCached) { // Cache image if not already cached rasterCachedImage.CacheData(); } // Binarize image with Otsu Thresholding rasterCachedImage.BinarizeOtsu(); // Save the resultant image rasterCachedImage.Save(dataDir + "BinarizationWithOtsuThreshold_out.jpg"); } // ExEnd:BinarizationWithOtsuThreshold }
public static void Run() { // To get proper output please apply a valid Aspose.Imaging License. You can purchase full license or get 30 day temporary license from http:// Www.aspose.com/purchase/default.aspx."); //ExStart:Grayscaling // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an image in an instance of Image using (Image image = Image.Load(dataDir + "aspose-logo.jpg")) { // Cast the image to RasterCachedImage and Check if image is cached RasterCachedImage rasterCachedImage = (RasterCachedImage)image; if (!rasterCachedImage.IsCached) { // Cache image if not already cached rasterCachedImage.CacheData(); } // Transform image to its grayscale representation and Save the resultant image rasterCachedImage.Grayscale(); rasterCachedImage.Save(dataDir + "Grayscaling_out.jpg"); } //ExEnd:Grayscaling }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); string outputFolder = RunExamples.GetDataDir_Output(); //ExStart:Saving16BitGrayscalePsdTo8BitRgb //The following example demonstrates that reading and saving the Grayscale 16 bit PSD files to 16bit per channel RGB works correctly and without an exception. string sourceFilePath = Path.Combine(dataDir, "grayscale5x5.psd"); string exportFilePath = Path.Combine(outputFolder, "rgb16bit5x5.psd"); PsdOptions psdOptions = new PsdOptions() { ColorMode = ColorModes.Rgb, ChannelBitsCount = 16, ChannelsCount = 4 }; using (PsdImage image = (PsdImage)Image.Load(sourceFilePath)) { RasterCachedImage raster = image.Layers[0]; Graphics graphics = new Graphics(raster); int width = raster.Width; int height = raster.Height; Rectangle rect = new Rectangle(width / 3, height / 3, width - (2 * (width / 3)) - 1, height - (2 * (height / 3)) - 1); graphics.DrawRectangle(new Pen(Color.DarkGray, 1), rect); image.Save(exportFilePath, psdOptions); } string pngExportPath = Path.ChangeExtension(exportFilePath, "png"); using (PsdImage image = (PsdImage)Image.Load(exportFilePath)) { // Here should be no exception. image.Save(pngExportPath, new PngOptions() { ColorType = PngColorType.GrayscaleWithAlpha }); } //ExEnd:Saving16BitGrayscalePsdTo8BitRgb Console.WriteLine("Saving16BitGrayscalePsdTo8BitRgb executed successfully"); }
public static void Run() { //ExStart:BinarizationWithFixedThreshold // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an image in an instance of Image using (Image image = Image.Load(dataDir + "aspose-logo.jpg")) { // Cast the image to RasterCachedImage and Check if image is cached RasterCachedImage rasterCachedImage = (RasterCachedImage)image; if (!rasterCachedImage.IsCached) { // Cache image if not already cached rasterCachedImage.CacheData(); } // Binarize image with predefined fixed threshold and Save the resultant image rasterCachedImage.BinarizeFixed(100); rasterCachedImage.Save(dataDir + "BinarizationWithFixedThreshold_out.jpg"); } //ExEnd:BinarizationWithFixedThreshold }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:AdjustingBrightness string sourceFile = dataDir + @"sample.psd"; string destName = dataDir + @"AdjustBrightness_out.tiff"; using (var image = (PsdImage)Image.Load(sourceFile)) { RasterCachedImage rasterImage = image; // Set the brightness value. The accepted values of brightness are in the range [-255, 255]. rasterImage.AdjustBrightness(-50); TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.Default); rasterImage.Save(destName, tiffOptions); } //ExEnd:AdjustingBrightness }
public static void Run() { string baseFolder = RunExamples.GetDataDir_PSD(); string output = RunExamples.GetDataDir_Output(); //ExStart:SupportOfCMYKColorMode16bit //ExSummary:The following code demonstrates the support of the CMYK ColorMode 16 bit and the ability to drawing by using Aspose.PSD.Graphics class. using (PsdImage image = (PsdImage)Image.Load(baseFolder + "cub16bit_cmyk.psd")) { RasterCachedImage raster = image.Layers[0]; Graphics graphics = new Graphics(raster); int width = raster.Width; int height = raster.Height; Rectangle rect = new Rectangle(width / 3, height / 3, width - (2 * (width / 3)) - 1, height - (2 * (height / 3)) - 1); graphics.DrawRectangle(new Pen(Color.DarkGray, 1), rect); image.Save(output + "output.psd"); image.Save(output + "output.png", new PngOptions()); } //ExEnd:SupportOfCMYKColorMode16bit Console.WriteLine("SupportOfCMYKColorMode16bit executed successfully"); }
public static void Run() { Console.WriteLine("Running example BinarizationWithOtsuThreshold"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an image in an instance of Image using (Image image = Image.Load(dataDir + "aspose-logo.jpg")) { // Cast the image to RasterCachedImage and Check if image is cached RasterCachedImage rasterCachedImage = (RasterCachedImage)image; if (!rasterCachedImage.IsCached) { // Cache image if not already cached rasterCachedImage.CacheData(); } // Binarize image with Otsu Thresholding and Save the resultant image rasterCachedImage.BinarizeOtsu(); rasterCachedImage.Save(dataDir + "BinarizationWithOtsuThreshold_out.jpg"); } Console.WriteLine("Finished example BinarizationWithOtsuThreshold"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); string outputFolder = RunExamples.GetDataDir_Output(); //ExStart:Saving16BitGrayscalePsdImage Stack <string> outputFilePathStack = new Stack <string>(); //The following example demonstrates that reading and saving the Grayscale 16 bit PSD files works correctly and without an exception. void SaveToPsdThenLoadAndSaveToPng( string file, ColorModes colorMode, short channelBitsCount, short channelsCount, CompressionMethod compression, int layerNumber) { string filePath = Path.Combine(dataDir, file + ".psd"); string postfix = colorMode.ToString() + channelBitsCount + "_" + channelsCount + "_" + compression; string exportPath = Path.Combine(outputFolder, file + postfix + ".psd"); PsdOptions psdOptions = new PsdOptions() { ColorMode = colorMode, ChannelBitsCount = channelBitsCount, ChannelsCount = channelsCount, CompressionMethod = compression }; using (PsdImage image = (PsdImage)Image.Load(filePath)) { RasterCachedImage raster = layerNumber >= 0 ? (RasterCachedImage)image.Layers[layerNumber] : image; Graphics graphics = new Graphics(raster); int width = raster.Width; int height = raster.Height; Rectangle rect = new Rectangle( width / 3, height / 3, width - (2 * (width / 3)) - 1, height - (2 * (height / 3)) - 1); graphics.DrawRectangle(new Pen(Color.DarkGray, 1), rect); image.Save(exportPath, psdOptions); } string pngExportPath = Path.ChangeExtension(exportPath, "png"); using (PsdImage image = (PsdImage)Image.Load(exportPath)) { // Here should be no exception. image.Save(pngExportPath, new PngOptions() { ColorType = PngColorType.GrayscaleWithAlpha }); } outputFilePathStack.Push(exportPath); } SaveToPsdThenLoadAndSaveToPng("grayscale5x5", ColorModes.Cmyk, 16, 5, CompressionMethod.RLE, 0); SaveToPsdThenLoadAndSaveToPng("argb16bit_5x5", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, 0); SaveToPsdThenLoadAndSaveToPng("argb16bit_5x5_no_layers", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, -1); SaveToPsdThenLoadAndSaveToPng("argb8bit_5x5", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, 0); SaveToPsdThenLoadAndSaveToPng("argb8bit_5x5_no_layers", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, -1); SaveToPsdThenLoadAndSaveToPng("cmyk16bit_5x5_no_layers", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, -1); SaveToPsdThenLoadAndSaveToPng("index8bit_5x5", ColorModes.Grayscale, 16, 2, CompressionMethod.RLE, -1); //ExEnd:Saving16BitGrayscalePsdImage Console.WriteLine("Saving16BitGrayscalePsdImage executed successfully"); }
public static void Run() { string baseFolder = RunExamples.GetDataDir_PSD(); string output = RunExamples.GetDataDir_Output(); //ExStart:ConversionPSDToGrayscaleRgbCmyk //ExSummary:These examples demonstrate conversion of the PSD image format to other Color Modes/BitDepth. string dataDir = baseFolder; string outputDir = output; // These examples demonstrate conversion of the PSD image format to other Color Modes/BitDepth. ImageConversion(ColorModes.Grayscale, 16, 2); ImageConversion(ColorModes.Grayscale, 8, 2); ImageConversion(ColorModes.Grayscale, 8, 1); ImageConversion(ColorModes.Rgb, 8, 4); ImageConversion(ColorModes.Rgb, 16, 4); ImageConversion(ColorModes.Cmyk, 8, 5); ImageConversion(ColorModes.Cmyk, 16, 5); void ImageConversion(ColorModes colorMode, short channelBitsCount, short channelsCount) { var compression = channelBitsCount > 8 ? CompressionMethod.Raw : CompressionMethod.RLE; SaveToPsdThenLoadAndSaveToPng( "SheetColorHighlightExample", colorMode, channelBitsCount, channelsCount, compression, 1); SaveToPsdThenLoadAndSaveToPng( "FillOpacitySample", colorMode, channelBitsCount, channelsCount, compression, 2); SaveToPsdThenLoadAndSaveToPng( "ClippingMaskRegular", colorMode, channelBitsCount, channelsCount, compression, 3); } // Saves to PSD then loads the saved file and saves to PNG. void SaveToPsdThenLoadAndSaveToPng( string file, ColorModes colorMode, short channelBitsCount, short channelsCount, CompressionMethod compression, int layerNumber) { string srcFile = dataDir + file + ".psd"; string postfix = colorMode.ToString() + channelBitsCount + "bits" + channelsCount + "channels" + compression; string fileName = file + "_" + postfix + ".psd"; string exportPath = outputDir + fileName; PsdOptions psdOptions = new PsdOptions() { ColorMode = colorMode, ChannelBitsCount = channelBitsCount, ChannelsCount = channelsCount, CompressionMethod = compression }; using (var image = (PsdImage)Image.Load(srcFile)) { image.Convert(psdOptions); RasterCachedImage raster = image.Layers.Length > 0 && layerNumber >= 0 ? (RasterCachedImage)image.Layers[layerNumber] : image; Graphics graphics = new Graphics(raster); int width = raster.Width; int height = raster.Height; Rectangle rect = new Rectangle( width / 3, height / 3, width - (2 * (width / 3)) - 1, height - (2 * (height / 3)) - 1); graphics.DrawRectangle(new Pen(Color.DarkGray, 1), rect); image.Save(exportPath); } string pngExportPath = Path.ChangeExtension(exportPath, "png"); using (PsdImage image = (PsdImage)Image.Load(exportPath)) { image.Save(pngExportPath, new PngOptions() { ColorType = PngColorType.TruecolorWithAlpha }); } } //ExEnd:ConversionPSDToGrayscaleRgbCmyk Console.WriteLine("ConversionPSDToGrayscaleRgbCmyk executed successfully"); }