views:

28

answers:

1

I'm making an overloaded TableLayoutPanel which draws some fancy borders, but for some reason the call to Graphics::DrawImage isn't working as expected. It seems to fade out my 1x10 pixel source image when I stretch it:

alt text

This is the function which does the rendering:

void GTableLayoutPanel::RenderSides(Graphics^ g, array<Drawing::Image^>^ sideImages)
{
    if( sideImages )
    {
        if( sideImages->Length < 4 )
        {
            throw gcnew System::ArgumentException(String::Format("Not enough images supplied to render sides (expected 4 but only got {0})", sideImages->Length));
        }

        int borderSize = sideImages[0]->Height;
        g->DrawImage(sideImages[0], Rectangle(borderSize, 0, this->Width-borderSize*2, borderSize));
        g->DrawImage(sideImages[1], Rectangle(this->Width-borderSize, borderSize, borderSize, this->Height-borderSize*2));
        g->DrawImage(sideImages[2], Rectangle(borderSize, this->Height-borderSize, this->Width-borderSize*2, borderSize));
        g->DrawImage(sideImages[3], Rectangle(0, borderSize, borderSize, this->Height-borderSize*2));
    }
}
+1  A: 

It is a side-effect of interpolation when you use extreme magnification. You'll need something like this:

 g->InterpolationMode = System::Drawing::Drawing2D::InterpolationMode::NearestNeighbor;
 g->PixelOffsetMode = System::Drawing::Drawing2D::PixelOffsetMode::None;
Hans Passant
Close enough; I found using `PixelOffsetMode::Half` and adding a few more pixels on to hide the occational glitch while scaling horizontally nailed it. I'm starting to think you're stalking my questions Hans ;-)
Jon Cage
@Jon, yes, no kidding. You are aware that you are doing something unusual? Windows Forms coding in C++/CLI is rarely done.
Hans Passant
I'm reminded of that fact on a fairly regular basis ;-) ..but the other Dev's on my team like C++ over C# so we tend to end up writing the GUI's in it as well..
Jon Cage