Manipulating JPEG2000 images
Contents
[
Hide
]
Memory Strategy optimization
Loading and creating of JPEG2000 images can be proceeded using memory strategy optimization - ie limiting memory buffer size for operation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Aspose.Imaging; | |
using Aspose.Imaging.FileFormats.Bmp; | |
using Aspose.Imaging.FileFormats.Dicom; | |
using Aspose.Imaging.FileFormats.Djvu; | |
using Aspose.Imaging.FileFormats.Emf; | |
using Aspose.Imaging.FileFormats.Eps; | |
using Aspose.Imaging.FileFormats.Eps.Consts; | |
using Aspose.Imaging.FileFormats.Gif; | |
using Aspose.Imaging.FileFormats.Gif.Blocks; | |
using Aspose.Imaging.FileFormats.Jpeg; | |
using Aspose.Imaging.FileFormats.Jpeg2000; | |
using Aspose.Imaging.FileFormats.Pdf; | |
using Aspose.Imaging.FileFormats.Png; | |
using Aspose.Imaging.FileFormats.Psd; | |
using Aspose.Imaging.FileFormats.Svg; | |
using Aspose.Imaging.FileFormats.Tga; | |
using Aspose.Imaging.FileFormats.Tiff.Enums; | |
using Aspose.Imaging.ImageFilters.FilterOptions; | |
using Aspose.Imaging.ImageOptions; | |
using Aspose.Imaging.Sources; | |
using Aspose.Imaging.Xmp; | |
using Aspose.Imaging.Xmp.Schemas.Dicom; | |
using System; | |
using System.IO; | |
using System.Linq; | |
using System.Threading.Tasks; | |
string templatesFolder = @"c:\Users\USER\Downloads\templates\"; | |
string dataDir = templatesFolder; | |
// Setting a memory limit of 10 megabytes for target loaded image | |
// JP2 codec | |
using (Image image = Image.Load(dataDir + "couple.jp2", new LoadOptions() { BufferSizeHint = 100 })) | |
{ | |
image.Save(dataDir + "result.jp2"); | |
} | |
File.Delete(dataDir + "result.jp2"); | |
// Setting a memory limit of 10 megabytes for target created image | |
// JP2 codec | |
ImageOptionsBase createOptions = new Jpeg2000Options { Codec = Jpeg2000Codec.Jp2 }; | |
createOptions.BufferSizeHint = 10; | |
createOptions.Source = new FileCreateSource(dataDir + "result.jp2", false); | |
using (var image = Image.Create(createOptions, 100, 100)) | |
{ | |
image.Save(); // save to same location | |
} | |
File.Delete(dataDir + "result.jp2"); | |
// J2K codec | |
createOptions = new Jpeg2000Options { Codec = Jpeg2000Codec.J2K }; | |
createOptions.BufferSizeHint = 10; | |
createOptions.Source = new FileCreateSource(dataDir + "result.j2k", false); | |
using (var image = Image.Create(createOptions, 100, 100)) | |
{ | |
image.Save(); // save to same location | |
} | |
File.Delete(dataDir + "result.j2k"); |