LEADTOOLS Support
Document
Document SDK Questions
Re: Saving file with annotation goes from 100kb to 25Mb
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Wednesday, December 2, 2009 2:33:05 AM(UTC)
Groups: Registered
Posts: 2
I wrote a utility which goes through our directories where our users store there images and I look for any .ann file's which indicate an annotation.
I then save the file with the annotation as part of the file. The problem is the image grows substanially. For example a 100kb jpg with a 2kb .ann file became a 25Mb jpg. Here is my code, what is wrong;
private void BurnAnnotaion(string strSourceFileName, string strAnnotationFileName,
string strTargetFileName, string strExtension)
{
const int firstPage = 1;
try
{
RasterImageFormat imgFormat = GetOutputFormat(strExtension);
// intitialize a new RasterCodecs object
//RasterCodecs.CodecsPath = CodecPath;
RasterCodecs codecs = new RasterCodecs();
// load the main image into our viewer
rasterImageViewer.Image = codecs.Load(strSourceFileName);
if (rasterImageViewer.Image != null)
{
// Load annotations into each image page
for (int page = 1; page <= rasterImageViewer.Image.PageCount; page++)
{
rasterImageViewer.Image.Page = page;
ColorResolutionCommand ColorRes = new ColorResolutionCommand();
ColorRes.BitsPerPixel = 24;
ColorRes.Run(rasterImageViewer.Image);
// Create an instance of the Annotation IO engine
AnnCodecs annCodecs = new AnnCodecs();
annAutomation.Container.UnitConverter.DpiX = 50;
annAutomation.Container.UnitConverter.DpiY = 50;
annCodecs.Load(strAnnotationFileName, annAutomation.Container, page);
annAutomation.Realize();
// Save the modified file out with annotation
if (page == firstPage)
{
codecs.Save(rasterImageViewer.Image, strTargetFileName, imgFormat,
rasterImageViewer.Image.BitsPerPixel < 4 ? 4 : rasterImageViewer.Image.BitsPerPixel, page, page, page, CodecsSavePageMode.Overwrite);
}
else
{
codecs.Save(rasterImageViewer.Image, strTargetFileName, imgFormat,
rasterImageViewer.Image.BitsPerPixel < 4 ? 4 : rasterImageViewer.Image.BitsPerPixel, page, page, page, CodecsSavePageMode.Append);
}
annAutomation.Container.Objects.Clear();
}
}
}
catch (Exception ex)
{
objLog.Error("BurnAnnotation Error:", ex);
}
}
#2
Posted
:
Thursday, December 3, 2009 5:28:57 AM(UTC)
Groups: Guests
Posts: 3,022
Was thanked: 2 time(s) in 2 post(s)
I'm not sure what is the value returned by GetOutputFormat, but it seems that you are saving the file as uncompressed JPEG. Try to use the RasterImage.OriginalFormat Property to save the file. For example try to save the file as follows:
Save(rasterImageViewer.Image, strTargetFileName, rasterImageViewer.Image.OriginalFormat , ....
LEADTOOLS Support
Document
Document SDK Questions
Re: Saving file with annotation goes from 100kb to 25Mb
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.