Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Printing JPGs

Posted on 1998-07-31
4
254 Views
Last Modified: 2013-11-19
Hello...
I have to print a document which includes a picture. To save physical space I decided to use .JPG - Files everywhere instead of BitMaps. But when I'm trying to print a such JPG, i get exception with 'Graphic Format is not valid', but I made sure, that the JPEG-Unit (Delphi 3, prof) is loaded. It would be good if I could use JPGs, because the BMP File Size is about 240KB while the JPG is only 32KB. Please note, I'm only a young student, so I hope there is a way to get around this without the need of an expensive component.

Another Question is, is there a command like <Center> in HTML to Center Text/Images or do I have to mess with the Pixels ?

here the used code (in short version)

procedure TForm43.BitBtn3Click(Sender: TObject);

var
  BitMap : TBitMap;

begin
  if Printer.Printing then
    Application.MessageBox('Printer is actually busy', 'CompQuiz Print Error', 0)
  else
    begin
      Printer.Title := 'CompQuiz Statistics';
      Printer.BeginDoc;
      with Printer.Canvas do
        begin
          Font.Name := 'Arial';
          Font.Pitch := fpDefault;
          Font.Style := [fsItalic, fsBold];
          Font.Size := 30;
          Font.Color := clBlue; //my printer ran out of black cartridge
          TextOut(100, 100, 'Omsec CompQuiz32 v1.0 ALPHA');
          BitMap := TBitMap.Create;
          BitMap.LoadFromFile('c:\quiz\gb.jpg');
          Draw(100, 300, BitMap);
          BitMap.Free;
        end;
      Printer.EndDoc;
    end;
end;

Thanx for Help :)
0
Comment
Question by:omsec
  • 2
4 Comments
 
LVL 2

Author Comment

by:omsec
ID: 1359302
btw, when I used "c:\quiz\gb2.bmp", same as the JPG instead it worked fine.
0
 
LVL 4

Accepted Solution

by:
BoRiS earned 70 total points
ID: 1359303
omsec

replace this

var
      BitMap : TBitMap;

with this

var
    JPG: TJpgImage;

and this

          BitMap := TBitMap.Create;
              BitMap.LoadFromFile('c:\quiz\gb.jpg');

with this...

          JPG := TJpgImage.Create;
              JPG.LoadFromFile('c:\quiz\gb.jpg');

and finally this...

          Draw(100, 300, BitMap);
              BitMap.Free;

with this...

          Draw(100, 300, JPG);
              JPG.Free;

this should do it...

Later
BoRiS  
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1359304
omsec

sorry it should be

var
 JPG : TJpegImage;

not TJpgImage;

and

JPG := TJpegImage.Create;

not JPG := TJpgImage.Create;

Later
BoRiS
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1359305
For your infomation, there are some FREEware for reading JPG file in the web. eg.

NViewlib.dll at http://einstein.ae.eng.ua.edu/nishita/index.htm 
is a dll that enable you to manupulate JPG, JIF, GIF, BMP, DIB, RLE, TGA, PCX.

Jpegimage at  WWW: http://www.westend.de/~hoerstemeier

checkout delphi super page for more.

Sound like advertisement? I have no dealing with the authors of these software or webpage :-))
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…
It’s easy to embed any of your public Prezi presentations on your website or social network to share with others. Learn how simple it is in this tutorial.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question