Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

save the content of polygon to 2d char array buffer for storing pixels

Hi All,
I have written code for draw a regular polygon for drawing rectangle, pentagon , hexagon etc.
Now i want to save the content of polygon to 2d char array buffer for storing pixels and save it into a bitmap image file.

But i am not able to do this.
please anyone can help me.


Thanks & Regards
Anuj Awasthi.


Comments

  • Malcolm_McLeanMalcolm_McLean Posts: 248Member ✭✭
    : Hi All,
    : I have written code for draw a regular polygon for drawing
    : rectangle, pentagon , hexagon etc.
    : Now i want to save the content of polygon to 2d char array buffer
    : for storing pixels and save it into a bitmap image file.
    :
    : But i am not able to do this.
    : please anyone can help me.
    :
    Don't try.
    Allocate a buffer of width * height

    by
    char *buff = malloc(width * height);

    now you can access the pixels like this

    buff[y*width+x] = val;

    You will need to call a getpixel or similar routine to read the pixel values off the screen, then place them in your buffer. You might need to look up the colour in the palette to convert from rgb values to palette indices.

    There is a routine on my website that save .bmp files. Look under the "Basic Algorithms" source code link.
Sign In or Register to comment.