c++ - 删除GDI+中某行的某一部分

标签 c++ windows gdi+

我有一条类似于箭头的线。我在那条线的顶部画了一个文本。现在我想删除与文本重叠的那部分线

我目前的代码是这样的:

SolidBrush *brush1=new SolidBrush(Color::Color(0,167,255));
StringFormat format; 
format.SetAlignment(StringAlignmentCenter); 
format.SetLineAlignment(StringAlignmentCenter); 
graph->DrawLine(myPen,point2,point1); 
graph->DrawString(strdata,wcslen(strdata),&font,point2,&format,brush1);

我也试过

AdjustableArrowCap *cap1 = new AdjustableArrowCap(5, 5, true);
Pen *myPen1 = new Pen(Color::Color(0,255,255), width);

myPen->SetCustomEndCap(cap1);
GraphicsPath path;
path.AddLine(point1,point2);
Font font(&FontFamily(L"arial"), 21);
Brush *brush=new SolidBrush(Color::Color(0,255,255,255));

SolidBrush solidBrush(Color(255, 255, 0, 0));

StringFormat format;
format.SetAlignment(StringAlignmentCenter);
format.SetLineAlignment(StringAlignmentCenter);
RectF rectbo;
graph->MeasureString(strdata,wcslen(strdata),&font,PointF::PointF(point2),&rectbo);


graph->DrawLine(myPen,point2,point1);
Region pathRegion(&path);
sta=pathRegion.Intersect(rectbo);
graph->fillRegion(pathRegion,&brush);
graph->DrawString(strdata,wcslen(strdata),&font,point2,&format,brush1);

最佳答案

先画线再画文字

  • 还要确保启用画笔纯色/清晰样式
  • 所以文本覆盖文本下方的空间
  • 并且纸张被清除/或保持原样

我帮你找到了

  • Brush Winapi refference
  • 因此设置 LOGBRUSH::lbStyle=BS_NULL; 等效于 bsClear
  • LOGBRUSH::lbStyle=BS_SOLID; 等效于 bsSolid

关于c++ - 删除GDI+中某行的某一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25861431/

相关文章:

c++ - Qt 使用 std::use_facet 和 wstring

windows - 使用 SetProcessWorkingSetSize 的优缺点

c++ - 在 C++ 中使用 GDI+ 平滑动画

c# - 检测应用程序的启动

c++ - IImageList->Draw - 透明度损坏

.net - GDI+:如何在任何设备上绘制一英寸长的线?

c++ - 相同类型的类成员之间的填充总是相同的吗?

c++ - 如何创建一个类,其成员变量包含唯一指针,可复制分配?

c++ - 包含指向对象的指针的多重集的自定义比较器

c# - 如何处理名称超过 259 个字符的文件?