public void Save(
RasterCodecs codecs,
Stream stream,
RasterImage image,
Jpeg2000FileFormat format,
int bitsPerPixel,
int qualityFactor
)
codecs
The Leadtools.Codecs.RasterCodecs object.
stream
A System.IO.Stream where the image data will be saved.
image
The Leadtools.RasterImage object that holds the image data.
format
Output JPEG 2000 file format. For valid values, refer to Jpeg2000FileFormat.
bitsPerPixel
Resulting file's pixel depth. Possible values are: 8, 12, 16, 24, 32, 48, 64, and 0. A value of zero [0] means that each image will be saved with its bits per pixel value, if that value is equal to one of the possible values (8, 12, 16, 24, 32, 48, or 64).
qualityFactor
Quality factor. This value determines the degree of loss in the compression process. Possible values are from 0 to 255. A value of zero (0) represents lossless compression. Values between 1 and 255 are interpreted as a compression ratio.
All engine boxes that are currently set will also be saved in this file.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Jpeg2000;
public void SaveStreamExample()
{
RasterCodecs codecs = new RasterCodecs();
codecs.ThrowExceptionsOnInvalidImages = true;
FileStream fs = File.OpenRead(Path.Combine(LEAD_VARS.ImagesDir, "image1.jp2"));
// Load a JPEG 2000 image
Jpeg2000Engine engine = new Jpeg2000Engine();
RasterImage image = engine.Load(codecs, fs, 0, CodecsLoadByteOrder.BgrOrGray);
List<XmlBox> xmlBoxes = engine.GetBoxes<XmlBox>(Jpeg2000FileFormat.LeadJp2);
ResolutionBox resBox = (ResolutionBox)engine.GetBox(Jpeg2000FileFormat.LeadJp2, Jpeg2000BoxType.ResolutionBox);
engine.ResetEngineBoxes();
//Set the JPX engine's XML box
engine.SetBoxes(Jpeg2000FileFormat.LeadJpx, xmlBoxes);
engine.SetBox(Jpeg2000FileFormat.LeadJpx, resBox);
fs.Close();
fs = File.Create(Path.Combine(LEAD_VARS.ImagesDir, "Test.jpx"));
//Save the image in JPX file format
engine.Save(codecs, fs, image, Jpeg2000FileFormat.LeadJpx, 24, 5);
//Append Intellectual Property Rights box
String copyRights = ("Copyright (c) 1991-2022 by LEAD Technologies, Inc. All Rights Reserved.");
IprBox ipr = new IprBox();
ipr.Data = Encoding.ASCII.GetBytes(copyRights);
engine.AppendBox(fs, ipr);
// Clean up
engine.Dispose();
image.Dispose();
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}