CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2010
    Posts
    4

    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::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

    Edit by admin: no contact info permitted on the forum, thank you

  2. #2
    Join Date
    Sep 2010
    Posts
    4

    Re: Visual C++ .NET 2005 Bitmap Problem

    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,cGreen,cBlue);

    I’ve tested this and it works.

    M. David Johnson

  3. #3
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+) ovidiucucu has a reputation beyond repute (3000+)
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    7,888

    Re: Visual C++ .NET 2005 Bitmap Problem

    [ Moved thread ]

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width