Save an area of a Form as BMP 
Author Message
 Save an area of a Form as BMP

Hi,
I'd like to save an area of a form as a bmp.
Does anyone know if there's a solution in pure VFP ... or a free solution
... or an alternate solution ...
In fact, i draw some shape on my form as the user want and i want to be able
to print it ...
Bests regards.


Sun, 28 Aug 2005 17:48:25 GMT  
 Save an area of a Form as BMP
Hello, Franck!
You wrote  on Wed, 12 Mar 2003 10:48:25 +0100:

 FF> Hi,
 FF> I'd like to save an area of a form as a bmp.
 FF> Does anyone know if there's a solution in pure VFP ... or a free
 FF> solution
 FF> ... or an alternate solution ...
 FF> In fact, i draw some shape on my form as the user want and i want to be
 FF> able to print it ...
 FF> Bests regards.

VFP code by Chin Bae:

***test.prg
LOCAL x, y
x = CREATEOBJECT('form')
x.Move(0,0,228,231)
x.BackColor = 0x996666
x.AddObject('Command1','CommandButton')
y = x.Command1
y.Move(1,1)
y.Visible = .T.
x.Show()

BuildBMP(x,'form.bmp',0,x.Width-1,0,x.Height-1)
BuildBMP(x,'button.bmp',y.Left,y.Width,y.Top,y.Height)

#DEFINE DWORDOFFSET 2147483648
#DEFINE WORDOFFSET 32768

FUNCTION BuildBMP(toForm, tcFile, tnX1, tnX2, tnY1, tnY2)
LOCAL nX1, nX2, nY1, nY2, nWidth, nHeight, nPixels, i, j, cBMP,
cColArray,cPad
nX1 = TVL(tnX1, 0)
nX2 = TVL(tnX2, toForm.Width-1)
nY1 = TVL(tnY1, 0)
nY2 = TVL(tnY2, toForm.Height-1)
nWidth = nX2 - nX1 + 1

***Width must be divisible by 4
***Need to pad each line with nulls
cPad = REPLICATE(CHR(0),MOD(nWidth,4))

nHeight = nY2 - nY1 + 1
nPixels = nWidth * nHeight
IF nPixels < 1 THEN
 RETURN .F.
ENDIF

cBMP = 'BM' + NumToDWord(54 + nWidth * nHeight * 3) + NumToWord(0)
+NumToWord(0) + NumToDWord(54)
cBMP = cBMP + GetBMPInfoHeader(nWidth, nHeight)
cColArray = ''
FOR j = nY2 TO nY1 STEP -1
 FOR i = nX1 TO nX2
  cColArray = cColArray + GetBinaryColor(toForm.Point(i,j))
 ENDFOR
 cColArray = cColArray + cPad
ENDFOR
cBMP = cBMP + cColArray
STRTOFILE(cBMP, tcFile)
ENDFUNC

FUNCTION GetBMPInfoHeader(tnWidth, tnHeight)
LOCAL cHeader, cZero
cZero = NumToDWord(0)
cHeader = NumToDWord(40) + NumToDWord(tnWidth) + NumToDWord(tnHeight)
cHeader = cHeader + NumToWord(1) + NumToWord(24) + cZero + cZero
cHeader = cHeader + NumToDWord(3780) + NumToDWord(3780) + cZero + cZero
RETURN cHeader
ENDFUNC

FUNCTION GetBinaryColor(tnColor)
RETURN SUBSTR(BINTOC(MAX(tnColor,0) - DWORDOFFSET),2)
ENDFUNC

FUNCTION NumToDWord(tnVal)
LOCAL cBin
cBin = BINTOC(tnVal - DWORDOFFSET)
RETURN SUBSTR(cBin,4,1) + SUBSTR(cBin,3,1) + SUBSTR(cBin,2,1)
+SUBSTR(cBin,1,1)
ENDFUNC

FUNCTION NumToWord(tnVal)
LOCAL cBin
cBin = BINTOC(tnVal - WORDOFFSET, 2)
RETURN SUBSTR(cBin,2,1) + SUBSTR(cBin,1,1)
ENDFUNC

FUNCTION TVL(tuParamValue, tuInitValue)
RETURN IIF(VARTYPE(tuParamValue) = VARTYPE(tuInitValue),
tuParamValue,tuInitValue)
ENDFUNC
***end test.prg

---
Eric den Doop
www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8



Sun, 28 Aug 2005 18:07:23 GMT  
 Save an area of a Form as BMP
Hi Eric,
I've just tried the sample you send me ...
It's work very well ... a great job ...
I think i'm the happiest man in the world today ...
Bests Regards
Franck.



Quote:
> Hello, Franck!
> You wrote  on Wed, 12 Mar 2003 10:48:25 +0100:

