Board index » delphi » D5 Jpegdemo Doesnt Print

D5 Jpegdemo Doesnt Print

A Delphi5 example of Jpeg viewer (jpegdemo) was perfect for an
application I am writing. The only trouble is that nothing prints out.
Here is the complete original source (what's wrong):

-----Begin-----
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;
-----End-----

TIA
Steven.

 

Re:D5 Jpegdemo Doesnt Print


StretchDraw doesn't work on most printer drivers ! You have to use
StretchDIBits instead (see
http://www.efg2.com/Lab/Library/Delphi/Printing/Default.htm).

"Steven" <zank...@hutch.com.au> schreef in bericht
news:3979648b.39070198@news.hutch.com.au...

Quote
> A Delphi5 example of Jpeg viewer (jpegdemo) was perfect for an
> application I am writing. The only trouble is that nothing prints out.
> Here is the complete original source (what's wrong):

> -----Begin-----
> 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;
> -----End-----

> TIA
> Steven.

Re:D5 Jpegdemo Doesnt Print


Hi :)

Do you use Win 9x or Win NT?
We developed app for wirk with graphics and it use jpegs. Everything
is fine on Win9x but on NT you cannot see pictures in TQRImage
component. But on printer it's fine.

Shalom,
Mladen K.

Re:D5 Jpegdemo Doesnt Print


On Mon, 24 Jul 2000 09:28:34 +0200, "M.H. Avegaart"

Quote
<avega...@NOSPAMmccomm.nl> wrote:
>StretchDraw doesn't work on most printer drivers ! You have to use
>StretchDIBits instead (see
>http://www.efg2.com/Lab/Library/Delphi/Printing/Default.htm).

Tried that site, grabbed two almost identical pieces of code. Removed
syntax errors in one caused by either 98 or D5. When running the code
I get an EAccess Violation, probably caused by Printer.Canvas.

I've tried the D5 Help examples. No luck there. Its not the printer,
as I've tried 3 different modern printers.

The Help file seems to make an excuse saying examples given might not
work with some printers. I think it's just Borland programmers taking
a short cut.

The rest of my application is working beautifully, but printing both
Jpegs and bitmaps is necessary.

HELP

TIA.

PS: Borland should fire some of their staff.

Re:D5 Jpegdemo Doesnt Print


StretchDIBits needs about 2000 lines of
support code to make it work right.

Take a look at TExcellentImagePrinter at:

http://www.code4sale.com/joehecht

--
Joe Hecht Associates

http://www.code4sale.com/joehecht/index.htm

Quote
"Steven" <zank...@hutch.com.au> wrote in message

news:397d6a16.19419660@news.hutch.com.au...
Quote
> On Mon, 24 Jul 2000 09:28:34 +0200, "M.H. Avegaart"
> <avega...@NOSPAMmccomm.nl> wrote:

> >StretchDraw doesn't work on most printer drivers ! You have to use
> >StretchDIBits instead (see
> >http://www.efg2.com/Lab/Library/Delphi/Printing/Default.htm).

> Tried that site, grabbed two almost identical pieces of code. Removed
> syntax errors in one caused by either 98 or D5. When running the code
> I get an EAccess Violation, probably caused by Printer.Canvas.

> I've tried the D5 Help examples. No luck there. Its not the printer,
> as I've tried 3 different modern printers.

> The Help file seems to make an excuse saying examples given might not
> work with some printers. I think it's just Borland programmers taking
> a short cut.

> The rest of my application is working beautifully, but printing both
> Jpegs and bitmaps is necessary.

> HELP

> TIA.

> PS: Borland should fire some of their staff.

Other Threads