Why is Graphics :: DrawImage not stretching the image as expected?

I am doing an overloaded TableLayoutPanelone that draws some fancy borders , but for some reason the call Graphics::DrawImagedoes not work as expected. It looks like I am reducing my image in 1x10 pixels when I stretch it:

alt text

This is the function that performs 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));
    }
}
+3
source share
1 answer

This is a side effect of interpolation when you use extreme magnification. You will need something like this:

 g->InterpolationMode = System::Drawing::Drawing2D::InterpolationMode::NearestNeighbor;
 g->PixelOffsetMode = System::Drawing::Drawing2D::PixelOffsetMode::None;
+4
source

Source: https://habr.com/ru/post/1755131/


All Articles