 |
 |

07-24-2003, 06:33 PM
|
 |
Contributor
|
|
Join Date: Nov 2002
Location: American Canyon, CA
Posts: 622
|
|
Put bitmap Bits Array into a Random Access file
|
I seem to be stuck on this one:
I have an array of bitmap bits, and i need to stick them into a random access file. The problem was, it took waaaay too much space.
After quite a bit of tinkering, i managed to just have each byte in the bitmap bits array added to an array of strings (each string holds 32 bytes of characters). That way, i could technically just add each string as a Random File entry.
This is where the real problem lies.
It still takes waaaay too much space, and it takes forever to save the bitmap bits to the custom file (bitmap and text into one file) if its even bigger than 32 by 32 pixels!
Does anyone know of a better way?  (thanks in advance)
Code:
'Here is approximatly what it looks like, assuming TotalBytes was already dim'ed and already has a value, and the Byte array is called 'bBYTE'
Dim I as long
Dim J as long
Dim MaxBytes as long
Dim TotalStrings as long
Dim sSTRING() as String
MaxBytes = 32
TotalStrings = TotalBytes / MaxBytes
redim sSTRING(0 to TotalStrings)
For I = 1 to TotalBytes
'Fill in Strings with Character representations of each byte
sString(J) = sString(J) & chr$(bBYTE(I))
'If this string is full, use the next String
if len(sString(J)) > MaxBytes then
J = J + 1
end if
next I
Open TheFile for Random as #1
For I = 0 to TotalStrings
'Put each string into the file as a record
Put #1, sSTRING(J)
next I
Close #1
|
|

07-24-2003, 06:44 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
|
|
Quote: Originally Posted by ALEX_0077 I seem to be stuck on this one:
I have an array of bitmap bits, and i need to stick them into a random access file. The problem was, it took waaaay too much space.
After quite a bit of tinkering, i managed to just have each byte in the bitmap bits array added to an array of strings (each string holds 32 bytes of characters). That way, i could technically just add each string as a Random File entry.
This is where the real problem lies.
It still takes waaaay too much space, and it takes forever to save the bitmap bits to the custom file (bitmap and text into one file) if its even bigger than 32 by 32 pixels!
Does anyone know of a better way? (thanks in advance)
Code:
'Here is approximatly what it looks like, assuming TotalBytes was already dim'ed and already has a value, and the Byte array is called 'bBYTE'
Dim I as long
Dim J as long
Dim MaxBytes as long
Dim TotalStrings as long
Dim sSTRING() as String
MaxBytes = 32
TotalStrings = TotalBytes / MaxBytes
redim sSTRING(0 to TotalStrings)
For I = 1 to TotalBytes
'Fill in Strings with Character representations of each byte
sString(J) = sString(J) & chr$(bBYTE(I))
'If this string is full, use the next String
if len(sString(J)) > MaxBytes then
J = J + 1
end if
next I
Open TheFile for Random as #1
For I = 0 to TotalStrings
'Put each string into the file as a record
Put #1, sSTRING(J)
next I
Close #1
The first thing I would do is declare the record size for the random file.
Since you don't declare it, it defaults to 128 bytes, so each 32 byte string is taking 128 of file space.
Another option is to use a binary file, which uses byte offsets, and not
records.
Then you would only have to change the "Random" to Binary and
"Put #1, sSTRING(J)" to "Put #1,,sSTRING(J)"
|
|

07-24-2003, 06:52 PM
|
 |
Contributor
|
|
Join Date: Nov 2002
Location: American Canyon, CA
Posts: 622
|
|
Of course! Open as BINARY!
(i must be too exhausted)
Passel, thank you very, very much. 
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|