Hi,
I have read in several images as INTEGER*2 matrices, am doing pixel manipulations with them and writing the result to an output matrix. How do I convert this output matrix into a bitmap image file?
Thanks for any help.
Mvpr
I know how to create a bmp file in C/C++ but I can't figure out how to do it with the compiler I have. I've got all the structures in but I can't read/write the files. There are lots of integer(len=2) and character(len=1) in the format specification. Looks like my Fortran compiler, which is the Lahey-Fujitsu elf90 (when it was free) doesn't support input/output of binary files.
Just wondering whether it is worth trying it in F77 or is everything F90/F95 based nowadays?
I've written a noddy one in F77 but it is too big to post in this forum (appx 300 lines, including comments). It will handle a 32x32 bitmap. You will have to modify the code for a bigger map. I haven't got a website and I can't be bothered to set one up. If you email me at
tech@cup.btinternet.co.uk
subject Fortran BMP
I'll email the source to you.
I don't mind if you decide to put it on your website. Just post it here to let everyone know.
Just looked at one of the other messages. Maybe 300 lines isn't so big after all. There are 2 files below. If your version of F77 does not accept includes, then you will need to replicate the header file wherever the common block is required
! type:: BmpFileHeader
character*2 bfType
integer*4 bfSize
integer*4 bfReserved ! actually Reserved1 & 2
integer*4 bfOffBits
! end type BmpFileHeader
! type:: BmpInfoHeader
integer*4 biSize
integer*4 biWidth
integer*4 biHeight
integer*2 biPlanes
integer*2 biBitCount
integer*4 biCompression
integer*4 biSizeImage
integer*4 biXPelsPerMeter
integer*4 biYPelsPerMeter
integer*4 biClrUsed
integer*4 biClrImportant
! end type BmpInfoHeader
!
! Some variables for colours
integer bcColours ! number of colours
integer bcIxPerByte ! colour indices per byte
integer bcBitsPerIx ! bits per colour index
integer bmpPosn
Source File
-----------
! WriteBmp
!
! Create a bmp file.
! This code assumes integer*2 takes up 2 bytes: not the space
! taken by 2 integers. If the implementation is such that it
! takes up the space of 2 integers, lots of declarations will
! have to be changed
!
! Many of the numbers are hard coded: no excuse except laziness
!
! Maximum image size is 32x32. If it is
! Any bigger, change all arrays preceded by !!!!!!CHANGE
!**********************************************************************
program main
! Common Blocks
! Locals
!!!!!!CHANGE
integer image(32,32)
integer imageHeight, imageWidth
! Clear the image
oHeight = 16
oWidth = 16
do 20 x = 1, oWidth, 1
do 10 y = 1, oHeight, 1
oImage(x,y) = 0
10 continue
20 continue
! Draw a cross
do 30 x = 1, oWidth, 1
oImage(x,x) = 1
oImage(oWidth - x + 1, x) = 1
30 continue
! Put a line at the top
do 40 x = 1, oWidth, 1
oImage(x,3) = 1
40 continue
! Put a line at the side
do 50 y = 1, oHeight, 1
oImage(5,y) = 1
50 continue
return
end
!**********************************************************************
! Create a bitmap
!**********************************************************************
subroutine CreateBmp (iFilename, iImage, iWidth, iHeight)
implicit none
! Parameters
character*(*) iFilename
!!!!!!CHANGE
integer iImage(32,32)
integer iHeight
integer iWidth
! Common Blocks
! Locals
integer fhand
fhand = 10
! try
open (
& unit = fhand,
& file = iFilename,
& status = 'UNKNOWN',
& access = 'DIRECT', ! Otherwise it assumes a record header
& form = 'UNFORMATTED',
& recl = 1,
& err = 100)
goto 200
! catch
100 print *, 'Unable to open ', iFilename
return
! end catch
200 continue
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.