Screen grabber in Alaska

This forum is for eXpress++ general support.
Message
Author
User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Screen grabber in Alaska

#1 Post by Eugene Lutsenko »

Is there in Alaska a function or program that provides a Screen grabber is the active window and allows to save the image as a file?

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Screen grabber in Alaska

#2 Post by rdonnay »

No, there is not a function. I had to write my own function:

Code: Select all

FUNCTION GraSaveScreen( oSourcePS, aPos, aSize )

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], aSize[2]}

oBitmap:presSpace( oTargetPS )
oBitmap:make( aSize[1], aSize[2] )

GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect )

RETURN oBitmap
The eXpress train is coming - and it has more cars.

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Screen grabber in Alaska

#3 Post by Cliff Wiernik »

There are some additional samples under xbpbitmap in the alaska help file.

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Screen grabber in Alaska

#4 Post by Eugene Lutsenko »

Hello, everyone!!!

The function apply like this:

oBitmap := GraSaveScreen( oPS, oStatic1:CurrentPos() , oStatic1:CurrentSize() )
oBitmap:SaveFile(cFileName)

Sorry again, black screen. I don't know what to do... While I display charts one by one and do Alt+PrnScreen

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: Screen grabber in Alaska

#5 Post by Auge_Ohr »

Eugene Lutsenko wrote: oBitmap := GraSaveScreen( oPS, oStatic1:CurrentPos() , oStatic1:CurrentSize() )
oBitmap:SaveFile(cFileName)
hm ... what is your oPS ?
greetings by OHR
Jimmy

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Screen grabber in Alaska

#6 Post by Cliff Wiernik »

This is what I use to capture the current dialog from the screen.


*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±± // PC CAW 12-30-05 modified to not do winapi printscreen if object passed
*+
*+ Function LB_Scrn2ClipBoard( oXbp )
*+
*+ Copies the specified object (oXbp) to clipboard or the application
*+ Application desktop if not specified
*+
*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
*+
FUNCTION LB_Scrn2ClipBoard( oXbp )

LOCAL oSourcePS, oBitmap, oClipBoard, aPos

oSourcePS := oXbp:lockPS()

IF oXbp:isDerivedFrom('XbpDialog')
IF left(OS(OS_VERSION),3)>='06.'
aPos := { -8, -8 }
ELSE
aPos := { -4, -4 }
ENDIF
ELSE
aPos := { 0, 0 }
ENDIF

oBitmap := GraSaveScreen( oSourcePS, aPos, oXbp:currentSize() )


RETURN oBitmap

User avatar
Auge_Ohr
Posts: 1407
Joined: Wed Feb 24, 2010 3:44 pm

Re: Screen grabber in Alaska

#7 Post by Auge_Ohr »

Cliff Wiernik wrote:

Code: Select all

    oSourcePS := oXbp:lockPS()
...
    oBitmap := GraSaveScreen( oSourcePS, aPos, oXbp:currentSize() )

// unlock before return
    oSourcePS:unlockPS() 

  RETURN oBitmap
greetings by OHR
Jimmy

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Screen grabber in Alaska

#8 Post by Eugene Lutsenko »

Greetings to all!

Tried all suggested options and a few of its own, but is in the form of file is saved in the black screen. And this despite the fact that the screen eyes all is perfectly visible that everything is correct. An error occurred with the line:

GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect )

function by Roger:

Code: Select all

*************************************************
******** Сохранение экрана (Screen grabber) Roger
*************************************************
FUNCTION GraSaveScreen( oSourcePS, aPos, aSize )

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], aSize[2]}

oBitmap:presSpace( oTargetPS )
oBitmap:make( aSize[1], aSize[2] )

GraBitBlt( oTargetPS, oSourcePS, aTargetRect, aSourceRect )

RETURN oBitmap
Attachments
Безымянный.jpg
Безымянный.jpg (463.32 KiB) Viewed 13716 times

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Screen grabber in Alaska

#9 Post by Eugene Lutsenko »

I think I guessed it! In function:

oBitmap := GraSaveScreen( oStatic1, oStatic1:CurrentPos() , oStatic1:CurrentSize() )

