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_contex t = 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(wind ow, ID_FNAME); // get file box handle
GetWindowText(f ile_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(imgform atg, 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(cleari ng_context, col+50, row+50, RGB(clear[row][col][0], clear[row][col][1], clear[row][col][2]));
//print out saved Message
SetWindowText(f ile_name_box, savemessage);
return(0);
}