谁能给我提供一个使用 CreateHatchBrush 的示例

发布于 2024-07-10 13:25:30 字数 92 浏览 2 评论 0原文

我想在我的软件中的缩略图周围绘制阴影。 看来 CreateHatchBrush 可以提供帮助,但我不知道如何使用它,任何人都可以为我提供 C++ 示例吗? 非常感谢!

I want to draw a shadow around a thumbnail in my software.
It seems CreateHatchBrush can help but I do not know how to use it, can anyone provide me a sample in C++?
Many thanks!

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

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

发布评论

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

评论(2

揽清风入怀 2024-07-17 13:25:30

最简单的选择是使用 GDI+做这个。 这是一个快速而肮脏的阴影渲染示例:

void Render( HDC hdc )
{
    Graphics gr( hdc );
    Image image( L"sample.jpg" );
    const int SHADOW_OFFSET = 7;

    //
    // draw shadow
    //
    SolidBrush shadow( Color( 190, 190, 190 ) );
    Rect rc( 50, 50, image.GetWidth(), image.GetHeight() );
    rc.Offset( SHADOW_OFFSET, SHADOW_OFFSET );
    gr.FillRectangle( &shadow, rc );

    //
    // draw the image
    //
    gr.DrawImage( &image, 50, 50, image.GetWidth(), image.GetHeight() );

    //
    // draw a border
    //
    Pen border( Color( 0, 0, 0 ), 1 );
    rc.Offset( -SHADOW_OFFSET, -SHADOW_OFFSET );
    gr.DrawRectangle( &border, rc );
}

希望这有帮助!

The easiest option would be to use GDI+ to do this. Here's a quick and dirty shadow rendering sample:

void Render( HDC hdc )
{
    Graphics gr( hdc );
    Image image( L"sample.jpg" );
    const int SHADOW_OFFSET = 7;

    //
    // draw shadow
    //
    SolidBrush shadow( Color( 190, 190, 190 ) );
    Rect rc( 50, 50, image.GetWidth(), image.GetHeight() );
    rc.Offset( SHADOW_OFFSET, SHADOW_OFFSET );
    gr.FillRectangle( &shadow, rc );

    //
    // draw the image
    //
    gr.DrawImage( &image, 50, 50, image.GetWidth(), image.GetHeight() );

    //
    // draw a border
    //
    Pen border( Color( 0, 0, 0 ), 1 );
    rc.Offset( -SHADOW_OFFSET, -SHADOW_OFFSET );
    gr.DrawRectangle( &border, rc );
}

Hope this helps!

孤星 2024-07-17 13:25:30

我没有示例,但有一些关于 Windows 中画笔的一般用法的提示。

CreateHatchBrush() 返回一个句柄。 您需要使用该句柄使该画笔成为您用于渲染的设备上下文中的当前画笔。 调用设备上下文的 SetObject 函数(普通 Windows GDI 调用版本):

HDC myDC = GetDC (hWnd); //pass your window handle here or NULL for the entire screen  
HBRUSH hatchBrush = CreateHatchBrush (HS_DIAGCROSS, RGB (255,128,0));  
HBRUSH oldBrush = SelectObject (myDC, hatchBrush);  
//draw something here  
SelectObject (myDC, oldBrush); //restore previous brush  
ReleaseDC (myDC);

I don't have a sample, but some hints on general usage of brushes in Windows.

CreateHatchBrush() returns a handle. You need to use that handle to make that brush the current brush in the Device Context you are using to render. Call the Device Context's SetObject function (plain Windows GDI calls version):

HDC myDC = GetDC (hWnd); //pass your window handle here or NULL for the entire screen  
HBRUSH hatchBrush = CreateHatchBrush (HS_DIAGCROSS, RGB (255,128,0));  
HBRUSH oldBrush = SelectObject (myDC, hatchBrush);  
//draw something here  
SelectObject (myDC, oldBrush); //restore previous brush  
ReleaseDC (myDC);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文