Thread: How save output histogram as png file?

  1. #1
    Registered User
    Join Date
    Jan 2021
    Posts
    1

    How save output histogram as png file?

    Hi. This is my first code in C I wrote ... it is supposed to create a grayscale image histogram. How do I save the histogram to a png file?
    (I'm not sure the code is correct but there are no compile time errors)

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
    unsigned char buffer[10];
    init disp;
    FILE *img;
    
    img = fopen("name.bin", "rb");
    disp = fread(buffer, sizeof(buffer), 1, img);
    
    int hist[256] = { 0 };
    int col = 1200;
    int row = 1500;
    int i;
    int j;
    int J;
    
    for (j = 0; j < row; j++);
    {
           for (i = 0; i < col; i++);
           {
                  J = (disp + i + j*col);
                  hist[J] = hist[J] + 1;
            }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > (I'm not sure the code is correct but there are no compile time errors)
    Well that would be the first step.

    If the code is actually wrong (but you don't know it yet), then even if you're successful with the PNG image, it's still going to look wrong.
    That will lead you to the wrong conclusions as to what is broken.

    As for drawing, start here -> libpng Home Page
    This is quite low level, you'd have to manage all the pixels yourself.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. save output file to excel format
    By imjustnew in forum C++ Programming
    Replies: 18
    Last Post: 12-31-2011, 11:09 AM
  2. save the output of child process
    By gandalf_bar in forum Linux Programming
    Replies: 3
    Last Post: 05-14-2004, 01:59 AM
  3. File input for histogram (programming)
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 07-22-2002, 08:26 PM
  4. how can i save the output of this function to use later?
    By Unregistered in forum C Programming
    Replies: 13
    Last Post: 07-18-2002, 07:27 PM
  5. Help Me ! Print a histogram From a file
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 07-10-2002, 09:57 AM

Tags for this Thread