Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting text file to bmp
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
01387627
Message ID:
01388350
Vues:
64
This message has been marked as the solution to the initial question of the thread.
Hi Colin,

Is it what you need?

Regards,
Sergey
?CreateBMP("c:\4\c.txt")

*==================================
FUNCTION CreateBMP(sFileCoord, sFileBmp)

LOCAL nf, fn, i, j, nX, nY
LOCAL ARRAY aCoord[4]
LOCAL sLine, nColor, iBit, nColorBit

nf= FOPEN(sFileCoord)
IF nf<1
	WAIT WINDOW "Cannot open "+sFileCoord+" !"
	RETURN .F.
ENDIF

STORE 0 TO nX, nY
DO WHILE !FEOF(nf)
	=ALINES(aCoord, FGETS(nf), 1, " ")
	nX= MAX(nX, VAL(aCoord[1]), VAL(aCoord[3]))
	nY= MAX(nY, VAL(aCoord[2]), VAL(aCoord[4]))
ENDDO

LOCAL ARRAY aMatrix[nX, nY]
STORE 1 TO aMatrix

=FSEEK(nf, 0, 0)
DO WHILE !FEOF(nf)
	=ALINES(aCoord, FGETS(nf), 1, " ")
	FOR i=MIN(VAL(aCoord[1]), VAL(aCoord[3])) TO MAX(VAL(aCoord[1]), VAL(aCoord[3]))
		FOR j=MIN(VAL(aCoord[2]), VAL(aCoord[4])) TO MAX(VAL(aCoord[2]), VAL(aCoord[4]))
			aMatrix[i,j] = 0
		ENDFOR
	ENDFOR
ENDDO

=FCLOSE(nf)

*---------------------
fn= IIF(!EMPTY(sFileBmp), sFileBmp, FORCEEXT(sFileCoord,"bmp"))

nf= FCREATE(fn)
IF nf<1
	WAIT WINDOW "Cannot create file "+fn+" !"
	RETURN .F.
ENDIF

sByte0= CreateBMPHeader(nf, 1, nX, nY)

FOR j=nY TO 1 STEP -1 &&the rows in the bitmap are stored upside down. 
	iBit= 0
	nColorBit= 0
	sLine= ""

	FOR i=1 TO nX
		IF iBit=8
			sLine= sLine+CHR(nColorBit)
			iBit= 0
			nColorBit= 0
		ENDIF

		nColor= BITLSHIFT(aMatrix[i,j], 7-iBit)
		nColorBit= BITOR(nColorBit, nColor)

		iBit= iBit+1
	ENDFOR

	=FWRITE(nf, sLine+CHR(nColorBit)+sByte0)
ENDFOR

=FCLOSE(nf)

RETURN .T.

*------------------------
FUNCTION CreateBMPHeader(nf, nBit0, nX, nY)
* Creates BMP file header and returns a string
* to pad each row to be adjusted to a multiple of four bytes

LOCAL sLine, nByte, nByte0
LOCAL nHeadSize, nPalettesSize, nFileSize
LOCAL i, nStep, nColor

nByte= CEILING(nX*nBit0/8) &&meaning bytes in a row
nByte0= 4*CEILING(nByte/4) &&adjust to be a multiple of four

nHeadSize= 54
nPalettesSize= IIF(nBit0=24, 0, 4*2^nBit0)
nFileSize= nHeadSize + nPalettesSize+ nByte0*nY

sLine= "BM"                    &&0
sLine= sLine+CHRN(nFileSize,4) && 2 file size
sLine= sLine+CHRN( 0,4)        && 6 just zero (reserved)
sLine= sLine+CHRN(nHeadSize+nPalettesSize,4) &&10 offset from the beginning of the file to the bitmap data

sLine= sLine+CHRN(40,4) &&14 size of the BITMAPINFOHEADER structure
sLine= sLine+CHRN(nX,4) &&18 width  of the image, in pixels
sLine= sLine+CHRN(nY,4) &&22 height of the image, in pixels

sLine= sLine+CHRN( 1,2)    &&26 number of planes of the target device
sLine= sLine+CHRN(nBit0,2) &&28 number of bits per pixel

