Re: Read a .BMP into Fortran?
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
Re: Read a .BMP into Fortran?         


Author: David.Paterson
Date: Apr 23, 2007 19:32

> How can I read a bitmap file into Fortran?

The following Fortran code fragment will read a 24 bit .bmp file. On
my compiler I also need the switch "/assume:byterecl"

integer Maxwidth,Maxheight,irec,iwidth,iheight,i,j,ipad
parameter(Maxwidth=3220,Maxheight=2415)
character header(54),ch
integer image(Maxheight,Maxwidth,3)

open(1,file='..\..
\cow_small.bmp',form='unformatted',access='direct',recl=1)

do irec=1,54
read(1,rec=irec) header(irec)
end do

if(ichar(header(11)).ne.54.or.ichar(header(29)).ne.
24.or.ichar(header(31)).ne.0) then
print*,'sorry, can not handle this file'
end if
Show full article (1.29Kb)
1 Comment
Re: Read a .BMP into Fortran?         


Author: David.Paterson
Date: Apr 25, 2007 11:57

> ipad=(Maxwidth-iwidth)-((Maxwidth-iwidth)/4)*4

Oops,

ipad=(Maxwidth-iwidth)*3-((Maxwidth-iwidth)*3/4)*4

Maxwidth has to be divisible by 4. On writing the .bmp bitmap out
again use:

do ip=1,ipad
irec=irec+1
write(2,rec=irec) char(0)
end do
no comments