Alaska Software Inc. - Save screen to BMP(JPG,GIF,PNG)
Username: Password:
AuthorTopic: Save screen to BMP(JPG,GIF,PNG)
Slavko SlavicSave screen to BMP(JPG,GIF,PNG)
on Sat, 15 Dec 2018 00:50:41 +0100
Hi!
Please help!
Why this is NOT working under Windows 10, 64 bit.
Windows 7, 64 bit is OK.
Thanks, Slavko!

*-------------------------------------------------------------------------------
#include "Gra.ch"
#include "Xbp.ch"
#include "Appevent.ch"

    #include "Appevent.ch"
    #include "Common.ch"
    #pragma Library( "XppUi2.lib" )
    PROCEDURE AppSys
     //fSaveScr2Bmp()

    RETURN
    PROCEDURE Main
       LOCAL nEvent, mp1, mp2, oXbp, oBrowse, cField, i
       oXbp := GuiStdDialog( "Standard GUI" )
       fSaveScr2Bmp(oXbp,oXbp:drawingArea)
       DO WHILE nEvent <> xbeP_Close
          nEvent := AppEvent( @mp1, @mp2, @oXbp )
          oXbp:handleEvent( nEvent, mp1, mp2 )
       ENDDO
    RETURN
*-----------------------------------
    FUNCTION GuiStdDialog( cTitle )
       LOCAL oDlg
       DEFAULT cTitle TO "Standard Dialog Window"
       oDlg          := XbpDialog():new( ,,{100,100}, {200,200},, .F. )
       oDlg:icon     := 1
       oDlg:taskList := .T.
       oDlg:title    := cTitle
       oDlg:create()
       oDlg:show()
       oDlg:drawingArea:setFontCompoundName( "8.Helv" )
    RETURN oDlg
*-----------------------------------------------------------------------
FUNCTION fSaveScr2Bmp(oProg,oPare)
LOCAL oPS,oBitmap,oPS1,oBitmapC
LOCAL nXof:=0,nYof:=0,nCompr:=0 //no compresion
LOCAL aPosBmp,aSizBmp,cNamBmp:='test.jpg',nBits:=1,nTransc:=1
         aPosBmp:={200,200}
         aSizBmp:={1200,800}
         cNamBmp:='test.jpg'
         nBits:=1
         nTransc:=1
       //oProg:=AppDesktop():childFromName(1)
       //oPare:=AppDesktop():childFromName(1):drawingArea
         oPS:= XbpPresSpace():new()
         oPS:create(oPare:winDevice())
         oBitmap := GraSaveScreen(oPS,aPosBmp,aSizBmp,1,nBits,nTransC)
         Erase(cNamBmp)
         oBitmap:SaveFile(cNamBmp,XBPBMP_FORMAT_JPG,nCompr)
         oBitmap:destroy()
         oPS:destroy()
RETURN NIL
*-------------------------------------------------------------------------------
FUNCTION GraSaveScreen( oSourcePS, aPos, aSize,nPM,nBits,nTransC)
       LOCAL oBitmap   := XbpBitmap():new():create( oSourcePS )
       LOCAL oTargetPS := XbpPresSpace():new():create()
       LOCAL aSourceRect[4], aTargetRect
       aSourceRect[1] := aSourceRect[3] := aPos[1]
       aSourceRect[2] := aSourceRect[4] := aPos[2]
       aSourceRect[3] += aSize[1]
       aSourceRect[4] += aSize[2]
       aTargetRect    := {0, 0, aSize[1]*nPM, aSize[2]*nPM}
       oBitmap:presSpace( oTargetPS )
       oBitmap:make( aSize[1]*nPM, aSize[2]*nPM )
       GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect )
RETURN oBitmap
*-------------------------------------------------------------------------------


test1812.prg
slavko_slavic.vcf
Jim LeeRe: Save screen to BMP(JPG,GIF,PNG)
on Sun, 16 Dec 2018 01:40:18 +0100
hi,

> Why this is NOT working under Windows 10, 64 bit.
> Windows 7, 64 bit is OK.

what on Screen do you want to save as Image ?
is it part of your Xbase++ App or external App ?

when i run your Sample i got a Bitmap which show me Background of Desktop or
Explorer (where i start it)



---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com
Jim LeeRe: Save screen to BMP(JPG,GIF,PNG)
on Sun, 16 Dec 2018 08:54:27 +0100
>  oPS:= XbpPresSpace():new()
>  oPS:create(oPare:winDevice())

