Visual C++ .NET 2005 Bitmap problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mdavidjohnson
    New Member
    • Sep 2010
    • 6

    #1

    Visual C++ .NET 2005 Bitmap problem

    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?
    private: System::Void button1_Click (System::Object ^ sender, System::EventAr gs^ 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.FromA rgb(cArg,cRed,c Green,cBlue);
    TempBitmap->SetPixeli,j,Te mpColor);
    }
    }
    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
  • mdavidjohnson
    New Member
    • Sep 2010
    • 6

    #2
    TempBitmap->SetPixeli,j,Te mpColor);

    should read

    TempBitmap->SetPixel(i,j,T empColor);

    Odd, the "(" is there in the snippet I copied, I don't know how it got lost. :-(

    Comment

    • mdavidjohnson
      New Member
      • Sep 2010
      • 6

      #3
      Thanks to Viorel at social_dot_msdn _dot_microsoft_ dot_com, the solution is to replace the TempColor assignment line with:

      TempColor = Color::FromArgb (cArg,cRed,cGre en,cBlue);

      I’ve tested this and it works.

      M. David Johnson
      mdj@bds-soft.com

      Comment

      Working...