I'm trying to learn how to modify Bitmaps programatically.
As a first attempt, I'm trying to simply create a blank bitmap, programatically change it to all red, and display it in a pictureBox.
The following code builds without error and, under "Start Without Debugging" runs without error except the blank pictureBox remains blank - no red bitmap is displayed in it. Any suggestions?
Also, forum technical question: this code was properly indented when I entered it, but it semms to be displayed all left justified no matter what I do, including using the "code" tag. How do I make it display properly here?
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
Bitmap^ TempBitmap;
TempBitmap = gcnew Bitmap(33,33);
Color TempColor;
unsigned char cArg;
unsigned char cRed;
unsigned char cGreen;
unsigned char cBlue;
for (int i=0; i<33; i++)
{
for (int j=0; j<33; j++)
{
cArg = 255;
cRed = 255;
cGreen = 0;
cBlue = 0;
TempColor.FromArgb(cArg,cRed,cGreen,cBlue);
TempBitmap->SetPixel(i,j,TempColor);
}
}
pictureBox1->Image = TempBitmap;
label4->Text = "DONE";
}
Yes, I know it's inefficient to put the color assignments inside the loop because they never change. But, since that's where I'll eventually put color modifications coding, they make good placeholders.
M. David Johnson
mdj@bds-soft.com
As a first attempt, I'm trying to simply create a blank bitmap, programatically change it to all red, and display it in a pictureBox.
The following code builds without error and, under "Start Without Debugging" runs without error except the blank pictureBox remains blank - no red bitmap is displayed in it. Any suggestions?
Also, forum technical question: this code was properly indented when I entered it, but it semms to be displayed all left justified no matter what I do, including using the "code" tag. How do I make it display properly here?
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
Bitmap^ TempBitmap;
TempBitmap = gcnew Bitmap(33,33);
Color TempColor;
unsigned char cArg;
unsigned char cRed;
unsigned char cGreen;
unsigned char cBlue;
for (int i=0; i<33; i++)
{
for (int j=0; j<33; j++)
{
cArg = 255;
cRed = 255;
cGreen = 0;
cBlue = 0;
TempColor.FromArgb(cArg,cRed,cGreen,cBlue);
TempBitmap->SetPixel(i,j,TempColor);
}
}
pictureBox1->Image = TempBitmap;
label4->Text = "DONE";
}
Yes, I know it's inefficient to put the color assignments inside the loop because they never change. But, since that's where I'll eventually put color modifications coding, they make good placeholders.
M. David Johnson
mdj@bds-soft.com