I need some guidance on how to resize a bmp image at run time. I thought I should use a 2 dimensional dynamic array.
What steps do I need to take to do something like this. fread and fwrite are working.
I now use a for loop to read the file row by row. But how to go any further.
In the mean time I found the steps:
1. Open the file
2. Start reading the header information
3. Allocate memory to hold the image
4. continue reading and decode the image from the file format to your memory
format
5. close the file
6. resize the image in memory
7. open a new file for writing
8. write the header
9. write the image data, encoding the memory image according to the file
format
10. close the output file
Now to see how I can use a dynamic array with fread as input, someone any idea ?
Code:
int **array = malloc(biHeight * sizeof(int *));
array[0] = malloc(biHeight * bi.biWidth * sizeof(int));
for(i = 1; i < biHeight; i++)
array[i] = array[0] + i * bi.biWidth;
// iterate over infile's scanlines
for (int i = 0 ; i < biHeight; i++)
{
// iterate over pixels in scanline
for (int j = 0; j < bi.biWidth; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}