This project is read-only.

GDIPlusX - Print Screen in Vista

Mar 29, 2008 at 9:29 AM
Hello,
I have created a print screen option that works great on XP.
But when I run the same routine on Vista, all I get is a black image.

Here is my code:
with _screen.system.drawing
loBmp = .Bitmap.FromScreen(_screen)
loBmp.save('prntscrn.jpg', .Imaging.ImageFormat.jpeg)
endwith

In XP, the jpg file is file, but in Vista all I get is a jpg that is completly black.

Can anyone help with this Vista problem ?
Thanks,
Kent
Apr 1, 2008 at 11:46 AM
Hi Kent,

Just tried the following on this side with Vista Ultimate... everything worked fine. I'm not sure what is going wrong on your end - I do run Visual FoxPro as Administrator. Can you check and see whether elevated permissions might be the difference?

DO LOCFILE("System.app")
with _screen.system.drawing
loBmp = .Bitmap.FromScreen(_screen)
loBmp.save('C:\prntscrn.jpg', .Imaging.ImageFormat.jpeg)
endwith
Apr 1, 2008 at 8:57 PM
Hello Craig,
Thanks for testing this code. I just tried again and no luck. I ran the EXE as administrator but still get a black image.
I copied your code and run it from VFP9 command window and it worked, so something is weird.
The program works fine on XP, just not Vista. I have tried many variations in my code but no luck yet.

Here is my code:
local loBmp, lcScreenCapture
lcScreenCapture = oApp.TempPath + "ScreenCapture.jpg"
if file(lcScreenCapture)
erase (lcScreenCapture)
endif
WITH _SCREEN.System.Drawing
loBmp = .Bitmap.FromScreen(_screen)
loBmp.Save(lcScreenCapture, .Imaging.ImageFormat.Jpeg)
endwith

basically same code as yours ... very weird.


craigsboyd wrote:
Hi Kent,

Just tried the following on this side with Vista Ultimate... everything worked fine. I'm not sure what is going wrong on your end - I do run Visual FoxPro as Administrator. Can you check and see whether elevated permissions might be the difference?

DO LOCFILE("System.app")
with _screen.system.drawing
loBmp = .Bitmap.FromScreen(_screen)
loBmp.save('C:\prntscrn.jpg', .Imaging.ImageFormat.jpeg)
endwith


Apr 29, 2008 at 5:33 PM
Kent,

Did you ever get this sorted out? I'm curious to know whether or not you figured out what the problem was. Thanks.
Apr 30, 2008 at 1:18 AM
Hello Craig,
Thanks for asking, yes I got it working after much trial and error. Not sure what the magic fix was, but I moved my code from a procedure to the INIT of a form and then display the print screen image and allow the user to print the image or not. I also changed the capture code to:
WITH _SCREEN.System.Drawing
loBmp = .Bitmap.FromScreen()
loBmp.Save('PrintScreen.jpg', .Imaging.ImageFormat.Jpeg)
endwith

This works, but I would have liked to get just the active screen but could not get that work work.
Thanks for your help and all you are doing for the Fox ...
Kent
Apr 30, 2008 at 12:22 PM
Hi Rocket,

To capture a form, all you need is to pass one parameter:
Please try the following:

WITH _SCREEN.System.Drawing
loBmp = .Bitmap.FromScreen(Thisform) && Could be also: Thisform.Hwnd
loBmp.Save('PrintScreen.jpg', .Imaging.ImageFormat.Jpeg)
endwith

Hope this helps !
May 16, 2008 at 8:09 PM
VfpImaging, I don't see how your example code is different than that which Rocket posted. I still don't understand what Rocket was running into here. Perhaps I will touch base with Bo and point him to this discussion. Maybe he'll have an idea.
May 16, 2008 at 10:54 PM
Edited May 17, 2008 at 2:19 AM


craigsboyd wrote:
I don't see how your example code is different than that which Rocket posted. I still don't understand what Rocket was running into here. Perhaps I will touch base with Bo and point him to this discussion. Maybe he'll have an idea.


See again what Kent said in his last post:
"but I would have liked to get just the active screen but could not get that work work."

I understand from that that he captured the whole _Screen, and he wanted to obtain just the form image.

In his example, he called the "FromScreen" method this way:


     loBmp = .Bitmap.FromScreen()


See that he did not send any parameter to the function ?
When we created "FromScreen", it was set that when it did not receive any parameter, the main Screen would be captured.
So, I suggested that he could send some parameters to this function in order to capture exactly the portion he wanted.

For his case, I suggested passing "Thisform" or the form HWND, in order to capture only the form he wanted.


