?
Solved

Printing JPGs

Posted on 1998-07-31
4
Medium Priority
?
257 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
[X]
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
  • 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 280 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Learn how to set up basic frames and paths in Prezi and understand the open space that Prezi allows you to create presentations in.
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.
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

765 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