Problem with printing, using Delphi XE2 [Edit]

I have problem with printing images using Delphi XE2. I have code Delphi 7, and this code work very well.
{code}
procedure Print;
var
  ImgName: string;
  rect: TRect;
  jpg: TJPEGImage;
begin
  OpenPictureDialog1.Execute;
  ImgName := OpenPictureDialog1.FileName;

  rect.TopLeft:=Point(0,0);
  rect.BottomRight:=Point(Printer.PageWidth,Printer.PageHeight);

  jpg := TJPEGImage.Create;
  jpg.LoadFromFile(ImgName);

  Printer.BeginDoc;
  Printer.Canvas.StretchDraw(rect,jpg);
  Printer.EndDoc;
end;
{code}
But this code Delphi XE2 is not work, printer print clear sheets. (HP LaserJet P1005)
{code}
procedure Print;
var
  ImgName: string;
  rect: TRect;
  jpg: TJPEGImage;
begin
  OpenPictureDialog1.Execute;
  ImgName := OpenPictureDialog1.FileName;

  rect := TRect.Create(Point(0, 0), Printer.PageWidth, Printer.PageHeight);

  jpg := TJPEGImage.Create;
  jpg.LoadFromFile(ImgName);

  Printer.BeginDoc;

  Printer.Canvas.StretchDraw(rect, jpg);

  Printer.EndDoc;

end;
{code}
I do not know what I should do. Help me please.

P.S. Sorry for my English.
0
Oleg
7/22/2013 9:55:04 AM
embarcadero.delphi.non-tech 5933 articles. 1 followers. Follow

6 Replies
2243 Views

Similar Articles

[PageSpeed] 44

Maybe you can try it in this way:

http://www.delphigroups.info/2/68/212878.html
0
Robert
7/22/2013 11:06:24 AM
Hello,

I don't see now exactly the reason why I changed to Windows API many years ago but this code is working for me in D7, XE, XE2

{code}
type
  TMyJpegImage = class(TJPEGImage)
  end;
procedure PrintJPEG(Canvas: TCanvas; X1, Y1, X2, Y2: Integer);
var
  B: TMyJpegImage;
  pt: TPoint;
begin
  B := TMyJpegImage.Create;
  try
    B.LoadFromFile(ImgName);
    GetBrushOrgEx(Canvas.Handle, pt);
    SetStretchBltMode(Canvas.Handle, HALFTONE);
    SetBrushOrgEx(Canvas.Handle, pt.x, pt.y, @pt);
    StretchBlt(Canvas.Handle, X1 + 1, Y1 + 1, X2 - X1, Y2 - Y1,       //<---- I don't see now why I used +1
      B.Bitmap.Canvas.Handle, 0, 0, B.Width, B.Height, Canvas.CopyMode);
  finally
    B.Free;
  end;
end;
{code}

Best Regards,
Cristian Peta

Edited by: Cristian Peta on Jul 22, 2013 3:07 PM
0
Cristian
7/22/2013 12:09:38 PM
Or better move PringJPEG procedure inside TMyJpegImage object. This is my old code that I must cleanup one day.

Best Regards,
Cristian Peta
0
Cristian
7/22/2013 12:23:06 PM
Thank you very much for your answers, but I still have a problem. I tried this code but I have error at *Printer.Canvas.Assign(canv);*
{code}
PROCEDURE PrintBitmap(Canvas: TCanvas; DestRect: TRect; Bitmap: TBitmap);
VAR
  BitmapHeader: pBitmapInfo;
  BitmapImage: POINTER;
  HeaderSize: DWORD;
  ImageSize: DWORD;
BEGIN
  GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
  GetMem(BitmapHeader, HeaderSize);
  GetMem(BitmapImage, ImageSize);

  TRY
    GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);

    StretchDIBits(Canvas.Handle, DestRect.Left, DestRect.Top,
      { Destination Origin }
      DestRect.Right - DestRect.Left, { Destination Width }
      DestRect.Bottom - DestRect.Top, { Destination Height }
      0, 0, { Source Origin }
      Bitmap.Width, Bitmap.Height, { Source Width & Height }
      BitmapImage, TBitmapInfo(BitmapHeader^), DIB_RGB_COLORS, SRCCOPY)
  FINALLY
    FreeMem(BitmapHeader);
    FreeMem(BitmapImage)
  END
END { PrintBitmap };

{ }

{ }
procedure PrintJPG;
CONST
  LOGPIXELSX = 88;
  LOGPIXELSY = 90;
  FilePath = 'F:\b.jpg';
VAR
  iPixelsPerInch: INTEGER;
  jPixelsPerInch: INTEGER;
  TargetRectangle: TRect;
  jpeg: TJPEGImage;
  pic: TPicture;
  canv: TCanvas;
begin
  jpeg := TJPEGImage.Create;
  pic := TPicture.Create;
  // canv:=TCanvas.Create;

  jpeg.LoadFromFile(FilePath);
  pic.Graphic := jpeg;

  iPixelsPerInch := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
  jPixelsPerInch := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
  Printer.Orientation := poPortrait;

  Printer.BeginDoc;

  TargetRectangle := Rect(3 * iPixelsPerInch, { 3" from left }
    2 * jPixelsPerInch, { 2" from top }
    7 * iPixelsPerInch, { 7" -- 7-3 = 4" wide }
    5 * jPixelsPerInch); { 5" -- 5-2 = 3" high }

  pic.Bitmap.Assign(jpeg);
  PrintBitmap(canv, TargetRectangle, pic.Bitmap);

  Printer.Canvas.Assign(canv);
  // access violation at 0x00467af7: read of address 0x00000064

  Printer.EndDoc;
end;

{code}
0
Oleg
7/22/2013 2:30:02 PM
I don't understand why you not use printers canvas for PrintBitmap() like this
{code}
   PrintBitmap(Printer.Canvas, TargetRectangle, pic.Bitmap);
{code}

And why do you need Printer.Canvas.Assign(canv). canv is nil.

Best Regards,
Cristian Peta
0
Cristian
7/22/2013 2:55:25 PM
You deleted the canv create..
> {code}
> begin
>   jpeg := TJPEGImage.Create;
>   pic := TPicture.Create;
>   // canv:=TCanvas.Create;
> 
>   Printer.Canvas.Assign(canv);
>   // access violation at 0x00467af7: read of address 0x00000064
> {code}

But I think you don't need this, just pass the printer canvas to:

PrintBitmap(Printer.Canvas, TargetRectangle, pic.Bitmap);
0
Robert
7/22/2013 3:04:12 PM
Reply:

Similar Artilces:

Problem with Delphi XE2 using parameters in SQL query [Edit]
Hello, I have problem with using SQL with parameters. This part of code works fine on Delphi 2007, but have Debugger Exception Notification in Delphi XE2 with ADOTmp do *//works fine on Delphi2007 and Delphi XE2, date value is inserted* begin SQL.Clear; *SQL.Add('UPDATE Table SET Date = ''2012-04-03 13:13:13'' ');* ExecSQL; end; with ADOTmp do *//works fine on Delphi2007* begin SQL.Clear; *SQL.Add('UPDATE Table SET Date = :D1 ');* Parameters.ParamByName('D1').DataType := ftDateTime; Parame...

Problem using InstallAware 7 CodeGear Special Edition with Delphi 2010 [Edit]
Hi Everyone, I am trying to create an installation disk for my delphi 2010 application using the installAware that kind of comes with Delphi 2010. When I try to built it, it keeps giving me the error message:- No files matching pattern "C:\Windows\system32\\*120.bpl" and when I look into my windows\system32 folder, there the files with extension *.bpl end with *140.bpl and not *120.bpl like it was expected. Can anyone tell me if I am doing something wrong or how I can get around this. Thanks in advance. Edited by: Tat Hon Chu on Dec 3, 2009 12:55 AM > {quo...

Delphi 2006 to Delphi XE Crystal BPL problem [Edit]
I am in the process of migrating our application from Delphi 2006 to Delphi XE and, for ease of use, I have both 2006 and XE installed on my development computer. I access Crystal Reports XI RDC in our application and so I rebuilt the BPL in XE in order to add the new package to XE. However, when I try to add the package to XE I get the error message: “Registration procedure, Craxddrt_tbl.Register in the package c:\Documents and Settings\All Uers\Documents\RADS Studio\8.0\BPL\Crystal.bpl raised exception class EFilerError: Component TDatabase can’t be registered by package crystal.bpl be...

converting delphi 2007 code to delphi XE2 -- emptyparam problem
Hi, I am trying to convert my applicantion code from delphi 2007 to delphi XE2 and i got stuck in this error "[DCC Error] ADODB_TLB.pas(4888): E2033 Types of actual and formal var parameters must be identical". This happens when we use emptyparam as an argument in a function that wants an olevariant. Example: function TAcadDatabase.CopyObjects(Objects: OleVariant): OleVariant; begin Result := DefaultInterface.CopyObjects(Objects, EmptyParam, EmptyParam); //this is where we get the ERROR end; The coyobjects function as this signature: " function CopyObjects(Object...

TDatamodule problem on Delphi XE2 [Edit]
I reported a problem to QC (#100324) that I think is related with this issue. I've a project that I'm trying to compile with Delphi XE2 and when I close the application or close a form that links to the datamodule where my main connection to Interbase database is located, I'm geting this error message: First chance exception at $0061BCEA. Exception class $C0000005 with message 'access violation at 0x0061bcea: read of address 0x80808088'. Process Fac2011.exe (5608) For example, I have a form with a TIBTransaction and a TIBQuery that are linked to a TIBDatabase that b...

Access to legacy (Delphi 4) Midas server from Delphi XE2 [Edit]
Hello, My company biggest product is developped with Delphi 4 and uses several Midas servers. It's a really big application (still in evolution, since 1997) , that has been started with Delphi 3. A partial or complete rewrite of this application is planned in a mid term future, and I must study if we can envisage a soft migration of some parts of the software on Delphi XE2 (or XE4), or if a complete rewrite even of the servers parts is required. If a complete rewrite must be done, my boss doesn't exclude to study the possibility of using another development environment to rewri...

Debugging in Delphi XE2 using another Delphi BDS process as host
Hi I've been using delphi a long time And I always had the possibility of debbuging Packages using another Delphi process as host. This is very useful to test the design-time side of packages. Now with XE 2 I can whether running with options - Debugger - Host Application or Attach to process Any ideas? Thanks Plp Pedro wrote: > Now with XE 2 I can whether running with options - Debugger - Host > Application or Attach to process What exactly are you having trouble with? Error messages, unexpected behavior, etc. -- Remy Lebeau (TeamB) Hi Remy ...

Delphi 7 to Delphi XE2
Hi, Still using that old workhorse, Delphi7, but am going to the conference in London hosted by Embarcadero on Delphi XE2. Although I would like to "move with the times" and am keen to get the UNICODE and 64-bit support offered by the latest IDEs, I confess to being more than a little scared about all the UNICODE/String/AnsiString and 32/64 bit issues I'm probably going to fall over. Anyone recently upgraded from Delphi7 to one of the latest Delphi IDEs? Thanks, Alain On 03/02/2012 08:55, Alain Dekker wrote: > Still using that old workhorse, Delphi7, but...

Problem using Delphi 6 with Windows 7 [Edit]
I have had all kind of problems with Delphi 6 and Windows 7. For example, when I try to open a TStringList file over a network drive I get the following error message (MyList.LoadFromFile(s:\info\tables\table.doc);): "--------------------------- Debugger Exception Notification -------------------------------------------------------------------------------- Project Tools_CREG.exe raised exception class EFOpenError with message 'Cannot open file ...\table.doc'. Process stopped. Use Step or Run to continue. --------------------------------------------------------------...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Delphi XE2 - Indy 10
Dear folks As result of security issues one of the email services in NZ has changed the settings of their email server. It used to be port 25 and outgoing mail was SMTP.xtra.co.nz. The port is now 465 and outgoing mail is now send.xtra.co.nz. The client configuration requires authentication and a secure connection (SSL). The result is that my code to connect for everyone using that provider is now "busted". I have changed the port and outgoing host accordingly. And have set the IOHandler of idSMTP as IdSSLIOHandlerSocketOpenSSL1. With the Authtype as satSASL. I have als...

Delphi XE2
I'm very excited about the Delphi XE2 update. We have a client server application using Midware from Fpiette. It has served us well for almost 10 years. That being said, Datasnap has been promising looking with Delphi 10 and XE, but with the XE2, I was really excited about the addition of HTTPS protocol being added to the server. The RSA/PC1 works good, but because some of our clients have strict firewall policies, https would solve alot of our headaches, making the application accessible without havi ng to deal with IIS. My problem: I created a test server and defined TCP, HTTP...

Delphi XE2, Indy 10
Dear folks The following code is supposed to send a text string to a client that is listening on a set port and ip address. The connection works fine. The problem is that nothing seems to be sent. {code} function TFCSelectForm.SendNitroMessage(NitroRequest: String): String; var sStrm: TMemoryStream; begin try sStrm := TMemoryStream.Create; try sStrm.WriteBuffer(Pointer(NitroRequest)^,Length(NitroRequest)); // sStrm shows as () in the debugger IdTCPClient1.IOHandler.Write(sStrm, 0, False); sStrm.Position := 0; finally ...

Delphi XE2 DLL can't be used in C# application [Edit]
For testing I am trying to call a Delphi XE2 DLL (see code) in a C# application (developed in Visual C# 2010 Express). procedure CLP; stdcall; export; begin showmessage('TEST'); end; exports CLP; However when trying to add the DLL as reference to a C# project the following message appears: "A reference to 'D:\temp\test.dll' could not be added. Please make sure that the file is accessible, and that is a valid assembly or COM component." When the same DLL is compiled under Delphi 2010 it works without any problem. Any suggestions how to solve the p...

Web resources about - Problem with printing, using Delphi XE2 [Edit] - embarcadero.delphi.non-tech

Printing - Wikipedia, the free encyclopedia
This article is about the process of reproducing text and images. For the handwriting method often called printing, see block letters . For other ...

Microsoft Outlook for iOS updated with 3D Touch and email printing
... a new event, and viewing your calendar. via iDownloadBlog Print The new version of Microsoft Outlook for iOS also adds support for printing. ...

Gelato Group Is Here To Democratize The World of Printing
... winning the Oslo Innovation Award 2015, we sat down with Henrik Müller-Hansen, Founder and CEO of Gelato Group. What Does Democratizing Printing ...

Apple Looks to Bring Multiple Colors to 3-D Printing with Patent Filing
... of an application by Apple ( AAPL ) for a 3-D Printer technology. The application for “systems, computer readable media, and methods for printing ...

"After the exodus of editors from The New Republic last year, the magazine is printing things like this..." ...
"'Ban guns. All guns. Get rid of guns in homes, and on the streets, and, as much as possible, on police.... Ban guns! Not just gun violence. ...

Baker to inquire about report ISIS printing passports
... for Syrian refugees entering the U.S., says he "certainly" will ask federal officials about an ABC News report indicating ISIS has been printing ...

How does Jay Leno get parts for his one-of-a-kind concept car? 3D printing, of course
The former talk-show host and massive car geek relies on new manufacturing techniques to provide parts you can't just pick up on Alibaba.

3D printing can recreate your vascular system for pre-op practice
... technology. With that in mind, physicians and researchers in Buffalo have worked with 3D printer maker Stratasys to develop a method of printing ...

3D printing files for guns are illegal in an Australian state
The Australian state of New South Wales has made it illegal to possess the blueprints necessary to make your own projectile weapons. Lawmakers ...

Is ISIS printing fake Syrian passports?
Is ISIS printing fake Syrian passports?

Resources last updated: 12/20/2015 10:13:31 AM