after rotation is incorrectly determined position and size. I'll check it

User avatar
Eugene Lutsenko
Posts: 1649
Joined: Sat Feb 04, 2012 2:23 am
Location: Russia, Southern federal district, city of Krasnodar
Contact:

Re: Screen grabber in Alaska

#10 Post by Eugene Lutsenko »

Can be anyone who is interested, you can rewrite this program to write two images: 1) before rotating the image; 2) after image rotation:

Code: Select all

//////////////////////////////////////////////////////////////////////
//
//  FANCYFNT.PRG
//
//  Copyright:
//      Alaska Software, (c) 1997-2009. All rights reserved.         
//  
//  Contents:
//      This sample program renders some text strings demonstrating the GRA
//      engine's GraStringAt() primitive.
//   
//////////////////////////////////////////////////////////////////////
#include "appevent.ch"
#include "xbp.ch"
#include "gra.ch"


******************************************************************************
* Main() procedure and event loop
******************************************************************************
PROCEDURE Main

   LOCAL nEvent, mp1, mp2, oObj
   LOCAL oPS
   LOCAL oFont
   LOCAL aLineAttrs
   LOCAL aStringAttrs
   LOCAL aMatrix
   LOCAL i


   /*
    * Setup XbpCrt object created by the AppSys()
    * procedure
    */
   SetAppWindow():useShortCuts := .T.
   SetColor( "N/W+" )
   CLS

   /* Get presentation space for rendering   */
   oPS := SetAppWindow():presSpace()

   oFont := XbpFont():new():create("20.Arial Bold")
   GraSetFont(oPS , oFont)
   aAttrF := ARRAY( GRA_AS_COUNT ) 
   aAttrF [ GRA_AS_COLOR      ] := GRA_CLR_BLACK 
   aAttrF [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_LEFT
   aAttrF [ GRA_AS_VERTALIGN  ] := GRA_VALIGN_HALF
   GraSetAttrString( oPS, aAttrF ) 
   GraStringAt( oPS, { 20,350 }, 'The text before the rotation' )

   *********************************************
   ******** Save before rotating the image *****
   *********************************************

   /*
    * Rotate text strings to show transforms via
    * SetGraTransform()
    */
   oFont := XbpFont():new():create("10.Arial Bold")
   GraSetFont(oPS , oFont)
   aAttrF := ARRAY( GRA_AS_COUNT ) 
   aAttrF [ GRA_AS_COLOR      ] := GRA_CLR_BLACK 
   aAttrF [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_CENTER
   aAttrF [ GRA_AS_VERTALIGN  ] := GRA_VALIGN_HALF
   GraSetAttrString( oPS, aAttrF ) 

   nAngle = 10

   aMatrix := GraInitMatrix()
   FOR i:=1 TO nAngle
      GraRotate( oPS, aMatrix, 360/nAngle, {200, 200}, GRA_TRANSFORM_ADD )
      oPS:setGraTransform( aMatrix, GRA_TRANSFORM_REPLACE )
      GraStringAt( oPS, {100,100}, ALLTRIM(STR(i))+"-Rotated text..." )
   NEXT

   ***** Rotate the image (360) for proper rendering

   GraRotate( oPS, aMatrix, 360, {200, 200}, GRA_TRANSFORM_ADD )
   oPS:setGraTransform( aMatrix, GRA_TRANSFORM_REPLACE )
   
   oFont := XbpFont():new():create("20.Arial Bold")
   GraSetFont(oPS , oFont)                        
   aAttrF := ARRAY( GRA_AS_COUNT ) 
   aAttrF [ GRA_AS_COLOR      ] := GRA_CLR_BLACK 
   aAttrF [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_LEFT
   aAttrF [ GRA_AS_VERTALIGN  ] := GRA_VALIGN_HALF
   GraSetAttrString( oPS, aAttrF ) 
   GraStringAt( oPS, { 20,50 }, 'The text after the label at an angle' )

   *********************************************
   **** Save after image rotation **************
   *********************************************

   INKEY(0)

RETURN

// EOF
[/size]

I have failed

Post Reply