Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1679
Number of posts: 4768

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How can I OPEN " file" FOR BINARY? Posted by Dr. COM WIZ on 29 Mar 2001 at 11:21 PM
This is Dr. COM WIZ, again. As most of you might know, I am 13. I will be the only 13-year-old advanced Qbasic programmer that I know if I just learn how to OPEN "files" FOR BINARY AS #1. Can somoene please teach me the fundamentals of doing so?

Don't get me wrong, though. I know that OPENing files FOR BINARY can legally transform files from one extention to another, load files of various extentions, and create them. I just, if you please, need someone to teach how to use the BINARY command proficiently so I don't have to use someone elses BMP loader.

By the way, if I use YPI's BMP saver and change all the PUT statements to GET statements, will I get a loader?


This has been,
Dr. COM WIZ

PS Thank you and goodnight!


Report
Re: How can I OPEN " file" FOR BINARY? Posted by kissmyasm on 30 Mar 2001 at 10:58 AM
: This is Dr. COM WIZ, again. As most of you might know, I am 13. I will be the only 13-year-old advanced Qbasic programmer that I know if I just learn how to OPEN "files" FOR BINARY AS #1. Can somoene please teach me the fundamentals of doing so?
:
: Don't get me wrong, though. I know that OPENing files FOR BINARY can legally transform files from one extention to another, load files of various extentions, and create them. I just, if you please, need someone to teach how to use the BINARY command proficiently so I don't have to use someone elses BMP loader.
:
: By the way, if I use YPI's BMP saver and change all the PUT statements to GET statements, will I get a loader?
:
:
: This has been,
: Dr. COM WIZ
:
: PS Thank you and goodnight!
:
:


Report
Re: How can I OPEN " file" FOR BINARY? Posted by kissmyasm on 30 Mar 2001 at 11:00 AM
hehe, oops... anyway...
i think i know what yer talking about.

open "file" for binary as #1
'file opened, you know that
get #1,1,var
'var= first record in file
var=var and 255
'gotta make sure that we get the right stuff
print chr$(var)
'see the contents

YAY!!!
i hope this is sorta kinda what you want

Report
BMP header reader Posted by BASIC Friend on 30 Mar 2001 at 8:19 PM
Hey Man,

I have alot of code here for you. I have been working on a BMP veiwer myself. I haven't been working on it lately because time is a little hard to find. What I have for you is a BMP header reader. It demonstrates how to use TYPEs for reading binary files. A TYPE makes it so much easier. I know that BMP.H is hard to read, I left the format info in comments.
'Save the following file as
'BMP.H
'Save it in your QB directory
'
TYPE BMPHEAD
'Offset  Field   Size    Contents
identifier AS STRING * 2
'0000h   Identifier  2 bytes The characters identifying the bitmap.
         'The following entries are possible:  'BM' - Windows 3.1x, 95, NT,
         ' 'BA' - OS/2 Bitmap Array 'CI' - OS/2 Color Icon
         ''CP' - OS/2 Color Pointer 'IC' - OS/2 Icon 'PT' - OS/2 Pointer
filesize AS LONG
'0002h   File Size   1 dword Complete file size in bytes.
reserved AS LONG
'0006h   Reserved    1 dword Reserved for later use.
dataoffset AS LONG
'000Ah   Bitmap Data Offset  1 dword Offset from beginning of file to the
         'beginning of the bitmap data.
headersize AS LONG
'000Eh   Bitmap Header Size  1 dword Length of the Bitmap Info Header
         'used to describe the bitmap colors, compression,  The following
         'sizes are possible:  28h - Windows 3.1x, 95, NT,
         '_ 0Ch - OS/2 1.x F0h - OS/2 2.x
lwidth AS LONG
'0012h   Width   1 dword Horizontal width of bitmap in pixels.
lheight AS LONG
'0016h   Height  1 dword Vertical height of bitmap in pixels.
planes AS INTEGER
'001Ah   Planes  1 word  Number of planes in this bitmap.
bitsperpixel AS INTEGER
'001Ch   Bits Per Pixel  1 word  Bits per pixel used to store palette entry
         'information. This also identifies in an indirect way the number of
         'possible colors. Possible values are: 1 - Monochrome bitmap
         '4 - 16 color bitmap 8 - 256 color bitmap
         '16 - 16bit (high color) bitmap 24 - 24bit (true color) bitmap
         '32 - 32bit (true color) bitmap
