Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
How do I create an image and set its color?
Posted
Updated 15-Feb-11 8:58am
v2
Comments
William Winner 15-Feb-11 14:56pm    
FYI, adding a question mark to a statement doesn't make it a question.

A proper question would have been...How do I create an image and set it's color?
Nish Nishant 15-Feb-11 14:59pm    
>> A proper question would have been...How do I create an image and set it's color? <<

its (not it's) :-)
William Winner 15-Feb-11 15:00pm    
touche!
Nish Nishant 15-Feb-11 15:01pm    
One of Murphy's laws I guess. If you correct grammar, you are bound to make a mistake yourself. :-)
cechode 15-Feb-11 15:38pm    
Murphy's law does not take into account the "reason" for why it will go wrong.
He's not bound to make a spelling mistake because he corrects someone else spelling error.
He made the mistake because it was there to be made. :)

Hope Image-Processing-in-C#[^] and Image Processing Lab in C#[^]article from Cp might help you.
 
Share this answer
 
C#
public static Bitmap CreateBitmap(int width, int height, Color color)
{
    Bitmap b = new Bitmap(width, -height);
    using (Graphics g = Graphics.FromImage(b))
    {
        g.Clear(color);
    }
    return b;
}
 
Share this answer
 
Here's an easy but rather inefficient approach:

C#
Bitmap bitmap = new Bitmap(100, 100);
for (int i = 0; i < 100; i++)
{
    for (int j = 0; j < 100; j++)
    {
        bitmap.SetPixel(i, j, Color.Blue);
    }
}
 
Share this answer
 
Comments
JOAT-MON 15-Feb-11 16:00pm    
And if the OP does a little exploration, he might even find a nifty function in the Graphics class (Hint, hint to OP)!
I'll put in as much answering as you did asking.

C# create image[^]
C# image color[^]
 
Share this answer
 
Comments
CPallini 15-Feb-11 14:56pm    
:-) 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900