Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Cropping 3

Status
Not open for further replies.

TariqMehmod

Programmer
Mar 4, 2004
100
PK
ear Experts

I have following excel file

aaa_luwzwu.png


I want to create an image based on usedcells (B3:J22)
Is it possible to crop required range then create an image.

I think GDIPLUS can do this, so I found these links but still confuse how to do this.


The codes in this link crop whole screen but not required area

Please help
 
My turn... there is bound to be a problem...

Code:
* getting desktop path
loShell = CREATEOBJECT ('WScript.Shell')
lcDesktop = loShell.SpecialFolders('desktop')

* select file
lcXLS = GETFILE('XLSx')
IF EMPTY(lcXLS)
    * user has cancelled
    RETURN
ENDIF

    LOCAL oForm
    oForm = CREATEOBJECT("Form")

    WITH oForm

        .HEIGHT = 550
        .WIDTH = 360
        .AUTOCENTER=.T.
        .CAPTION=[Dashboard]
        .MINBUTTON=.F.
        .MAXBUTTON=.F.
        .ALWAYSONTOP=.T.

        .NEWOBJECT("ExcelObject","oleExcelObject")  && Add OLE object
        WITH .ExcelObject
            .LEFT = 5
            .TOP = 5
            .WIDTH = .PARENT.WIDTH - 10
            .HEIGHT = .PARENT.HEIGHT - 10
            .VISIBLE = .T.
        ENDWITH

        .NEWOBJECT("Timer1","oTimer")  		


    oForm.SHOW(1)  && form is modal, so no need for READ EVENTS
ENDWITH

DEFINE CLASS oleExcelObject AS OLECONTROL
    OLECLASS ="Excel.Sheet"  && Server name
    OLETYPEALLOWED = 0      && Linked
    DOCUMENTFILE = lcXLS && This file should exist
ENDDEFINE

DEFINE CLASS oTimer AS TIMER							&& timer
    INTERVAL=5000

    PROCEDURE TIMER
    THIS.ENABLED = .F.
    DO ScreenShot(THIS.PARENT)
    THIS.ENABLED = .T.
ENDDEFINE

PROCEDURE ScreenShot
PARAMETER oFORM
PRIVATE oFORM

#INCLUDE gpImage.h

IF NOT "gpImage" $ SET("Procedure")
    SET PROCEDURE TO gpImage ADDITIVE
ENDIF

