Solved

Printing JPGs

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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 create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…

929 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

13 Experts available now in Live!

Get 1:1 Help Now