TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Christos Alexiou
NA
61
0
SetPixel method in C#
May 11 2010 6:13 AM
Hello to everyone,
I'm writing code for an application form with a pictureBox inside it.
All i want to do is, to load an image (in a picture box) and after that to change pixels in this image.
After searching, I've already read that SetPixel Method-in C#-can help me with that!
In PaintEvent of pictureBox the code is:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
// Create a Bitmap object from a file.
Bitmap myBitmap = new Bitmap("D:\\...\\SP_A0195.jpg");
// Draw myBitmap to the screen.
e.Graphics.DrawImage(myBitmap,0,0,myBitmap.Width,myBitmap.Height);
// Set each pixel in myBitmap to red.
for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
{
for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
{
myBitmap.SetPixel(Xcount, Ycount, Color.Red);
}
}
// Draw myBitmap to the screen again.
e.Graphics.DrawImage(myBitmap,myBitmap.Width,0,myBitmap.Width,myBitmap.Height);
}
The code above doesn't work but i can not understand why...please help on how to do that.
Thank you in advance for your time!
Reply
Answers (
11
)
how to develop a C# program for pc to pc fiber optic communication
Compare PictureBoxes