C/C++ Windows API

Moderators: Lundin
Number of threads: 450
Number of posts: 1225

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
save the content of polygon to 2d char array buffer for storing pixels Posted by anujkawasthi on 11 Sept 2008 at 2:56 AM
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.


Report
Re: buffer for storing pixels Posted by Malcolm_McLean on 11 Sept 2008 at 10:49 AM
: 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.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.