GDIP = CREATEOBJECT("gpInit")
img = CREATEOBJECT("gpImage")
img.Capture(oFORM.HWND)
LOCAL lnTitleHeight, lnLeftBorder, lnTopBorder
lnTitleHeight = SYSMETRIC(9)
lnLeftBorder = SYSMETRIC(3)
lnTopBorder = SYSMETRIC(4)
img.Crop(lnLeftBorder, lnTitleHeight + lnTopBorder, ;
img.ImageWidth - (lnLeftBorder * 2), ;
img.ImageHeight - (lnTitleHeight + (lnTopBorder * 2)))
img.SaveasBMP(lcDesktop+'\'+"Dash")
img = NULL
GDIP = NULL
RELEASE oFORM

ENDFUNC

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Sir,

ax2_knqcvn.png


image is not uploading

But now error appears on this line
Code:
do screenshot(this.parent)

Error is
Invalid Subscript reference

Best regards
 
Sorry, rarely think proc only funct

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Sir this time no error occurs

But

Form does not release, after every five seconds images file is replaced with new one.

Please help me to release this form after after 5 seconds.

I modified this portion
Code:
 Define Class oTimer As Timer							&& timer
	Interval=5000

	Procedure Timer
	This.Enabled = .F.
	Do ScreenShot With This.Parent
	This.Enabled = .T.
	This.Parent.Release
Enddefine

But Form still not releases.

Best Regards
 
Code:
Define Class oTimer As Timer							&& timer
	Interval=5000

	Procedure Timer
	This.Enabled = .F.
	Do ScreenShot With This.Parent
	This.Enabled = .T.
	Quit
Enddefine

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Try putting this near the top of your code

Code:
ON SHUTDOWN CLEAR EVENTS

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Sir here are complete codes, I run the codes, images file is created successfully but FORM still not releases.


Code:
 ON SHUTDOWN CLEAR EVENTS

* getting desktop path
loShell = CREATEOBJECT ('WScript.Shell')
lcDesktop = loShell.SpecialFolders('desktop')

* select file
lcXLS = GETFILE('XLSx')
IF EMPTY(lcXLS)
    * user has cancelled
    RETURN
ENDIF

    LOCAL oForm
    oForm = CREATEOBJECT("Form")

    WITH oForm

        .HEIGHT = 550
        .WIDTH = 360
        .AUTOCENTER=.T.
        .CAPTION=[Dashboard]
        .MINBUTTON=.F.
        .MAXBUTTON=.F.
        .ALWAYSONTOP=.T.

        .NEWOBJECT("ExcelObject","oleExcelObject")  && Add OLE object
        WITH .ExcelObject
            .LEFT = 5
            .TOP = 5
            .WIDTH = .PARENT.WIDTH - 10
            .HEIGHT = .PARENT.HEIGHT - 10
            .VISIBLE = .T.
        ENDWITH

        .NEWOBJECT("Timer1","oTimer")  		


    oForm.SHOW(1)  && form is modal, so no need for READ EVENTS
ENDWITH

DEFINE CLASS oleExcelObject AS OLECONTROL
    OLECLASS ="Excel.Sheet"  && Server name
    OLETYPEALLOWED = 0      && Linked
    DOCUMENTFILE = lcXLS && This file should exist
ENDDEFINE


Define Class oTimer As Timer		
	Interval=5000

	Procedure Timer
	This.Enabled = .F.
	Do ScreenShot With This.Parent
	This.Enabled = .T.
	Quit
Enddefine 


PROCEDURE ScreenShot
PARAMETER oFORM
PRIVATE oFORM

#INCLUDE gpImage.h

IF NOT "gpImage" $ SET("Procedure")
    SET PROCEDURE TO gpImage ADDITIVE
ENDIF

GDIP = CREATEOBJECT("gpInit")
img = CREATEOBJECT("gpImage")
img.Capture(oFORM.HWND)
LOCAL lnTitleHeight, lnLeftBorder, lnTopBorder
lnTitleHeight = SYSMETRIC(9)
lnLeftBorder = SYSMETRIC(3)
lnTopBorder = SYSMETRIC(4)
img.Crop(lnLeftBorder, lnTitleHeight + lnTopBorder, ;
img.ImageWidth - (lnLeftBorder * 2), ;
img.ImageHeight - (lnTitleHeight + (lnTopBorder * 2)))
img.SaveasBMP(lcDesktop+'\'+"Dash")
img = NULL
GDIP = NULL
RELEASE oFORM

ENDFUNC
 
Instead of this:

Code:
    oForm.SHOW(1)  && form is modal, so no need for READ EVENTS
ENDWITH

this seems to work (but I'm not sure why):

Code:
ENDWITH
    oForm.SHOW(1)  && form is modal, so no need for READ EVENTS

And get rid of the [tt]QUIT[/tt], and replace the[tt] RELEASE oForm[/tt] with [tt]oForm.Release[/tt]

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
So here is my latest version (again, not tested because I don't have the imaging control):

Code:
* getting desktop path
loShell = CREATEOBJECT ('WScript.Shell')
lcDesktop = loShell.SpecialFolders('desktop')

* select file
lcXLS = GETFILE('XLSx')
IF EMPTY(lcXLS)
    * user has cancelled
    RETURN
ENDIF

    LOCAL oForm
    oForm = CREATEOBJECT("Form")

    WITH oForm

        .HEIGHT = 550
        .WIDTH = 360
        .AUTOCENTER=.T.
        .CAPTION=[Dashboard]
        .MINBUTTON=.F.
        .MAXBUTTON=.F.
        .ALWAYSONTOP=.T.

        .NEWOBJECT("ExcelObject","oleExcelObject")  && Add OLE object
        WITH .ExcelObject
            .LEFT = 5
            .TOP = 5
            .WIDTH = .PARENT.WIDTH - 10
            .HEIGHT = .PARENT.HEIGHT - 10
            .VISIBLE = .T.
        ENDWITH

        .NEWOBJECT("Timer1","oTimer")  		
ENDWITH

    oForm.SHOW(1)  && form is modal, so no need for READ EVENTS


DEFINE CLASS oleExcelObject AS OLECONTROL
    OLECLASS ="Excel.Sheet"  && Server name
    OLETYPEALLOWED = 0      && Linked
    DOCUMENTFILE = lcXLS && This file should exist
ENDDEFINE

DEFINE CLASS oTimer AS TIMER							&& timer
    INTERVAL=5000

    PROCEDURE TIMER
    THIS.ENABLED = .F.
    DO ScreenShot WITH this.Parent
	this.enabled = .T.
ENDDEFINE

PROCEDURE ScreenShot
LPARAMETERS oForm

#INCLUDE gpImage.h

IF NOT "gpImage" $ SET("Procedure")
    SET PROCEDURE TO gpImage ADDITIVE
ENDIF

GDIP = CREATEOBJECT("gpInit")
img = CREATEOBJECT("gpImage")
img.Capture(THISFORM.HWND)
LOCAL lnTitleHeight, lnLeftBorder, lnTopBorder
lnTitleHeight = SYSMETRIC(9)
lnLeftBorder = SYSMETRIC(3)
lnTopBorder = SYSMETRIC(4)
img.Crop(lnLeftBorder, lnTitleHeight + lnTopBorder, ;
img.ImageWidth - (lnLeftBorder * 2), ;
img.ImageHeight - (lnTitleHeight + (lnTopBorder * 2)))
img.SaveasBMP(lcDesktop+'\'+"Dash")
img = NULL
oForm.Release

ENDFUNC


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Are we nearly there yet?

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
And only 45/46 US Presidents later

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Sir, Finally I used these codes

Code:
 Define Class oTimer As Timer
	Interval=5000

	Procedure Timer
	This.Enabled = .F.
	Do ScreenShot With This.Parent
	This.Enabled = .T.
	This.Parent.Hide(1)
	
Enddefine

Now form hides.
Specially thanks to Respected Sir GriffMG and Mike Lewis.

With Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top