>  FF> Hi,
>  FF> I'd like to save an area of a form as a bmp.
>  FF> Does anyone know if there's a solution in pure VFP ... or a free
>  FF> solution
>  FF> ... or an alternate solution ...
>  FF> In fact, i draw some shape on my form as the user want and i want to
be
>  FF> able to print it ...
>  FF> Bests regards.

> VFP code by Chin Bae:

> ***test.prg
> LOCAL x, y
> x = CREATEOBJECT('form')
> x.Move(0,0,228,231)
> x.BackColor = 0x996666
> x.AddObject('Command1','CommandButton')
> y = x.Command1
> y.Move(1,1)
> y.Visible = .T.
> x.Show()

> BuildBMP(x,'form.bmp',0,x.Width-1,0,x.Height-1)
> BuildBMP(x,'button.bmp',y.Left,y.Width,y.Top,y.Height)

> #DEFINE DWORDOFFSET 2147483648
> #DEFINE WORDOFFSET 32768

> FUNCTION BuildBMP(toForm, tcFile, tnX1, tnX2, tnY1, tnY2)
> LOCAL nX1, nX2, nY1, nY2, nWidth, nHeight, nPixels, i, j, cBMP,
> cColArray,cPad
> nX1 = TVL(tnX1, 0)
> nX2 = TVL(tnX2, toForm.Width-1)
> nY1 = TVL(tnY1, 0)
> nY2 = TVL(tnY2, toForm.Height-1)
> nWidth = nX2 - nX1 + 1

> ***Width must be divisible by 4
> ***Need to pad each line with nulls
> cPad = REPLICATE(CHR(0),MOD(nWidth,4))

> nHeight = nY2 - nY1 + 1
> nPixels = nWidth * nHeight
> IF nPixels < 1 THEN
>  RETURN .F.
> ENDIF

> cBMP = 'BM' + NumToDWord(54 + nWidth * nHeight * 3) + NumToWord(0)
> +NumToWord(0) + NumToDWord(54)
> cBMP = cBMP + GetBMPInfoHeader(nWidth, nHeight)
> cColArray = ''
> FOR j = nY2 TO nY1 STEP -1
>  FOR i = nX1 TO nX2
>   cColArray = cColArray + GetBinaryColor(toForm.Point(i,j))
>  ENDFOR
>  cColArray = cColArray + cPad
> ENDFOR
> cBMP = cBMP + cColArray
> STRTOFILE(cBMP, tcFile)
> ENDFUNC

> FUNCTION GetBMPInfoHeader(tnWidth, tnHeight)
> LOCAL cHeader, cZero
> cZero = NumToDWord(0)
> cHeader = NumToDWord(40) + NumToDWord(tnWidth) + NumToDWord(tnHeight)
> cHeader = cHeader + NumToWord(1) + NumToWord(24) + cZero + cZero
> cHeader = cHeader + NumToDWord(3780) + NumToDWord(3780) + cZero + cZero
> RETURN cHeader
> ENDFUNC

> FUNCTION GetBinaryColor(tnColor)
> RETURN SUBSTR(BINTOC(MAX(tnColor,0) - DWORDOFFSET),2)
> ENDFUNC

> FUNCTION NumToDWord(tnVal)
> LOCAL cBin
> cBin = BINTOC(tnVal - DWORDOFFSET)
> RETURN SUBSTR(cBin,4,1) + SUBSTR(cBin,3,1) + SUBSTR(cBin,2,1)
> +SUBSTR(cBin,1,1)
> ENDFUNC

> FUNCTION NumToWord(tnVal)
> LOCAL cBin
> cBin = BINTOC(tnVal - WORDOFFSET, 2)
> RETURN SUBSTR(cBin,2,1) + SUBSTR(cBin,1,1)
> ENDFUNC

> FUNCTION TVL(tuParamValue, tuInitValue)
> RETURN IIF(VARTYPE(tuParamValue) = VARTYPE(tuInitValue),
> tuParamValue,tuInitValue)
> ENDFUNC
> ***end test.prg

> ---
> Eric den Doop
> www.foxite.com - The Home Of The Visual FoxPro Experts - Powered By VFP8



Sun, 28 Aug 2005 18:46:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Save form as BMP

2. Save clippboard in bmp files

3. FPW26: Save a general field as a .bmp

4. BMP in Clipboard save to a File

5. Saving BMP to disk from general field.

6. Forms: Converting BMP files to ICO files for use in icon properties of forms

7. VFP User Groups - Bay Area & Ventura Area

8. 'Greyed' areas when viewing a form

9. Edit buttons on form call to wrong work area

10. Other pictures than BMP on forms and reports

11. Display BMP as thumbnail on form.

12. Limited form viewing area in design mode

 

 
Powered by phpBB® Forum Software