hi,
i have to do image read and write in Turbo C.
i am very new to C.
so please help me out as to how to do these operations and provide some sample code if you have any..
i have a vague idea that it can be read as .dat file and stored in a 2d array.
I didn't know anybody still used this old horse!
Anyway, I found something in my archives and removed the dust! This reads a character file, you want to read a binary file. The end of file marker will be different. Well partner, it's a start!
[PHP]/******************************* fgetc.c ********************************
**
** Experiments with disk file I/O:
** int fgetc(FILE *stream)
** Get a character from the device indicated by stream ( set by fopen() ).
** Written in Turbo C by vegaseat 6/23/88
**
****************************************************************************/
#include <stdio.h> /* defines FILE and EOF */
#define AMOUNT 5 /* amount of data items */
#define FALSE 0
#define TRUE 1
int display_file(void);
void main(void)
{
if (display_file() == FALSE)
puts("\n Couldn't open data file!");
printf("\n\n Press any key to go on .... ");
getchar(); /* wait */
}
int display_file(void) /* read an ASCII file and display on screen */
{
int ch; /* use int since EOF = -1 */
char filename[25];
FILE *fptr;
clrscr();
printf("\n Enter name of ASCII file : ");
gets(filename);
fptr = fopen(filename,"r"); /* open file for disk reading */
thanks a lot vegaseat..
ur code is working great..
i am actually reading a gray scale image, which has 0-255 levels of gray intensities.
so each pixel in the image or each character represents a level of gray intensity(eight bits in binary).
but as far as characters are concerned, there are only 128 ascii chars, so how can 128 ascii chars represent 256 levels of image intensities??
guess i made my question clear enough..
can anyone clear it for me???
what u need to do is to find out the header and pixel structures for the type of file ur reading and then declare them as structs at the start of ur code. Then u can read in chunks of data from your binary file using fwrite and fread and cast it into ur structs and edit it.
You got me stomped, which is easy to do.
Looking through the dusty old code I noticed that I assigned the incoming character to type integer to trap the End Of File marker (-1). It makes me suspicious that in Turbo C type char was unsigned 8bit (0 to 255).
In fact, 1 byte = 8 bits; so a char variable can have 2^8 = 256 values; this have nothing to do with ASCII chars...
i have an 256x256 grayscale image in .dat format.
i am reading the file in turbo C in an 2d char array and comparing with another similar picture to check if they are the same..
and i am doing some enhancement of the original image,
and to view the enhanced image, am changing .dat to .raw format and viewing in adobe photoshop.
well is this process right?
in the sense that getting an gray scale image in 2d char array.
will it be exactly reproduced.
will the 2d char array handle a gray scale image?
thats my basic doubt..
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.