sLine= sLine+CHRN( 0,4) &&30 type of compression
sLine= sLine+CHRN( 0,4) &&34 size of the image data, in bytes. If there is no compression, it is zero
sLine= sLine+CHRN( 0,4) &&38 horizontal pixels per meter on the designated targer device, usually set to zero
sLine= sLine+CHRN( 0,4) &&42 vertical   pixels per meter on the designated targer device, usually set to zero

sLine= sLine+CHRN( 0,4) &&46 number of colors used in the bitmap, if set to zero the number of colors is calculated using the nBit0
sLine= sLine+CHRN( 0,4) &&50 number of color that are 'important' for the bitmap, if set to zero, all colors are important
                        &&54 starts palette table   
=FWRITE(nf, sLine)

* Note that the term palette does not refer to a RGBQUAD array,
* which is called color table instead. Also note that, in a color
* table (RGBQUAD), the specification for a color starts with the BLUE byte.
* (In a palette a color always starts with the red byte.)

* palette table
sLine= ""
IF nBit0#24
	nStep= 255/(2^nBit0-1)
	nColor= 0
	FOR i=1 TO 2^nBit0
		sLine= sLine+REPLICATE(CHR(ROUND(nColor,0)),3)+CHR(0)
		nColor= nColor+nStep
	ENDFOR
ENDIF

=FWRITE(nf, sLine)

RETURN REPLICATE(CHR(0),nByte0-nByte) &&to pad row

*-------------------------------
FUNCTION CHRN(n, ln) &&converts numeric value to binary string,
                     &&bytes go from tail to head
* n, ln - numeric value and output string length

LOCAL i, s, sc

s= ""
sc= n
FOR i=1 TO ln
   s= s+CHR(sc%256)
   sc= INT(sc/256)
ENDFOR

RETURN s
>Koen
>
>This is the text file. Its an image of a rectangle drawn with a stylus. Each line has 4 points. x,y,x1,y1.
>
>21 15 19 14
>19 14 21 15
>21 15 23 15
>23 15 26 15
>26 15 28 15
>28 15 30 15
>30 15 32 15
>32 15 38 15
>38 15 40 15
>40 15 43 15
>43 15 46 14
>46 14 51 15
>51 15 61 15
>61 15 67 15
>67 15 73 15
>73 15 81 14
>81 14 87 15
>87 15 93 14
>93 14 102 13
>102 13 110 13
>110 13 117 13
>117 13 126 12
>126 12 133 12
>133 12 135 11
>135 11 141 11
>141 11 147 11
>147 11 153 11
>153 11 160 12
>160 12 162 12
>162 12 167 13
>167 13 169 13
>169 13 171 13
>171 13 173 13
>173 13 175 15
>175 15 176 17
>176 17 177 20
>177 20 178 22
>178 22 178 24
>178 24 179 27
>179 27 179 34
>179 34 179 36
>179 36 179 39
>179 39 179 46
>179 46 179 52
>179 52 179 55
>179 55 179 60
>179 60 180 62
>180 62 180 65
>180 65 181 67
>181 67 179 67
>179 67 176 67
>176 67 174 67
>174 67 165 67
>165 67 158 67
>158 67 150 68
>150 68 139 67
>139 67 131 67
>131 67 119 67
>119 67 110 68
>110 68 102 68
>102 68 90 68
>90 68 81 69
>81 69 72 70
>72 70 63 71
>63 71 58 72
>58 72 55 73
>55 73 52 73
>52 73 50 74
>50 74 46 74
>46 74 41 74
>41 74 39 74
>39 74 37 74
>37 74 35 74
>35 74 33 74
>33 74 30 71
>30 71 30 69
>30 69 29 65
>29 65 29 62
>29 62 29 59
>29 59 29 57
>29 57 29 52
>29 52 28 47
>28 47 28 44
>28 44 28 39
>28 39 28 35
>28 35 28 32
>28 32 28 28
>28 28 28 25
>28 25 28 23
>28 23 27 21
>27 21 27 19
>27 19 28 16
>28 16 28 14
>28 14 30 9
>30 9 30 9
>
>I can't upload it as an image - text file is not accepted by UT
>
>Thanks
>
>Colin
>
>
>>Colin,
>>
>>how do you capture a signature as a text file???
>>Please show me an example - upload image - (be sure the signature is fake!)
>>In case you dont have an account here, so you are not allowed to upload images you are invited to mail to koenUnderscorepillerAThotmailDotcom
>>
>>Regards,
>>
>>Koen
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform