Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

own qrImage in delphi 3

Hi,
I'm trying to make a qrimage that uses stretchdib to print
something to enhance greatly the quality of the printed images. My problem is that I can't get the image
to print at the right size specified in the size property
of the components.

Here is the component, it is working except that the print
sizes are not accurate. What can I do ?

thanks for your help.
Here follows the source code:

------------------------------------------------
unit qrji;

interface

uses classes, quickrpt, Qrctrls, windows, graphics, dialogs;

type
     TQRJImg = class(TQRImage)
     public
          constructor Create(AOwner: TComponent); override;
          procedure Print(OfsX, OfsY: integer); override;
     end;

procedure Register;

implementation

procedure DrawImage(Canvas: TCanvas; DestRect: TRect; ABitmap: TBitmap);
var
     Header, Bits: Pointer;
     HeaderSize: Integer;
     BitsSize: Longint;
     test: integer;
begin
     GetDIBSizes(ABitmap.Handle, HeaderSize, BitsSize);
     getMem(Header, HeaderSize);
     getMem(Bits, BitsSize);
     try
          GetDIB(ABitmap.Handle, ABitmap.Palette, Header^, Bits^);
          test := StretchDIBits(Canvas.Handle, DestRect.Left, DestRect.Top,
               DestRect.Right, DestRect.Bottom,
               0, 0, ABitmap.Width, ABitmap.Height,
               Bits, TBitmapInfo(Header^),
               DIB_RGB_COLORS, SRCCOPY);

          if test = 0 then
               MessageDlg('Sorry, but one of your cover will not be printed' + #13 + #10 + 'Maybe of a lack of memory.' + #13 + #10 + 'Try to reduce the printing resolution.'
                    + #13 + #10 + ''
                    + #13 + #10 + 'Go ahead anyway ?', mtError, [mbYes, mbNo], 0);
     finally
          FreeMem(Header);
          FreeMem(Bits);
     end;
end;

constructor TQRJImg.Create(AOwner: TComponent);
begin
     inherited Create(AOwner);
end;

procedure TQRJImg.Print(OfsX, OfsY: integer);
var
//     CalcLeft,
//          CalcTop,
//          CalcRight,
//          CalcBottom: Longint;
//     checked: boolean;
     dest:trect;
begin
     with ParentReport.QRPrinter do
     begin
          with dest do
          begin
               Top := YPos(OfsY + Size.Top);
               Bottom := YPos(OfsY + Size.Top + Size.Height);
               left := XPos(OfsX + Size.Left);
               right := XPos(OfsX + Size.Left + Size.Width);
          end;
          drawImage(Canvas, dest, picture.Bitmap);
     end;
end;

procedure Register;
begin
     RegisterComponents('QReport', [TQRJImg]);
end;

end.

0
jeurk
Asked:
jeurk
  • 6
  • 6
1 Solution
 
ZifNabCommented:
hi jeurk,

What about streching the picture to printer dimensions, when printing?

Regards, Zif.
0
 
ZifNabCommented:
Hi jeurk,

this is some code I've used one day, maybe you can change it to your needs....

var ScaleX, ScaleY : integer;

with metacnvase do begin
 ScaleX := GetDeviceCaps(Printer.Handle, logPixelsX) div PixelsPerInch;
 ScaleY := GetDeviceCaps(Printer.Handle, logPixelsY) div PixelsPerInch;
end;

 ARect:= rect(0,0,MetaPage.Width*ScaleX, MetaPage.Height*ScaleY);

Regards, ZiF.
0
 
MatveyCommented:
Do I understand you right: you want to print stretched images ??

If so, I can suggest you to use the Wang OCXes that have such options.
(-They're free...)

Regards,
bosism@netvision.net.il
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
jeurkAuthor Commented:
Hi guys,
Did you took a look at my code ?
I am printing stretched images.
All is working right. Except that the printed image has
not the right size.
here:
with ParentReport.QRPrinter do
         begin
              with dest do
              begin
                   Top := YPos(OfsY + Size.Top);
                   Bottom := YPos(OfsY + Size.Top + Size.Height);
                   left := XPos(OfsX + Size.Left);
                   right := XPos(OfsX + Size.Left + Size.Width);
              end;

I'm using qreports functions to get the right sizes.
The params of the print function are OfsX and OfsY those
are the printer coords where I should print. Qreport is giving
them to me.
after that I have to get the right width and height, here I do use
Xpos and Ypos that makes the right conversion for me, like your
code Zif.
What I was asking was, if you would understand it better the me,
let's change My component source code to make it print right.
I don't think we need ocx's or others functions, do we ?

Thanks for the help guys, let's finish the work.

Jeurk.
0
 
ZifNabCommented:
Maybe I'm stupid, but can you define 'not correct size' better...?
Is the Top place not good, are the widths of the drawing bad?

I can't see what's wrong with your code, ...

      ImRect:=Rect( Xpos(OfsX+Size.Left),
                       Ypos(OfsY+Size.Top),
                       Xpos(OfsX+Size.Left+Size.Width),
                       Ypos(OfsY+Size.Top+Size.Height));

     Canvas.StretchDraw(ImRect, Bitmap);
    or Canvas.Draw(XPos(OfsX+SIze.Left),Ypos(OfsY+Size.Top),Bitmap);

Regards, ZiF.
0
 
jeurkAuthor Commented:
Your not stupid Zif ;)
If someone is stupid it must be me ;)
It's the widths of the drawing that are bad,
AMybe you could try the component out and let me
know if you have the same problem,
maybe it's only a problem on my printer ?
Have you tryed it ?
If You try it out make sure you print the thing,
a preview is not enough, the preview differs from the
print.

Please let me know.
Thanks.

0
 
ZifNabCommented:
Hi jeurk,

I've got a component which handles it's printing with QR the same. I have no problems with it... Which printer do you use AND which version of QR do you use?

Regards, ZIF.
0
 
jeurkAuthor Commented:
Hi Zif,
can I take a look at that component ?
mailto://knipjo@citeweb.net

Thanks
0
 
jeurkAuthor Commented:
by the way,
I'm using qr 2.0g and delphi 3.02 ;)

0
 
jeurkAuthor Commented:
To better illustrate my problem, I made a little project that I
can send to you if you want.

You'll have to install my component.
After that look what it is printing. Normally the too images should
print at the same size, but they don't. The first is my component
the second is the standard qrimage component. So what shall I do
for them to print at the same size ?

0
 
ZifNabCommented:
Hi jeurk,

The component is QR component of TeeChart

Mmm, I think you better download QR 2.0k ... I know of some bugs in QR of printing pictures.

No problem, you may send me the code... (But I'm going home now, so I can't check it till tomorrow). Tom.Deprez@uz.kuleuven.ac.be

Regards, Zif.
0
 
jeurkAuthor Commented:
Hello zif,
The prooblem is no more,
I installed QR2.0j and now the qrimage is doing what I want from his own.
Let's answer that question so I can give you the points. You gave time, you earn points ;)
(thank you too matvey)
Regards.
0
 
ZifNabCommented:
Thanks jeurk,

To answer the qsuestion :

Mmm, I think you better download QR 2.0k ... I know of some bugs in QR of printing pictures in earlier versions.

PS. Why j instead of newer version k? k is already out of beta.

Regards, ZiF.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now