these line are not correct

   o:winDevice() --> oWindowDC

you try to assign a XbpPresSpace to Device-Context instead of get
(Micro-)PresSpace from Object

---

Question : do you want to make a SnapShot from DeskTop() ?



---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com
Slavko SlavicRe: Save screen to BMP(JPG,GIF,PNG)
on Sun, 16 Dec 2018 22:43:58 +0100
Hi Jim!
Thanks!
Yes, I want to save (JPG,BMP,PNG)part of screen (i.e. some graphics 
which I made before).
I know it is possible to save graphics directly to file,
but in this case it is to demanding.
What should be instead this two lines.
Interesting, it is working fine under W7,64

Best regards S.


Jim Lee wrote:
>>  oPS:= XbpPresSpace():new()
>>  oPS:create(oPare:winDevice())
>
> these line are not correct
>
>    o:winDevice() --> oWindowDC
>
> you try to assign a XbpPresSpace to Device-Context instead of get
> (Micro-)PresSpace from Object
>
> ---
>
> Question : do you want to make a SnapShot from DeskTop() ?
>
>
>
> ---
> Diese E-Mail wurde von AVG auf Viren geprüft.
> http://www.avg.com
>


slavko_slavic.vcf
Jim LeeRe: Save screen to BMP(JPG,GIF,PNG)
on Mon, 17 Dec 2018 04:17:24 +0100
> Yes, I want to save (JPG,BMP,PNG)part of screen (i.e. some graphics
> which I made before).
> I know it is possible to save graphics directly to file,
> but in this case it is to demanding.
> What should be instead this two lines.

*  oPS:= XbpPresSpace():new()
*  oPS:create(oPare:winDevice())

   oPS := oPare:LockPS()
   aPosBmp := {0,0}
   aSizBmp := oPare:CurrentSize()

   oBitmap := GraSaveScreen(oPS,aPosBmp,aSizBmp,1,nBits,nTransC)
   Erase(cNamBmp)
   oBitmap:SaveFile(cNamBmp,XBPBMP_FORMAT_JPG)    //,nCompr)
   oBitmap:destroy()

*  oPS:destroy()
   oPare:UnLockPS()



---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com
Slavko SlavicRe: Save screen to BMP(JPG,GIF,PNG)
on Tue, 18 Dec 2018 13:43:22 +0100
Hi Jim!
Not working.
What I made wrong?

         aPosBmp:={0,0}
         aSizBmp:=oPare:currentSize()
         cNamBmp:='test.jpg'
         oPS:=oPare:lockPS()
         oBitmap := GraSaveScreen(oPS,aPosBmp,aSizBmp,1,nBits,nTransC)
         Erase(cNamBmp)
         oBitmap:SaveFile(cNamBmp,XBPBMP_FORMAT_JPG) //,nCompr)
         oBitmap:destroy()
         oPare:unlockPS()
       //oPS:destroy()


Jim Lee wrote:
>> Yes, I want to save (JPG,BMP,PNG)part of screen (i.e. some graphics
>> which I made before).
>> I know it is possible to save graphics directly to file,
>> but in this case it is to demanding.
>> What should be instead this two lines.
>
> *  oPS:= XbpPresSpace():new()
> *  oPS:create(oPare:winDevice())
>
>    oPS := oPare:LockPS()
>    aPosBmp := {0,0}
>    aSizBmp := oPare:CurrentSize()
>
>    oBitmap := GraSaveScreen(oPS,aPosBmp,aSizBmp,1,nBits,nTransC)
>    Erase(cNamBmp)
>    oBitmap:SaveFile(cNamBmp,XBPBMP_FORMAT_JPG)    //,nCompr)
>    oBitmap:destroy()
>
> *  oPS:destroy()
>    oPare:UnLockPS()
>
>
>
> ---
> Diese E-Mail wurde von AVG auf Viren geprüft.
> http://www.avg.com
>


test.w10.jpg
test.w7.jpg
slavko_slavic.vcf
Jim LeeRe: Save screen to BMP(JPG,GIF,PNG)
on Tue, 18 Dec 2018 21:58:49 +0100
hi,

> Not working.
> What I made wrong?

are you painting on oPare ?
are you using oPare:Paint Callback Slot ?

is you Image stable when minimize/normalize ?

---

other Way is to use "Print Screen" and than GraBitBlt() what you want





---
Diese E-Mail wurde von AVG auf Viren geprüft.
http://www.avg.com