This project is read-only.

fit picture to frame / gdiPlusx

Topics: Bug Information, General
Dec 21, 2008 at 8:21 PM
Edited Dec 21, 2008 at 8:22 PM
Hi All
Am using gdiplusx ( in our vfp9 application. am having some weird problem printing a scanned document. i tries all different combinations (on this page) for "ToPrinter" method but cannot get picture to print full page photo on A4. if i use "Clip" constants it blows a part of image and prints only small part on A4. if i use "Isometric" settings it prints small image rather than fitting page.

btw if i print from any other windows application it works as expected.
any advise is greatly appreciated.
Mar 12, 2009 at 4:00 AM
any one got any advise for me please ? it still a problem. let me know if u need any further info. thanks
Mar 12, 2009 at 7:45 AM
Hi sqlpro,

It might be helpful to see some of the code that you are using, or even a small/concise snippet that we could use to reproduce the problem. Without code it's not apparent how your image object is set up nor what the size of the image is that you are dealing with, nor can things such as the orientation or alignment parameters be ascertained based on your post. I've asked Bo to take a look at it and he is doing so even as I am replying to you here. If he locates an issue with the ToPrinter method I am sure he will post back to you here. If the problem is with your code/image object then we will need to get some idea of what exactly you are doing prior to and upon calling the ToPrinter method before a solution can be proposed.
Mar 12, 2009 at 8:59 PM
Edited Mar 12, 2009 at 9:01 PM
thanks for reply craig. am not doing anything fancy just using toprinter() method and trying different settings. see my code below

DO LOCFILE("","app","Locate file")
WITH _Screen.System.Drawing
       LOCAL loBmp as xfcBitmap
       m.loBmp = .Bitmap.FromFile(tcFileName)

the variable lcprintsettings contains different settings toprinter() accepts but i tried with out setting parameters also. unfortunately i cant seem to upload files to the discussion here but hopefully i explained problem clearly.

All i want is when i print image it stretches to fit the page nicely without shrinking whole image OR enlarging a particular part of image. thanks for the advise

Mar 14, 2009 at 2:56 PM

Please send me the values that you have in your variable "lcPrinterSettings". All your problem will be solved passing the correct parameters.

Below is a list of the "ToPrinter()"documentation, please try changing the 1st parameter using integer values between 0 and 2:
More info here:



            Sends the image object to the Printer<O:P></O:P>


Parameters: tnStretch, tcPrinterName, tnOrientation, tnAlignment<O:P></O:P>



                        *   Specifies how an image is sized to fit inside a control.<O:P></O:P>

                        *   0 - Clip. The image is clipped to fit the page. (Default)<O:P></O:P>

                        *   1 - Isometric. The image resizes to fit the page while maintaining its original proportions.<O:P></O:P>

                        *   2 - Stretch. The image resizes to fit the page, but does not maintain its original proportions.<O:P></O:P>



                        *   Specifies the name of the printer, the same of GETPRINTER()<O:P></O:P>



                        *   0 - Portrait<O:P></O:P>

                        *   1 - Landscape<O:P></O:P>



                        *   Specifies a numerical value representing the alignment of the image in the page.<O:P></O:P>

                        *   0 - Vertically Centered Left.<O:P></O:P>

                        *   1 - Vertically Centered Right.<O:P></O:P>

                        *   2 - Centered. Centers image vertically and horizontally.<O:P></O:P>

                        *   4 - Top Left. Aligns image in top left corner of the page.<O:P></O:P>

                        *   5 - Top Right. Aligns image in top right corner of the page.<O:P></O:P>

                        *   6 - Top Center. Aligns image at the top and horizontally centered on the page.<O:P></O:P>

                        *   7 - Bottom Left. Aligns image in the bottom left corner of the page.<O:P></O:P>

                        *   8 - Bottom Right. Aligns image in bottom right corner of the page.<O:P></O:P>

                        *   9 - Bottom Center. Aligns image at the bottom and vertically centered on the page.<O:P></O:P>

<O:P> </O:P>

            Returns: Nothing<O:P></O:P>



            Code sample:<O:P></O:P>




WITH _Screen

loBmp as xfcBitmap
   loBmp = .


<O:P> </O:P>


Mar 15, 2009 at 8:42 PM
Hi there
like i mentioned in my original post, i tried all possible combinations with the parameters mentioned in the mentioned link. unfortunately i cant attach any images here but issue easy to replicate. try to print an image (using GDI+) and print full page and print another copy using windows built in viewer and see the difference.
Mar 15, 2009 at 8:46 PM
by the way out of all the parameters (toprinter()) Isometric seems to be logical one but unfortunately it leaves out quite big margins making image smaller. our clients do scan in lot of documents and reading these becoming difficult after print out.
Mar 16, 2009 at 1:15 AM
Edited Mar 16, 2009 at 1:22 AM

If the borders are a problem to you, then I would recommend you to customize the original function, because in that function before printing I'm getting the margins that are set for the current or selected printer. If you need to bypass it, you need to customize that function.

Follow these steps:

1 - download the sources of GdiPlusX.
2 - open the file "System.Drawing.prg"
3 - look for the "ToPrinter" method
4 - Copy and paste these codes to a new PRG or function, call it ToPrinterX
5 - When you find "This." replace with your current xfcBitmap object
6 - Finally, comment the lines below:

* Adjust coordinates to start after the TopLeft margin
x = x + lnHorOffSet
y = y + lnHorOffSet 


Feel free to call again if you need any other help with this.

Mar 16, 2009 at 1:22 AM
thanks for  that,will look into it. what i've not followed is , you say, you set margins based on selected printer if thats the case when i print same image using windows photo editor how it prints whithout those big margins ?

Mar 17, 2009 at 2:30 AM
Hi there
i tried what you suggested but to no avail yet. but i noticed couple of things. In toprinter() method why you are always getting default printer properties (ie. PRTINFO()) ? even though this function has parameter for a printer which may not be default printer. ofcourse i tried to pass 2nd parameter (ie. printer name) to this foxpro command but made no difference in printing though.

the other thing when i extracted it to separate prg it was complaining abt following line (error : unknown property setstatus)
This.SetStatus(xfcGdipCloneImage(This.Handle, @lhobject))

btw can you explain why you need to adjust paper size like below (divide by 2.54)?
* Adjust page Width and Height
m.lnPageWidth = (m.lnPageWidth / 2.54)
m.lnPageHeight = (m.lnPageHeight / 2.54)

any insight much appreciated.
Mar 17, 2009 at 1:47 PM

I'm out of town for the whole day, so  can't make tests here...

>>This.SetStatus(xfcGdipCloneImage(This.Handle, @lhobject))

Just replace it with:
=xfcGdipCloneImage(This.Handle, @lhobject)

Every time that you see "This." replace with the Bitmap object that you want to print.
That means that it could be also:

loBmp.SetStatus(xfcGdipCloneImage(This.Handle, @lhobject))

Thanks for testing this.
In fact, I just saw that the version that was released for this function is not the latest, there seem to have been a confusion between us. I probably forgot to update the "SourceCode" version at that time.

Later during this week I'll try to revise this method, and upload an updated, but NON OFFICIAL version of the GdiPlusX.App file with this fix and a couple of others that I have.



Mar 17, 2009 at 8:39 PM
wonderful, thanks for that Cesar. cant wait for the final build :)
Mar 18, 2009 at 4:01 AM
to Update you on this, i did further testing on this and i think i got what wanted. i commented following code lines to print full page without any margins ! finally ;o)

commented lines:-
* Adjust paper size
lnPageWidth  = lnPageWidth  - (2 * lnHorOffSet)
lnPageHeight = lnPageHeight - (2 * lnVertOffSet)

* Adjust coordinates to start after the TopLeft margin
x = x + lnHorOffSet
y = y + lnHorOffSet