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() { // 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: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 static void Run() { // ExStart:ReadAllEXIFTags // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); // Load a Jpeg image from file path location or stream using (JpegImage image = (JpegImage)Image.Load(dataDir + "aspose-logo.jpg")) { // Perform the automatic rotation on the image depending on the orientation data stored in the EXIF image.AutoRotate(); // Save the result on disc or stream image.Save(dataDir + "aspose-logo_out.jpg"); } }
public static void Run() { // ExStart:AddThumbnailToJFIFSegment // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); using (MemoryStream stream = new MemoryStream()) { JpegImage thumbnailImage = new JpegImage(100, 100); JpegImage image = new JpegImage(1000, 1000); image.Jfif = new JFIFData(); image.Jfif.Thumbnail = thumbnailImage; image.Save(dataDir + stream + "_out.jpeg"); } // ExEnd:AddThumbnailToJFIFSegment }
public static void Run() { //ExStart:AddThumbnailToEXIFSegment // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); using (MemoryStream stream = new MemoryStream()) { JpegImage thumbnailImage = new JpegImage(100, 100); JpegImage image = new JpegImage(1000, 1000); image.ExifData = new JpegExifData(); image.ExifData.Thumbnail = thumbnailImage; image.Save(dataDir + stream + "_out.jpg"); } //ExEnd:AddThumbnailToEXIFSegmentk }
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:ColorConversionUsingDefaultProfiles // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); // Load an existing JPG image using (JpegImage image = (JpegImage)Image.Load(dataDir + "aspose-logo_tn.jpg")) { StreamSource rgbprofile = new StreamSource(File.OpenRead(dataDir + "rgb.icc")); StreamSource cmykprofile = new StreamSource(File.OpenRead(dataDir + "cmyk.icc")); image.DestinationRgbColorProfile = rgbprofile; image.DestinationCmykColorProfile = cmykprofile; image.Save(dataDir + "ColorConversionUsingDefaultProfiles_out.icc"); } //ExStart:ColorConversionUsingDefaultProfiles }
public static void Run() { //ExStart:AutoCorrectOrientationOfJPEGImages // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); Console.WriteLine("Running example AutoCorrectOrientationOfJPEGImages"); // Load a Jpeg image from file path location or stream using (JpegImage image = (JpegImage)Image.Load(dataDir + "aspose-logo.jpg")) { // Perform the automatic rotation on the image depending on the orientation data stored in the EXIF and Save the result on disc or stream image.AutoRotate(); image.Save(dataDir + "aspose-logo_out.jpg"); } Console.WriteLine("Finished example AutoCorrectOrientationOfJPEGImages"); //ExEnd:AutoCorrectOrientationOfJPEGImages }
public static void Run() { //ExStart:AddThumbnailToJFIFSegment // The path to the documents directory. string dataDir = RunExamples.GetDataDir_JPEG(); Console.WriteLine("Running example AddThumbnailToJFIFSegment"); using (MemoryStream stream = new MemoryStream()) { JpegImage thumbnailImage = new JpegImage(100, 100); JpegImage image = new JpegImage(1000, 1000); image.Jfif = new JFIFData(); image.Jfif.Thumbnail = thumbnailImage; image.Save(dataDir + stream + "_out.jpeg"); } Console.WriteLine("Finished example AddThumbnailToJFIFSegment"); //ExEnd:AddThumbnailToJFIFSegment }
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() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_ModifyingAndConvertingImages(); //ExStart:ColorConversionUsingICCProfiles // Create a new JpegImage. using (JpegImage image = new JpegImage(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 resultant image with default Icc profiles. image.Save(dataDir + "Default_profiles.jpg"); // 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.Ycck; image.Save(dataDir + "Ycck_profiles.jpg", options); } //ExEnd:ColorConversionUsingICCProfiles }