Solved

Printing JPGs

Posted on 1998-07-31
4
251 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now