Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

Use scanner as copier

I am trying to write an application that will use a scanner/printer as a photocopier.

I have a component that does the scanning and puts the result in a TImage.

How can I then print it so that it looks like the original?
0
sharons
Asked:
sharons
  • 7
  • 5
  • 3
  • +1
1 Solution
 
TheNeilCommented:
Are you scanning the entire page? It should just be a case of outputting the image to the printer a la:

Printer.BeginDoc;
Printer.Canvas.StretchDraw(RECT(0, 0, Printer.PageWidth, Printer.PageHeight), Image1.Picture.Bitmap);
Printer.EndDoc;

The Neil =:)
0
 
sharonsAuthor Commented:
Thank you Neil. Now it fills the page but for some reason the quality is very poor, like it's been fax and photocopied many times.

I tried an application from the Internet that allows you to make copies like I describe and the quality was perfect. Therefore I know this is possible.  Maybe the problem as to do with how I load the picture.The Twain component I am using is MCM Twain.
0
 
TheNeilCommented:
I don't know the component that you're using but to get decent quality out of it you're going to have to scan at something like 200dpi (at least). That's going to mean a lot of memory. There are a few things to try first though:

Are you in 16/24 bit colour mode?
Is the graphic being stored in a visual component? (Faster if you can store it purely in memory)
Is the scanner setup correctly?
If you're only using a B&W printer, try scanning as greyscale instead of true colour

How big is the scanned image (in terms of pixels)? I think you'll find that this is the root of your problem (or I hope so as we can easily fix it)

The Neil =:)
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
mullet_attackCommented:
I agree with TheNeil. Scan the image into a memory DC at the highest res you can afford, I'd use 300 DPI as that's common amongst laser and inkjet's. At 300 dpi scanned, your image on screen is huge (probably 72 dpi, so it's approx 16 times bigger !), hence the need for the memory DC. Once scanned, you can Bitblt the MemDC onto an image to show the user.
0
 
TheNeilCommented:
The DPI is probably the root of low quality but just in case it isn't, what version of Delphi are you using Sharons? Delphi 2's implementation of StretchDraw is useless for the Printer and you have to start using StretchBlt

The Neil =:)

PS Thanks Mullet_Attack - does help to know that I'm not coming up with stupid ideas on my own (well, not all the time anyway)
0
 
PortalCommented:
Actually the most probable reason the printer comes out low quality is that you should be using stretchdibs instead of stretchdraw.

To prove that the image can be printed better try printing it with Microsoft Word - it should come out a lot better.

Also check out this link at comparison printouts between stretchdraw and stretchdibs.

http://www.efg2.com/lab/OtherProjects/PrinterDemo1.htm
0
 
TheNeilCommented:
Portal,

This used to be a problem but Borland went and fixed it for later versions of Delphi (4 and 5 certainly, but don't know about 3). Version 2 was a nightmare and Stretchdraw DID look awful

The Neil =:)
0
 
mullet_attackCommented:
Let's stop for a second. An A4 page is  about 8 1/2 inches by 11 inches. At even 200 dpi that's 1700 x 2200 pixels. I doubt that sharons's TImage is that big. At half a high res screen it's gonna be at most about 500 wide by 750 high. That's less than one ninth the resolution. If you stretch the Timage to fit the A4 page, it's gonna look like rubbish no matter what streching routine you use. The only solution is to scan at a reasonable res into memory, and print from that memory. That A4 page at 24 bit color is nearly 4 meg. No wonder scan and print is a slow process.

Try scanning at decent res into Timage, and have Stretch true. The Timage will have the high res pic in memory, but display a shrunk, low-res version.

Portal : Word does this this. It 'stores' images internally and only shows a shrunk version in the document. Proves this by changing the zoom % in word. You can go from unreadable rubbish to perfect image and back again.

BTW you might use GetDeviceCaps to get the printer resolution, and determine your scan resolution from there, to try and match them up.

0
 
sharonsAuthor Commented:
I am using Delphi 5.

Do you have an example of using StretchDIBits to take the content of a TImage and print it.
0
 
sharonsAuthor Commented:
Tha scanned image is an 8 1/2 by 11 page with some text.
0
 
TheNeilCommented:
In Delphi 5 it won't make any difference. I haven't used StretchDIBits for several years (which is how much faith I have in StretchDraw). Trust me, StretchDraw works perfectly in Delphi 5

The Neil =:)
0
 
sharonsAuthor Commented:
I think it might be more of a scanner issue than a delphi issue. It seems that the result of the scanning produces a large bitmap, much larger than the page. When it is reduced to fit a page, I think that's when the poor quality is created.

I am just trying to figure out why the bitmap cannot simply be the right size.
0
 
TheNeilCommented:
What do you mean 'bigger than the page'? If the bitmap is bigger than the page, the StretchDraw routine will simply shrink it to fit (or raise the dpi depending on how you look at it). In fact, the bigger the bitmap, the better the output quality. I know this is a stupid question but is the printer setup correctly?

The Neil =:)
0
 
mullet_attackCommented:
Sharons: did you read my previous post?

TheNiel : please tell me if I am gibbering...

If you scan at a higher res than printer, then you will need to shrink the image to fit the page. You will lose data. Your algorythm will determine how much data you lose, hence the quality of the print.

If you scan at a lower res than printer, then you need to upscale the image, creating pixel data where there was none before. Again, you algorytm for stretching will determine the print quality.

The easiest way is to match your scan and print resolutions.

Scan and print at the same res. No stretching or shrinking. none.

eg If you scan at 9600 DPI, and print it to a 300 DPI printer, you page will now print on 1024 pages. try it !.

0
 
TheNeilCommented:
Mullet,

Rest assured, you're talking sense (although the chances of scanning at BIGGER than the printed page are remote). It all depends what the printer dpi is set to

The Neil =:)
0
 
sharonsAuthor Commented:
It seems I was making things way too complicated. I just load the bitmap in a TImage then use StretchDraw and it works fine. I think it's probably a setting on the scanner that fixed it. Thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now