vt_steve_01 Posted August 27, 2003 Posted August 27, 2003 Hello all. I have a little problem that I need some help with. Here's a little background info on the project I'm 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 doesn't like this resolution. It needs it to be around 200x200. I've 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? I've 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! Quote
*Experts* Nerseus Posted August 27, 2003 *Experts* Posted August 27, 2003 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? I'm 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. Here's some code to do the stretched version: 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): 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 Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.