By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,110 Members | 990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,110 IT Pros & Developers. It's quick & easy.

save code for a .pnm image editor

P: 1
hi,

This is my first post in this forum and I just wanted to thank you for even taking a look at my post. The class that I am writing the C code for is my first computer class and my knowledge is limited to what was taught in lectures.

Right now I am making a GUI code and am having trouble saving the image after it has been altered. As of now, the only way that I know how to save is to save over the original picture, but that doesn't even work when I open the new image.

My goal is to not save the new image over the original, but to have a new image file when the save button is pressed. I have no idea where to start.

Thanks again for your suggestions/guidance.

This is what I have so far..


//Save image file (need code)
int SaveFile(HWND window)
{
// Declare local variables
HDC clearing_context = GetDC(window);
HWND file_name_box;
char filename[MAXLETTERS];
char savemessage[ MAXLETTERS ] = "Image Saved! please re-load the image";
char imgformatg[80] = "p5";
FILE * outfile;
int count;

// Get the output file's name from the File Text Box
file_name_box = GetDlgItem(window, ID_FNAME); // get file box handle
GetWindowText(file_name_box, filename, MAXLETTERS); // get file name from file box

// Open the input file, for writing
outfile = fopen( filename , "w");

// Write-out image information from the input file
fprintf(outfile,"%s", imgformat);
fprintf(outfile,"%d", imgwidth);
fprintf(outfile,"%d", imgheight);
fprintf(outfile,"%d", imgdepth);

// Write-out the image data from the input file
count = 0;
if (strcmp(imgformatg, imgformat))
{
//for gray scale image
for (row = 0 ; row < imgheight ; row++)
for (col = 0 ; col < imgwidth ; col++)
{
fputc(imgdata[row][col][0], outfile);
count++;
}
}
else
{
//for color image
for (row = 0 ; row < imgheight ; row++)
for (col = 0 ; col < imgwidth ; col++)
for (plane = 0 ; plane < 3 ; plane++)
{
fputc(imgdata[row][col][plane], outfile);
count++;
}
}

// close the output file
fclose(outfile);

//clear the background after saving
for (row = 0 ; row < imgheight ; row++)
for (col = 0 ; col < imgwidth ; col++)
SetPixel(clearing_context, col+50, row+50, RGB(clear[row][col][0], clear[row][col][1], clear[row][col][2]));

//print out saved Message
SetWindowText(file_name_box, savemessage);

return(0);
}
May 2 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.