Link to home
Start Free TrialLog in
Avatar of menorcanet
menorcanetFlag for Spain

asked on

'''>>- Print JPG Files -<<'''

why doesn't this work ?

ShellExecute(0,'print','c:\a.jpg','','',0);   ?

How should I do it ?

k, thanx ya.
Avatar of binkzz
binkzz

One way to do it is loading it into a component and then execute the component.print
method.

Binkzz
menorcanet

Have you included the JPEG unit in you uses clause..

uses
 Forms...., JPEG;

Also your Shellexecute's handle should be

Handle not 0

ShellExecute(Handle, 'print', 'c:\a.jpg', '', '', 0);

have you tried loading the jpg into a image component and then printing it..

Later
BoRiS
as explained in my previous comment
Avatar of menorcanet

ASKER

ok, I tried with "Handle" and I still get the Error 31 ( a:= Shellexecute(handle,'pri...)

and... I have no idea on how to load the jpg file into an image component, and then
 print it.

and yeah, I included the ShellApi and JPEG in the USES clause.

This one works with a DOC file extension

      ShellExecute(0, 'print', 'c:\windows\desktop\test.doc', nil, nil, 0);

Regards,
Viktor Ivanov
menorcanet

drop  a button on your form and on the onclick event copy this, also add printers to your uses clause...

procedure TForm1.BitBtn1Click(Sender: TObject);
    var
      JPG : TJpegImage;

    begin
      if Printer.Printing then
        Application.MessageBox('Printer is busy', 'Print Error', 0)
      else
        begin
          Printer.Title := 'Printing JPEG'S';
          Printer.BeginDoc;
          with Printer.Canvas do
            begin
              Font.Name := 'Arial';
              Font.Pitch := fpDefault;
              Font.Style := [fsItalic, fsBold];
              Font.Size := 30;
              Font.Color := clBlack;
              TextOut(100, 100, 'Getting the JPEG Printed');
              JPG := TJpegImage.Create;
              JPG.LoadFromFile('c:\a.jpg');
              Draw(100, 300, JPG);
              JPG.Free;
            end;
          Printer.EndDoc;
        end;
    end;

Later
BoRiS
Or use the example in D4's help\example\Jpeg directory!:

procedure TForm1.Print1Click(Sender: TObject);
var
  AspectRatio: Single;
  OutputWidth, OutputHeight: Single;
begin
  if not PrintDialog1.Execute then Exit;
  Printer.BeginDoc;
  try
    OutputWidth := Image1.Picture.Width;
    OutputHeight := Image1.Picture.Height;
    AspectRatio := OutputWidth / OutputHeight;
    if (OutputWidth < Printer.PageWidth) and
      (OutputHeight < Printer.PageHeight) then
    begin
      if OutputWidth < OutputHeight then
      begin
        OutputHeight := Printer.PageHeight;
        OutputWidth := OutputHeight * AspectRatio;
      end
      else
      begin
        OutputWidth := Printer.PageWidth;
        OutputHeight := OutputWidth / AspectRatio;
      end
    end;
    if OutputWidth > Printer.PageWidth then
    begin
      OutputWidth := Printer.PageWidth;
      OutputHeight := OutputWidth / AspectRatio;
    end;
    if OutputHeight > Printer.PageHeight then
    begin
      OutputHeight := Printer.PageHeight;
      OutputWidth := OutputHeight * AspectRatio;
    end;
    Printer.Canvas.StretchDraw(Rect(0,0,
      Trunc(OutputWidth), Trunc(OutputHeight)),
      Image1.Picture.Graphic);
  finally
    Printer.EndDoc;
  end;
end;

Thaddy:::

How do I assign Image1.Picture with a jpg file ?
Boris' answer works, but the image is printed very small.


hey Boris, take a look at my question about Using JPEG,

I left a message for you

Look at the comment
I don't have D4, I have Delphi 1 to 3.

Hello menorcanet.////

When you draw the JPG image onto the Printer's canvas use StretchDraw() If you need help with that just tell me :-)

Cheers,
Viktor
menorcanet

Yip send me your component and I'll put it up, like I said the page is for you guys here at the EX-EX my email is phillip@vwv.com
remember to send a brief discription of the component etc.

also I see you say the jpeg prints to small just increase the draw size

Draw(100, 300, JPG);
to
Draw(500, 480, JPG);

Later
BoRiS
Hello guys.

Draw(500, 480) will just print it in a x=500 and y=480...it won't increase the size of the printed image....

As I said before you need to use StretchDraw() even thought it's not the only one to use...however it's the easiest one to be used ;->

Regards,
Viktor Ivanov
menocanet

Yip viktornet is totally correct, sorry wasn't thinking I meant to say
 
StrechDraw();

Viktornet

check out my home page it's for all the experts here at Ex-Ex to put up there components etc...

http://www.geocities.com/SiliconValley/Garage/3862/

follow the delphi section...

That goes for the rest of you here at Ex-Ex (delphi)

Later
BoRiS
menorcanet

forgot to mention how to use strechDraw

StrechDraw(Rect, JPG);

rect been the defined rectangle for the printer canvas

Later
BoRiS
Hello again!

Here is how to use StrecthDraw()

This is Boris' procedure but I've added the needed function



     procedure TForm1.BitBtn1Click(Sender: TObject);
         var
           JPG : TJpegImage;
           R : TRect;
         begin
           if Printer.Printing then
             Application.MessageBox('Printer is busy', 'Print Error', 0)
           else
             begin
               Printer.Title := 'Printing JPEG''S';
               Printer.BeginDoc;
               with Printer.Canvas do
                 begin
                   Font.Name := 'Arial';
                   Font.Pitch := fpDefault;
                   Font.Style := [fsItalic, fsBold];
                   Font.Size := 30;
                   Font.Color := clBlack;
                   TextOut(100, 100, 'Getting the JPEG Printed');
                   JPG := TJpegImage.Create;
                   JPG.LoadFromFile('C:\something\test.jpg');
                   R := Rect(0, 0, JPG.Width * 2, JPG.Height * 2);//make it twice as big as it was b4
                   StretchDraw(R, JPG);
                   JPG.Free;
                 end;
               Printer.EndDoc;
             end;
         end;

Hope this helps :-)

Regards,
Viktor Ivanov
Yeah ! it works now with StretchDraw !

thanx a lot you all !


Hello y'all,....

Boris....go for the points....

Cheers,
Viktor
ASKER CERTIFIED SOLUTION
Avatar of BoRiS
BoRiS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No problem :-)

Cheers,
Viktor
there you have the points.