Thread: resize image

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    44

    resize image

    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);
            }
    Last edited by lamko; 08-26-2011 at 08:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-13-2010, 05:10 AM
  2. Replies: 13
    Last Post: 11-20-2009, 04:43 PM
  3. png Image Resize
    By bhupesh.kec in forum C Programming
    Replies: 3
    Last Post: 12-06-2007, 07:52 AM
  4. Problems with Image Magick [Unable to Quantisize Image]
    By Maragato in forum C Programming
    Replies: 1
    Last Post: 09-18-2006, 10:41 PM
  5. Resize Image File???
    By stickman in forum C++ Programming
    Replies: 4
    Last Post: 09-19-2004, 11:46 AM