public static void Run() { // ExStart:SupportForCMYKAndYCCKColorModesInJPEGLossless // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); MemoryStream jpegStream = new MemoryStream(); try { // Save to JPEG Lossless CMYK using (JpegImage image = (JpegImage)Image.Load("056.jpg")) { JpegOptions options = new JpegOptions(); options.ColorType = JpegCompressionColorMode.Cmyk; options.CompressionType = JpegCompressionMode.Lossless; // The default profiles will be used. options.RgbColorProfile = null; options.CmykColorProfile = null; image.Save(jpegStream, options); } // Load from JPEG Lossless CMYK jpegStream.Position = 0; using (JpegImage image = (JpegImage)Image.Load(jpegStream)) { image.Save("056_cmyk.png", new PngOptions()); } } finally { jpegStream.Dispose(); } }
public async Task ProcessFilesAsync(IEnumerable <int> previewDelta, Func <Stream, string, Task> pagePreviewCallback, CancellationToken token) { var jpgCreateOptions = new JpegOptions(); var diff = Enumerable.Range(0, _image.Frames.Length); diff = diff.Except(previewDelta); var t = new List <Task>(); foreach (var item in diff) { if (token.IsCancellationRequested) { break; } _image.ActiveFrame = _image.Frames[item];// tiffFrame; var pixels = _image.LoadPixels(_image.Bounds); //bmpCreateOptions as FileCreateSource saved var ms = new MemoryStream(); jpgCreateOptions.Source = new StreamSource(ms); using (var jpgImage = (JpegImage)Image.Create(jpgCreateOptions, _image.Width, _image.Height)) { //TiffFrame jpgImage.SavePixels(_image.Bounds, pixels); jpgImage.Save(); } var task = pagePreviewCallback(ms, $"{item}.jpg").ContinueWith(_ => ms.Dispose(), token); t.Add(task); } await Task.WhenAll(t); }
public static void Run() { //ExStart:SupportOfLayers // The path to the documents directory. string MyDir = RunExamples.GetDataDir_DXFDrawings(); string sourceFilePath = MyDir + "for_layers_test.dwf"; using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(sourceFilePath)) { // Create an instance of CadRasterizationOptions and set its various properties Aspose.CAD.ImageOptions.CadRasterizationOptions rasterizationOptions = new Aspose.CAD.ImageOptions.CadRasterizationOptions(); rasterizationOptions.PageWidth = 1600; rasterizationOptions.PageHeight = 1600; // Add desired layers rasterizationOptions.Layers = new string[] { "LayerA" }; rasterizationOptions.CenterDrawing = true; JpegOptions jpegOptions = new JpegOptions(); jpegOptions.VectorRasterizationOptions = rasterizationOptions; MyDir = MyDir + "for_layers_test.jpg"; // Export the DXF to JPG image.Save(MyDir, jpegOptions); } //ExEnd:SupportOfLayers }
public static void Run() { // ExStart:SupportForJPEG-LSFormat // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); string sourceJpegFileName = @"c:\aspose.work\lena24b.jls"; string outputPngFileName = @"c:\aspose.work\\lena24b.png"; string outputPngRectFileName = @"c:\aspose.work\\lena24b_rect.png"; // Decoding using (JpegImage jpegImage = (JpegImage)Image.Load(sourceJpegFileName)) { JpegOptions jpegOptions = jpegImage.JpegOptions; // You can read new options: System.Console.WriteLine("Compression type: {0}", jpegOptions.CompressionType); System.Console.WriteLine("Allowed lossy error (NEAR): {0}", jpegOptions.JpegLsAllowedLossyError); System.Console.WriteLine("Interleaved mode (ILV): {0}", jpegOptions.JpegLsInterleaveMode); System.Console.WriteLine("Horizontal sampling: {0}", ArrayToString(jpegOptions.HorizontalSampling)); System.Console.WriteLine("Vertical sampling: {0}", ArrayToString(jpegOptions.VerticalSampling)); // Save the original JPEG-LS image to PNG. jpegImage.Save(outputPngFileName, new PngOptions()); // Save the bottom-right quarter of the original JPEG-LS to PNG Rectangle quarter = new Rectangle(jpegImage.Width / 2, jpegImage.Height / 2, jpegImage.Width / 2, jpegImage.Height / 2); jpegImage.Save(outputPngRectFileName, new PngOptions(), quarter); } }
public static void Run() { Console.WriteLine("Running example CombineImages"); // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages(); // Create an instance of JpegOptions and set its various properties JpegOptions imageOptions = new JpegOptions(); // Create an instance of FileCreateSource and assign it to Source property imageOptions.Source = new FileCreateSource(dataDir + "Two_images_result_out.bmp", false); // Create an instance of Image and define canvas size using (var image = Image.Create(imageOptions, 600, 600)) { // Create and initialize an instance of Graphics, Clear the image surface with white color and Draw Image var graphics = new Graphics(image); graphics.Clear(Color.White); graphics.DrawImage(Image.Load(dataDir + "sample_1.bmp"), 0, 0, 600, 300); graphics.DrawImage(Image.Load(dataDir + "File1.bmp"), 0, 300, 600, 300); image.Save(); } Console.WriteLine("Finished example CombineImages"); }
public static void Run() { // ExStart:SupportForJPEGBITS // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); int bpp = 2; // Set 2 bits per sample to see the difference in size and quality // The origin PNG with 8 bits per sample string originPngFileName = System.IO.Path.Combine(dataDir, "lena_16g_lin.png"); // The output JPEG-LS with 2 bits per sample. string outputJpegFileName = "lena24b " + bpp + "-bit Gold.jls"; using (PngImage pngImage = (PngImage)Image.Load(originPngFileName)) { JpegOptions jpegOptions = new JpegOptions(); jpegOptions.BitsPerChannel = (byte)bpp; jpegOptions.CompressionType = JpegCompressionMode.JpegLs; pngImage.Save(outputJpegFileName, jpegOptions); } // The output PNG is produced from JPEG-LS to check image visually. string outputPngFileName = "lena24b " + bpp + "-bit Gold.png"; using (JpegImage jpegImage = (JpegImage)Image.Load(outputJpegFileName)) { jpegImage.Save(outputPngFileName, new PngOptions()); } }
public static void Run() { //ExStart:AIToJPG // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AI(); string[] sourcesFiles = new string[] { @"34992OStroke", @"rect2_color", }; for (int i = 0; i < sourcesFiles.Length; i++) { string name = sourcesFiles[i]; string sourceFileName = dataDir + name + ".ai"; string outFileName = dataDir + name + ".jpg"; using (AiImage image = (AiImage)Image.Load(sourceFileName)) { ImageOptionsBase options = new JpegOptions() { Quality = 85 }; image.Save(outFileName, options); } } //ExEnd:AIToJPG }
public static void Run() { // ExStart:MergePSDlayers // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); string sourceFileName = dataDir + "samplePsd.psd"; // Load an existing PSD file as image using (Image image = Image.Load(sourceFileName)) { // Convert the loaded image to PSDImage var psdImage = (PsdImage)image; // create a JPG file stream using (Stream stream = File.Create(sourceFileName.Replace("psd", "jpg"))) { // Create JPEG option class object var jpgOptions = new JpegOptions(); // Set the source property to jpg file stream. jpgOptions.Source = new StreamSource(stream); // call the Save the method of PSDImage class to merge the layers and save it as jpg image. psdImage.Save(stream, jpgOptions); } } // ExEnd:MergePSDlayers }
public static void Run() { //ExStart:FreePointOfView // The path to the documents directory. string MyDir = RunExamples.GetDataDir_ConvertingCAD(); string sourceFilePath = MyDir + "conic_pyramid.dxf"; var outPath = Path.Combine(MyDir, "FreePointOfView_out.jpg"); using (CadImage cadImage = (CadImage)Image.Load(sourceFilePath)) { JpegOptions options = new JpegOptions { VectorRasterizationOptions = new CadRasterizationOptions { PageWidth = 1500, PageHeight = 1500 } }; float xAngle = 10; //Angle of rotation along the X axis float yAngle = 30; //Angle of rotation along the Y axis float zAngle = 40; //Angle of rotation along the Z axis ((CadRasterizationOptions)(options.VectorRasterizationOptions)).ObserverPoint = new ObserverPoint(xAngle, yAngle, zAngle); cadImage.Save(outPath, options); } //ExEnd:FreePointOfView Console.WriteLine("\n3D images exported successfully to JPEG.\nFile saved at " + outPath); }
public static void Run() { //ExStart:SupportFor2_7BitsJPEG // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load PSD image. using (PsdImage image = (PsdImage)Image.Load(dataDir + "PsdImage.psd")) { JpegOptions options = new JpegOptions(); // Set 2 bits per sample to see the difference in size and quality byte bpp = 2; //Just replace one line given below in examples to use YCCK instead of CMYK //options.ColorType = JpegCompressionColorMode.Cmyk; options.ColorType = JpegCompressionColorMode.Cmyk; options.CompressionType = JpegCompressionMode.JpegLs; options.BitsPerChannel = bpp; // The default profiles will be used. options.RgbColorProfile = null; options.CmykColorProfile = null; image.Save(dataDir + "2_7BitsJPEG_output.jpg", options); } //ExEnd:SupportFor2_7BitsJPEG }
public override byte[] Decode(Bytes.Buffer data, PdfDirectObject parameters, IDictionary <PdfName, PdfDirectObject> header) { var imageParams = header; var dictHeight = ((IPdfNumber)(header[PdfName.Height] ?? header[PdfName.H])).IntValue; var dictWidth = ((IPdfNumber)(header[PdfName.Width] ?? header[PdfName.W])).IntValue; var bitsPerComponent = ((IPdfNumber)imageParams[PdfName.BitsPerComponent])?.IntValue ?? 8; var flag = imageParams[PdfName.ImageMask] as PdfBoolean; var jpegOptions = new JpegOptions(decodeTransform: null, colorTransform: null); // Checking if values need to be transformed before conversion. var decodeObj = imageParams[PdfName.Decode] ?? imageParams[PdfName.D]; var decodeArr = decodeObj?.Resolve() as PdfArray; if (false && decodeArr != null) { var decode = decodeArr.Select(p => ((IPdfNumber)p).IntValue).ToArray(); var decodeArrLength = decodeArr.Count; var transform = new int[decodeArr.Count]; var transformNeeded = false; var maxValue = (1 << bitsPerComponent) - 1; for (var i = 0; i < decodeArrLength; i += 2) { transform[i] = ((decode[i + 1] - decode[i]) * 256) | 0; transform[i + 1] = (decode[i] * maxValue) | 0; if (transform[i] != 256 || transform[i + 1] != 0) { transformNeeded = true; } } if (transformNeeded) { jpegOptions.DecodeTransform = transform; } } // Fetching the 'ColorTransform' entry, if it exists. if (parameters is PdfDictionary paramDict) { var colorTransform = paramDict[PdfName.ColorTransform]; if (colorTransform is IPdfNumber number) { jpegOptions.ColorTransform = number.IntValue; } } var jpegImage = new JpegImage(jpegOptions); jpegImage.Parse(data.GetBuffer()); var buffer = jpegImage.GetData(width: dictWidth, height: dictHeight, forceRGB: false, isSourcePDF: true); return(buffer); }
//ExStart:PLTSupport public static void Run() { string MyDir = RunExamples.GetDataDir_ConvertingCAD(); string sourceFilePath = MyDir + "themepark.plt"; Image image = Image.Load((sourceFilePath)); ImageOptionsBase imageOptions = new JpegOptions(); CadRasterizationOptions options = new CadRasterizationOptions { PageHeight = 500, PageWidth = 1000, }; imageOptions.VectorRasterizationOptions = options; image.Save((MyDir + "themepark.jpg"), imageOptions); }
public static void Run() { //ExStart:GetSizeOfDwfLayout // The path to the documents directory. string MyDir = RunExamples.GetDataDir_DWFDrawings(); string sourceFilePath = MyDir + "blocks_and_tables.dwf"; string extension = Path.GetExtension(sourceFilePath); using (DwfImage image = (DwfImage)Aspose.CAD.Image.Load(sourceFilePath)) { foreach (var page in image.Pages) { var layout = page.Name; System.Console.WriteLine("Layout= " + layout); using (FileStream fs = new FileStream(MyDir + "layout_" + layout + ".jpg", FileMode.Create)) { JpegOptions jpegOptions = new JpegOptions(); CadRasterizationOptions options = new CadRasterizationOptions(); options.Layouts = new string[] { layout }; double sizeExtX = page.MaxPoint.X - page.MinPoint.X; double sizeExtY = page.MaxPoint.Y - page.MinPoint.Y; if (page.UnitType == UnitType.Inch) { options.PageHeight = CommonHelper.INtoPixels(sizeExtY, CommonHelper.DPI); options.PageWidth = CommonHelper.INtoPixels(sizeExtX, CommonHelper.DPI); } else if (page.UnitType == UnitType.Millimeter) { options.PageHeight = CommonHelper.MMtoPixels(sizeExtY, CommonHelper.DPI); options.PageWidth = CommonHelper.MMtoPixels(sizeExtX, CommonHelper.DPI); } else { options.PageHeight = (float)sizeExtY; options.PageWidth = (float)sizeExtX; } //options.CenterDrawing = true; jpegOptions.VectorRasterizationOptions = options; image.Save(fs, jpegOptions); } } } //ExEnd:GetSizeOfDwfLayout }
public static void Run() { //ExStart:MergePSDlayers // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load a PSD file as an image and cast it into PsdImage using (PsdImage psdImage = (PsdImage)Image.Load(dataDir + "layers.psd")) { // Create JPEG option class object, Set its properties and save image var jpgOptions = new JpegOptions(); psdImage.Save(dataDir + "MergePSDlayers_output.jpg", jpgOptions); } //ExEnd:MergePSDlayers }
public static void Run() { // ExStart:SupportForCMYKAndYCCKColorModesInJPEGLosslessUsingRGBProfile // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); MemoryStream jpegStream = new MemoryStream(); FileStream rgbProfileStream = new FileStream("eciRGB_v2.icc", FileMode.Open); FileStream cmykProfileStream = new FileStream("ISOcoated_v2_FullGamut4.icc", FileMode.Open); Sources.StreamSource rgbColorProfile = new Sources.StreamSource(rgbProfileStream); Sources.StreamSource cmykColorProfile = new Sources.StreamSource(cmykProfileStream); try { // Save to JPEG Lossless CMYK using (JpegImage image = (JpegImage)Image.Load("056.jpg")) { JpegOptions options = new JpegOptions(); options.ColorType = JpegCompressionColorMode.Cmyk; options.CompressionType = JpegCompressionMode.Lossless; // The custom profiles will be used. options.RgbColorProfile = rgbColorProfile; options.CmykColorProfile = cmykColorProfile; image.Save(jpegStream, options); } // Load from JPEG Lossless CMYK jpegStream.Position = 0; rgbProfileStream.Position = 0; cmykProfileStream.Position = 0; using (JpegImage image = (JpegImage)Image.Load(jpegStream)) { image.RgbColorProfile = rgbColorProfile; image.CmykColorProfile = cmykColorProfile; image.Save("056_cmyk_custom_profiles.png", new PngOptions()); } } finally { jpegStream.Dispose(); rgbProfileStream.Dispose(); cmykProfileStream.Dispose(); } // ExEnd:SupportForCMYKAndYCCKColorModesInJPEGLosslessUsingRGBProfile }
public static void Run() { //ExStart:RenderDXFAsPDF // The path to the documents directory. string MyDir = RunExamples.GetDataDir_DXFDrawings(); string sourceFilePath = MyDir + "conic_pyramid.dxf"; using (CadImage image = (CadImage)Image.Load(fileName); { ImageOptionsBase options = new JpegOptions(); options.VectorRasterizationOptions = new CadRasterizationOptions() {PdfProductLocation = "C:\PDF" /*path to pdf product and licence*/ }; options.VectorRasterizationOptions.PageHeight = 1000; options.VectorRasterizationOptions.PageWidth = 1000; image.Save(outPath, options); } } //ExEnd:RenderDXFAsPDF }
public static void Run() { //ExStart:ColorTypeAndCompressionType // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); using (var original = Image.Load(dataDir + "ColorGif.gif")) { var jpegOptions = new JpegOptions() { ColorType = JpegCompressionColorMode.Grayscale, CompressionType = JpegCompressionMode.Progressive, }; original.Save("D:/temp/result.jpg", jpegOptions); } //ExEnd:ColorTypeAndCompressionType }
public static void Run() { //ExStart:ColorTypeAndCompressionType // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); // Load PSD image. using (PsdImage image = (PsdImage)Image.Load(dataDir + "PsdImage.psd")) { JpegOptions options = new JpegOptions(); options.ColorType = JpegCompressionColorMode.Grayscale; options.CompressionType = JpegCompressionMode.Progressive; image.Save(dataDir + "ColorTypeAndCompressionType_output.jpg", options); } //ExEnd:ColorTypeAndCompressionType }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:PSDToRasterImageFormats String srcPath = dataDir + @"sample.psd"; string destName = dataDir + @"export"; // Load an existing PSD image as Image using (Image image = Image.Load(srcPath)) { // Create an instance of PngOptions class PngOptions pngOptions = new PngOptions(); // Create an instance of BmpOptions class BmpOptions bmpOptions = new BmpOptions(); // Create an instance of TiffOptions class TiffOptions tiffOptions = new TiffOptions(FileFormats.Tiff.Enums.TiffExpectedFormat.Default); // Create an instance of GifOptions class GifOptions gifOptions = new GifOptions(); // Create an instance of JpegOptions class JpegOptions jpegOptions = new JpegOptions(); // Create an instance of Jpeg2000Options class Jpeg2000Options jpeg2000Options = new Jpeg2000Options(); // Call the save method, provide output path and export options to convert PSD file to various raster file formats. image.Save(destName + ".png", pngOptions); image.Save(destName + ".bmp", bmpOptions); image.Save(destName + ".tiff", tiffOptions); image.Save(destName + ".gif", gifOptions); image.Save(destName + ".jpeg", jpegOptions); image.Save(destName + ".jp2", jpeg2000Options); } //ExEnd:PSDToRasterImageFormats }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); //ExStart:SupportForJPEG_LSWithCMYK // Load PSD image. using (PsdImage image = (PsdImage)Image.Load(dataDir + "PsdImage.psd")) { JpegOptions options = new JpegOptions(); //Just replace one line given below in examples to use YCCK instead of CMYK //options.ColorType = JpegCompressionColorMode.Cmyk; options.ColorType = JpegCompressionColorMode.Cmyk; options.CompressionType = JpegCompressionMode.JpegLs; // The default profiles will be used. options.RgbColorProfile = null; options.CmykColorProfile = null; image.Save(dataDir + "output.jpg", options); } // Load PSD image. using (PsdImage image = (PsdImage)Image.Load(dataDir + "PsdImage.psd")) { JpegOptions options = new JpegOptions(); //Just replace one line given below in examples to use YCCK instead of CMYK //options.ColorType = JpegCompressionColorMode.Cmyk; options.ColorType = JpegCompressionColorMode.Cmyk; options.CompressionType = JpegCompressionMode.Lossless; // The default profiles will be used. options.RgbColorProfile = null; options.CmykColorProfile = null; image.Save(dataDir + "output2.jpg", options); } //ExEnd:SupportForJPEG_LSWithCMYK }
public static void Run() { //ExStart:ExportPLTtoImage // The path to the documents directory. string MyDir = RunExamples.GetDataDir_PLTDrawings(); string sourceFilePath = MyDir + "50states.plt"; using (Image cadImage = Image.Load(sourceFilePath)) { ImageOptionsBase imageOptions = new JpegOptions(); CadRasterizationOptions options = new CadRasterizationOptions { PageHeight = 500, PageWidth = 1000, }; imageOptions.VectorRasterizationOptions = options; cadImage.Save(MyDir + "50states.jpg", imageOptions); } //ExEnd:ExportPLTtoImage }
public static void Run() { //ExStart:ConvertImageWithGrayscale string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); using (var image = Image.Load(dataDir + "aspose-logo.jpg")); JpegCompressionColorMode[] colorTypes = new JpegCompressionColorMode[] { JpegCompressionColorMode.Grayscale, JpegCompressionColorMode.YCbCr, JpegCompressionColorMode.Rgb, JpegCompressionColorMode.Cmyk, JpegCompressionColorMode.Ycck, }; string[] sourceFileNames = new string[] { "Rgb.jpg", "Rgb.jpg", "Rgb.jpg", "Rgb.jpg", "Rgb.jpg", }; JpegOptions options = new JpegOptions(); options.BitsPerChannel = 12; for (int i = 0; i < colorTypes.Length; ++i) { options.ColorType = colorTypes[i]; string fileName = colorTypes[i] + " 12-bit.jpg"; using (Image image = Image.Load(sourceFileNames[i])) { image.Save(fileName, options); } } //ExEnd:ConvertImageWithGrayscale }
public static void Run() { Console.WriteLine("Running example ConvertImageWithGrayscale"); string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); JpegCompressionColorMode[] colorTypes = new JpegCompressionColorMode[] { JpegCompressionColorMode.Grayscale, JpegCompressionColorMode.YCbCr, JpegCompressionColorMode.Rgb, JpegCompressionColorMode.Cmyk, JpegCompressionColorMode.Ycck, }; string[] sourceFileNames = new string[] { "Grayscale.jpg", "Grayscale.jpg", "Grayscale.jpg", "Grayscale.jpg", "Grayscale.jpg", }; JpegOptions options = new JpegOptions(); options.BitsPerChannel = 12; for (int i = 0; i < colorTypes.Length; ++i) { options.ColorType = colorTypes[i]; string fileName = colorTypes[i] + " 12-bit.jpg"; using (Image image = Image.Load(dataDir + sourceFileNames[i])) { image.Save(dataDir + fileName, options); } } Console.WriteLine("Finished example ConvertImageWithGrayscale"); }
///<Summary> /// ConvertCadToImages method to convert cad to images ///</Summary> public Response ConvertCadToImages(string fileName, string folderName, string outputType) { if (outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png") || outputType.Equals("gif") || outputType.Equals("svg")) { ImageOptionsBase imageOptionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { imageOptionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { imageOptionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { imageOptionsBase = new GifOptions(); } else if (outputType.Equals("svg")) { imageOptionsBase = new SvgOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, false, false, delegate(string inFilePath, string outPath, string zipOutFolder) { using (Aspose.CAD.Image image = Aspose.CAD.Image.Load(inFilePath)) { image.Save(outPath, imageOptionsBase); } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }
///<Summary> /// ConvertPSDToImageFiles method to convert psd to image ///</Summary> public Response ConvertPSDToImageFiles(string fileName, string folderName, string outputType) { if (outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png")) { ImageOptionsBase optionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { optionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { optionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { optionsBase = new GifOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, true, false, delegate(string inFilePath, string outPath, string zipOutFolder) { string fileExtension = Path.GetExtension(inFilePath).ToLower(); using (Image image = Image.Load(inFilePath)) { image.Save(outPath, optionsBase); } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }
public static void Run() { // ExStart:SupportForJPEG-LSWithCMYK // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); MemoryStream jpegLsStream = new MemoryStream(); try { // Save to CMYK JPEG-LS using (JpegImage image = (JpegImage)Image.Load("056.jpg")) { JpegOptions options = new JpegOptions(); //Just replace one line given below in examples to use YCCK instead of CMYK //options.ColorType = JpegCompressionColorMode.Cmyk; options.ColorType = JpegCompressionColorMode.Cmyk; options.CompressionType = JpegCompressionMode.JpegLs; // The default profiles will be used. options.RgbColorProfile = null; options.CmykColorProfile = null; image.Save(jpegLsStream, options); } // Load from CMYK JPEG-LS jpegLsStream.Position = 0; using (JpegImage image = (JpegImage)Image.Load(jpegLsStream)) { image.Save("056_cmyk.png", new PngOptions()); } } finally { jpegLsStream.Dispose(); } }
public static void Run() { // ExStart:MergePSDlayers // The path to the documents directory. string dataDir = RunExamples.GetDataDir_PSD(); string sourceFileName = dataDir + "PsdImage.psd"; // Load an existing PSD file as image using (Image image = Image.Load(sourceFileName)) { // Convert the loaded image to PSDImage var psdImage = (PsdImage)image; // Create a JPG file stream using (Stream stream = File.Create(sourceFileName.Replace("psd", "jpg"))) { // Create JPEG option class object, Set the source property to jpg file stream and save image var jpgOptions = new JpegOptions(); jpgOptions.Source = new StreamSource(stream); psdImage.Save(stream, jpgOptions); } } // ExEnd:MergePSDlayers }
public static void Run() { // ExStart:CombineImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages(); // Create an instance of JpegOptions and set its various properties JpegOptions imageOptions = new JpegOptions(); // Create an instance of FileCreateSource and assign it to Source property imageOptions.Source = new FileCreateSource(dataDir + "Two_images_result_out.bmp", false); // Create an instance of Image and define canvas size using (var image = Image.Create(imageOptions, 600, 600)) { // Create and initialize an instance of Graphics, Clear the image surface with white color and Draw Image var graphics = new Graphics(image); graphics.Clear(Color.White); graphics.DrawImage(Image.Load(dataDir + "sample_1.bmp"), 0, 0, 600, 300); graphics.DrawImage(Image.Load(dataDir + "File1.bmp"), 0, 300, 600, 300); image.Save(); } // ExEnd:CombineImages }
public static void Run() { //ExStart:GetSizeOfCADLayout // The path to the documents directory. string MyDir = RunExamples.GetDataDir_ConvertingCAD(); string[] sourceFilePaths = new[] { MyDir + "conic_pyramid.dxf", MyDir + "Bottom_plate.dwg" }; foreach (var sourceFilePath in sourceFilePaths) { string extension = Path.GetExtension(sourceFilePath); using (CadImage cadImage = (CadImage)Aspose.CAD.Image.Load(sourceFilePath)) { List <string> layouts = GetNotEmptyLayouts(cadImage, extension); const double Epsilon = 0.00001; foreach (string layout in layouts) { System.Console.WriteLine("Layout= " + layout); using (FileStream fs = new FileStream(MyDir + "layout_" + extension + "_" + layout + ".jpg", FileMode.Create)) { JpegOptions jpegOptions = new JpegOptions(); CadRasterizationOptions options = new CadRasterizationOptions(); options.Layouts = new string[] { layout }; CadLayout l = cadImage.Layouts[layout]; if ((Math.Abs(l.MaxExtents.Y) < Epsilon && Math.Abs(l.MaxExtents.X) < Epsilon) || (Math.Abs(l.MaxExtents.Y + 1E+20) < Epsilon || Math.Abs(l.MaxExtents.X + 1E+20) < Epsilon) || (Math.Abs(l.MinExtents.Y - 1E+20) < Epsilon || Math.Abs(l.MinExtents.X - 1E+20) < Epsilon)) { // do nothing, we can automatically detect size // we can not rely on PlotPaperUnits here too because it is PlotInInches by default } else { double sizeExtX = l.MaxExtents.X - l.MinExtents.X; double sizeExtY = l.MaxExtents.Y - l.MinExtents.Y; if (l.PlotPaperUnits == CadPlotPaperUnits.PlotInInches) { options.PageHeight = CommonHelper.INtoPixels(sizeExtY, CommonHelper.DPI); options.PageWidth = CommonHelper.INtoPixels(sizeExtX, CommonHelper.DPI); } else { if (l.PlotPaperUnits == CadPlotPaperUnits.PlotInMillimeters) { options.PageHeight = CommonHelper.MMtoPixels(sizeExtY, CommonHelper.DPI); options.PageWidth = CommonHelper.MMtoPixels(sizeExtX, CommonHelper.DPI); } else { options.PageHeight = (float)sizeExtY; options.PageWidth = (float)sizeExtX; } } } options.CenterDrawing = true; jpegOptions.VectorRasterizationOptions = options; cadImage.Save(fs, jpegOptions); } } } } }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); //ExStart:ColorConversionUsingDefaultProfiles // Create a new Image. using (PsdImage image = new PsdImage(500, 500)) { // Fill image data. int count = image.Width * image.Height; int[] pixels = new int[count]; int r = 0; int g = 0; int b = 0; int channel = 0; for (int i = 0; i < count; i++) { if (channel % 3 == 0) { r++; if (r == 256) { r = 0; channel++; } } else if (channel % 3 == 1) { g++; if (g == 256) { g = 0; channel++; } } else { b++; if (b == 256) { b = 0; channel++; } } pixels[i] = Color.FromArgb(r, g, b).ToArgb(); } // Save the newly created pixels. image.SaveArgb32Pixels(image.Bounds, pixels); // Save the newly created image. image.Save(dataDir + "Default.jpg", new JpegOptions()); // Update color profile. StreamSource rgbprofile = new StreamSource(File.OpenRead(dataDir + "eciRGB_v2.icc")); StreamSource cmykprofile = new StreamSource(File.OpenRead(dataDir + "ISOcoated_v2_FullGamut4.icc")); image.RgbColorProfile = rgbprofile; image.CmykColorProfile = cmykprofile; // Save the resultant image with new YCCK profiles. You will notice differences in color values if compare the images. JpegOptions options = new JpegOptions(); options.ColorType = JpegCompressionColorMode.Cmyk; image.Save(dataDir + "Cmyk_Default_profiles.jpg", options); } //ExEnd:ColorConversionUsingDefaultProfiles }
///<Summary> /// ConvertImageFormat method to convert image to different image formats ///</Summary> public Response ConvertImageFormat(string fileName, string folderName, string outputType) { if (outputType.Equals("gif") || outputType.Equals("bmp") || outputType.Equals("jpg") || outputType.Equals("png") || outputType.Equals("psd") || outputType.Equals("emf") || outputType.Equals("svg") || outputType.Equals("wmf")) { ImageOptionsBase optionsBase = new BmpOptions(); if (outputType.Equals("jpg")) { optionsBase = new JpegOptions(); } else if (outputType.Equals("png")) { optionsBase = new PngOptions(); } else if (outputType.Equals("gif")) { optionsBase = new GifOptions(); } else if (outputType.Equals("psd")) { optionsBase = new PsdOptions(); } else if (outputType.Equals("emf")) { optionsBase = new EmfOptions(); } else if (outputType.Equals("svg")) { optionsBase = new SvgOptions(); } else if (outputType.Equals("wmf")) { optionsBase = new WmfOptions(); } return(ProcessTask(fileName, folderName, "." + outputType, true, true, delegate(string inFilePath, string outPath, string zipOutFolder) { string fileExtension = Path.GetExtension(inFilePath).ToLower(); if ((fileExtension == ".tif") || (fileExtension == ".tiff")) { string outfileName = Path.GetFileNameWithoutExtension(fileName) + "_{0}"; using (TiffImage multiImage = (TiffImage)Image.Load(inFilePath)) { if (multiImage.Frames.Length > 1) { int frameCounter = 0; // Iterate over the TiffFrames in TiffImage foreach (TiffFrame tiffFrame in multiImage.Frames) { multiImage.ActiveFrame = tiffFrame; // Load Pixels of TiffFrame into an array of Colors Color[] pixels = multiImage.LoadPixels(tiffFrame.Bounds); // Create an instance of JpegOptions // Set the Source of JpegOptions as FileCreateSource by specifying the location where output will be saved // Last boolean parameter denotes isTemporal outPath = zipOutFolder + "/" + outfileName; optionsBase.Source = new FileCreateSource(string.Format(outPath, frameCounter + 1) + "." + outputType, false); // Create a new RasterImage of Jpeg type using (var jpgImage = (RasterImage)Image.Create(optionsBase, tiffFrame.Width, tiffFrame.Height)) { // Save the JpegImage with pixels from TiffFrame jpgImage.SavePixels(tiffFrame.Bounds, pixels); // Resize the Jpeg Image jpgImage.Resize(100, 100, ResizeType.NearestNeighbourResample); // Save the results on disk jpgImage.Save(); } frameCounter++; } } else { multiImage.Save(outPath, optionsBase); } } } else { using (Image image = Image.Load(inFilePath)) { image.Save(outPath, optionsBase); } } })); } return(new Response { FileName = null, Status = "Output type not found", StatusCode = 500 }); }