Image Resolution

vt_steve_01

New member
Joined
Aug 27, 2003
Messages
1
Location
Roanoke, VA
Hello all. I have a little problem that I need some help with. Heres a little background info on the project Im working on. Our users fax documents all over the place. When the scan the documents, a digital copy is sent to our server. We then have an OCR engine that reads it and inserts it into a document manager database.

Well the documents come in with a 204x98 resolution. The OCR doesnt like this resolution. It needs it to be around 200x200. Ive been assigned to write a small app that will change the images resolutions.

There, in lies the issue. How do I go about doing this? Ive played around with GDI and other controls (i.e. Kodak Image Edit Control). I can easily GET the resolutions, but I cannot SET them because the are READ ONLY.

Can anyone shed some light on this for me? Is there a good control or any good examples that you could point me to? Thanks in advance!
 
I assume you have a way of reading the image into a Bitmap object in .NET and you just need a way to get it saved out again?

Im not sure how you want to resize: stretch the image or just make the image 200x200 and leave some extra "white" area on the bottom of the image. Heres some code to do the stretched version:
C#:
Bitmap b1 = new Bitmap(@"c:\temp\test.bmp");
// Stretched version
Bitmap b2 = new Bitmap(b1, new Size(200, 200));

And some for the non stretched version (well, stretched but keeping the same aspect ratio):
C#:
Bitmap b1 = new Bitmap(@"c:\temp\test.bmp");
// Non stretched version
Bitmap b3 = new Bitmap(200, 200, b1.PixelFormat);

// Figure out scaling factor for drawing
float scale;
if(b1.Width > b1.Height)
	scale = 200f / b1.Width;
else
	scale = 200f / b1.Height;
	

Rectangle dest = new Rectangle(0, 0, (int)((float)b1.Size.Width * scale), (int)((float)b1.Size.Height * scale));
Rectangle src = new Rectangle(0, 0, b1.Size.Width, b1.Size.Height);

Graphics g3 = Graphics.FromImage(b3);
g3.DrawImage(b1, dest, src, GraphicsUnit.Pixel);
g3.Dispose();

-Ner
 
Back
Top