loBmp = .Bitmap.FromScreen(Thisform) && Could be also: Thisform.Hwnd






Actually, "FromScreen" accepts other parameters too.
The one I most like is that you can pass any VFP object to it.

This way, supposing you have a container inside your form, and you want to capture only the image of the container, you can call this way:


loBmp = .Bitmap.FromScreen(Thisform.Container1)





I hope I was clear this time

Regards

Cesar

May 17, 2008 at 8:53 PM
VfpImaging,

I see what you're saying now. Thank you for the clarification. What causes the completely black image is still a mystery. I've pointed Bo towards this thread, hopefully he'll respond soon.
May 20, 2008 at 2:29 AM
Edited May 20, 2008 at 2:30 AM
The sample code works for me in Vista (Business). I am not sure what would cause the all black image unless one of the API calls failed. In looking at the source for the "FromScreen" method we could add some more error trapping and at least provide an error message or a NULL Bitmap if any of the API functions fail. This would at least give you soemthing to "trap" for.
May 20, 2008 at 2:09 PM
Edited May 20, 2008 at 2:20 PM
I'd like to know where he put that code in the first moment.
I use the "capture" function a lot, and never faced this problem of the blank capture.

In Vista Home and Vista Starter Edition it works normally, tested in EXE, with some procedures inside forms and also in a PRG that handles errors.

We need more details, like:
Was the capture code in the Load event? In "Load" the form is still invisible...
Is he using the _screen.Visible = .F. ?


Are there toolbars in the form ?
Is it a TopLevelForm ?
Maybe we should handle these cases too, because the HWND changes for these two cases.
May 20, 2008 at 2:26 PM


binarybo wrote:
The sample code works for me in Vista (Business). I am not sure what would cause the all black image unless one of the API calls failed. In looking at the source for the "FromScreen" method we could add some more error trapping and at least provide an error message or a NULL Bitmap if any of the API functions fail. This would at least give you soemthing to "trap" for.


Hi for all (Bo, Cesar and Craig).
A long time ago, in Outlook2003Bar times, I have problems using GDIPlus.dll directly.
In some machines, when I try to create gradient images, I only get black images.
Cesar helped me and found that the problem's cause was that there are more than one copy of GDIPlus.dll installed with different versions.
To fix the problem he suggested to include .dll extension in the api declaration and it solved the problem.
Maybe this also could be the cause of black images in GDIPlusX.

Hope it help.
May 20, 2008 at 4:36 PM
Edited May 22, 2008 at 3:45 PM
Hello,
Sorry I have not posted sooner. I have the code working now but not exactly the way I would like it.

I wanted to create a print screen option so a user can hit a key and print the screen. When I first wrote the code it worked fine on XP but when I tested it on my Vista Home Premium laptop it would give me a black image.

Here is what I was trying to do. I mapped the F12 key to a print screen function in my tools.prg where all my global functions are stored.
I wanted to remap the "Print Screen" button but I could never figure out how to remap it so I settled for the F12 key ...

on key label F12 to RockPrintScreen()

Then i my global tools.prg here is the original function:

function

RockPrintScreen
local loBmp, lcScreenCapture
lcScreenCapture
= oApp.TempPath + "ScreenCapture.jpg"
WITH _SCREEN.System.Drawing
     * Variables to store the new Image size
     * loBmp = .Bitmap.FromScreen()
     *you can also use this syntax to capture the current form
     * loBmp = .Bitmap.FromScreen(Thisform)
     *or this syntax to capture the vfp screen area
     loBmp = .Bitmap.FromScreen(_screen)
     * Save to JPG File
     loBmp.Save(lcScreenCapture, .Imaging.ImageFormat.Jpeg)
ENDWITH
if file(lcScreenCapture)
   do form PrintScreen with lcScreenCapture
endif
return
endfunc

I wanted to use thisform but it is not valid inside a prg in my tools.prg so I settled for _screen as the parameter.
Like I said it worked fine on XP but on Vista all I got was a black image.

The form PrintScreen just displays the image that was created and gives the user a button to print the image.

I have since moved the image capture code to the init of the PrintScreen form and now I don't get the black image.
I tried all the different options and the one that worked the best was .FromScreen() without any parameters.
.FromScreen(thisform) did not capture the entire form and .FromScreen(_screen) captured more but still not the entire form.

So I had to settle for .FromScreen() without parameters.

If anyone has any ideas on how to make a print screen routine that would just capture the current form that would be great.
Thanks for everyones help,
Kent

 

 

 

 

 

May 28, 2008 at 10:16 PM
Is anyone else on VFPX able to reproduce what Rocket is seeing? I am not able to reproduce this on Vista Ultimate.