compression AS LONG
'001Eh   Compression 1 dword Compression specifications.
        'The following values are possible:
        '0 - none (Also identified by BI_RGB)
        '1 - RLE 8-bit / pixel (Also identified by BI_RLE4)
        '2 - RLE 4-bit / pixel (Also identified by BI_RLE8)
        '3 - Bitfields  (Also identified by BI_BITFIELDS)
datasize AS LONG
'0022h   Bitmap Data Size    1 dword Size of the bitmap data in bytes.
        'This number must be rounded to the next 4 byte boundary.
hresolution AS LONG
'0026h   HResolution 1 dword Horizontal resolution expressed in
        'pixel per meter.
vresolution AS LONG
'002Ah   VResolution 1 dword Vertical resolution expressed in
        'pixels per meter.
colors AS LONG
'002Eh   Colors  1 dword Number of colors used by this bitmap.
        'For a 8-bit / pixel bitmap this will be 100h or 256.
important AS LONG
'0032h   Important Colors    1 dword Number of important colors.
        'This number will be equal to the number of colors when every
        'color is important.
'0036h   Palette N * 4 byte  The palette specification.
        'For every entry in the palette four bytes are used to describe the
        'RGB values of the color in the following way:
        '1 byte for blue component 1 byte for green component
        '1 byte for red component 1 byte filler which is set to 0 (zero)
'0436h   Bitmap Data x bytes Depending on the compression specifications,
        'this field contains all the bitmap data bytes which represent
        'indices in the color palette.
END TYPE

The next code is the main program--------------------------------
'Save this as BMPREAD.BAS
'
'all this does is read the BMP Header
'$INCLUDE: 'bmp.h'
DIM bmp1 AS BMPHEAD
OPEN COMMAND$ FOR BINARY AS #1
GET #1, , bmp1
CLOSE #1
PRINT "Identifier: "; bmp1.identifier
PRINT "File size:"; bmp1.filesize
PRINT "Reserved:"; bmp1.reserved
PRINT "Offset of bitmap data:"; bmp1.dataoffset
PRINT "Size of header:"; bmp1.headersize
PRINT "Length of image:"; bmp1.lwidth
PRINT "Height of image:"; bmp1.lheight
PRINT "Planes:"; bmp1.planes
PRINT "Bits per pixel:"; bmp1.bitsperpixel
PRINT "Compression:"; bmp1.compression
PRINT "Size of bitmap data:"; bmp1.datasize
PRINT "Horizontal resolution:"; bmp1.hresolution; "pixels per meter"
PRINT "Vertical resolution:"; bmp1.vresolution; "pixels per meter"
PRINT "Number of colors:"; bmp1.colors
PRINT "Number of important colors:"; bmp1.important
PRINT
END



Report
Thanks but it didn't work. Posted by Dr. COM WIZ on 31 Mar 2001 at 9:52 PM
Hello

First of all, I want to thank you very much for the BMP loader you gave me, BASIC friend. I was so excited to try it out, but this isn't the first time my computer compained about any BMP loader. This time, Windows tells me, "The MS-DOS program has performed an illegal operation and will be shut down." Either you made a boo-boo in your program or my computer just hates BMP loaders. Usually, though, DOS complains about the loaders, but this one was a little more serious. Windows also said, "Close all programs and restart your computer." What gives?

--Dr. COM WIZ




Report
Re: Thanks but it didn't work. Posted by BASIC Friend on 1 Apr 2001 at 6:59 PM
: Hello
:
: First of all, I want to thank you very much for the BMP loader you gave me, BASIC friend. I was so excited to try it out, but this isn't the first time my computer compained about any BMP loader. This time, Windows tells me, "The MS-DOS program has performed an illegal operation and will be shut down." Either you made a boo-boo in your program or my computer just hates BMP loaders. Usually, though, DOS complains about the loaders, but this one was a little more serious. Windows also said, "Close all programs and restart your computer." What gives?
:
: --Dr. COM WIZ
:
:
:
:
It worked fine on my machine. Did you save the type in the BMP.H file? That file needs to be in the same folder as QB.

It works on the command line like BMPREAD picture.bmp

It's ok, all it does is read the bmp header. I haven't finished the loader yet.

I'll check out the code that I posted just to make sure.







 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.