Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, September 21, 2010 10:59:28 AM(UTC)

amurray  
amurray

Groups: Registered
Posts: 12


There's got to be a dither setting I'm missing, but the bitonalization applied when saving out printed pages with the code below looks terrible. What can I do to improve the quality of the image after it's been bitonalized?

#region print event handling

int currentPageNumber = 0;
Leadtools.RasterImage currentImage = null;

void printer_JobEvent(object sender, Leadtools.Printer.JobEventArgs e)
{
if (e.JobEventState == Leadtools.Printer.EventState.JobStart) {
this.currentPageNumber = 0;
}
else if (e.JobEventState == Leadtools.Printer.EventState.JobEnd) {
// save the file to disk
string filename = Path.GetTempFileName();
codecs.Save(currentImage, filename, Leadtools.RasterImageFormat.CcittGroup4, 1);
currentImage.Dispose();

// pass the image off to the DTI application itself
LaunchImageIntoDTI(filename);

return;
}
}

void printer_EmfEvent(object sender, Leadtools.Printer.EmfEventArgs e)
{
Leadtools.RasterImage newPage;

using (var mf = new System.Drawing.Imaging.Metafile(e.Stream)) {
int targetDpi = 200;

double sourceWidthInInches = Math.Round(mf.Width / mf.HorizontalResolution, 2);
double sourceHeightInInches = Math.Round(mf.Height / mf.VerticalResolution, 2);

int destWidthInPixels = (int)Math.Round(sourceWidthInInches * targetDpi);
int destHeightInPixels = (int)Math.Round(sourceHeightInInches * targetDpi);

using (Bitmap bmp = new Bitmap(destWidthInPixels, destHeightInPixels)) {
bmp.SetResolution(targetDpi, targetDpi);

using (Graphics g = Graphics.FromImage(bmp)) {
g.Clear(System.Drawing.Color.White);
g.DrawImage(mf, 0, 0, bmp.Width, bmp.Height);
}

newPage = Leadtools.Drawing.RasterImageConverter.ConvertFromImage(
bmp, Leadtools.Drawing.ConvertFromImageOptions.None);
}
}

if (++currentPageNumber == 1)
currentImage = newPage;
else
currentImage.AddPage(newPage);
}

#endregion
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, September 22, 2010 5:45:08 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

If you save a colored image as 1-bit, the default behavior is used and you will not be able to control it.
If you use the Leadtools.ImageProcessing.ColorResolutionCommand Class to convert from any bits-per-pixel to any bits-per-pixel, you will be able to control dithering options including 'None' mode.

 
#3 Posted : Thursday, September 23, 2010 5:42:07 AM(UTC)

amurray  
amurray

Groups: Registered
Posts: 12


Which dither method would you recommend for best results with text?
 
#4 Posted : Sunday, September 26, 2010 5:59:34 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

Was thanked: 2 time(s) in 2 post(s)

You can check the ColorResolutionCommand from the pre-built C# demo shipped with our toolkit and try the Color => Transform => Color Resolution and try the different dithering methods. But for text, you might get good results when setting dithering to 'none'.
 
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.122 seconds.