为什么 Graphics::DrawImage 没有按预期拉伸图像?

发布于 2024-09-10 11:11:40 字数 1181 浏览 4 评论 0原文

我正在制作一个重载的TableLayoutPanel它绘制了一些奇特的边框,但由于某种原因,对 Graphics::DrawImage 的调用无法按预期工作。当我拉伸它时,它似乎淡出了我的 1x10 像素源图像:

alt text

这是进行渲染的函数:

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));
    }
}

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));
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思故 2024-09-17 11:11:40

这是使用极端放大倍率时插值的副作用。你需要这样的东西:

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

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文