如何在圆圈内绘制图像
How to draw an image inside a circle?
我有一个MFC应用程序,我需要在圆圈内绘制图像(或在圆圈中裁剪图像(。
我使用免费映射来加载图像,因此使用免费映像或MFC功能的答案将起作用。
这就是我加载图像的方式:
void DrawImage(CDC *pDC, RECT *pRect, const BYTE *pBuffer, int nBufferLength)
{
FIMEMORY *pfmem = FreeImage_OpenMemory((BYTE*)pBuffer, nBufferLength);
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(pfmem);
FIBITMAP *pdib = FreeImage_LoadFromMemory(fif, pfmem);
sz.cx = FreeImage_GetWidth(pdib);
sz.cy = FreeImage_GetHeight(pdib);
CRect rc(pRect);
BITMAPINFO *pbmpi = FreeImage_GetInfo(pdib);
BYTE *pDibBits = FreeImage_GetBits(pdib);
::SetDIBitsToDevice(pDC->GetSafeHdc(),
rc.left,
rc.top,
rc.Width(),
rc.Height(),
0,
0,
0,
rc.Height(),
pDibBits,
pbmpi,
DIB_RGB_COLORS);
FreeImage_Unload(pdib);
FreeImage_CloseMemory(pfmem);
}
发布我的答案,以防有人在同一问题中运行,实际上很容易做到了@karthik Krish写的:
// Get the rect of a circle in the center o the image.
CRect rectMask(pRect);
int cx = rectMask.Width();
int cy = rectMask.Heigth();
if (cx > cy)
{
rectMask.left += (cx - cy) / 2;
rectMask.right = rectMask.left + cy;
}
else
{
rectMask.top += (cy - cx) / 2;
rectMask.bottom = rectMask.top + cx;
}
HRGN hRegiaoClip = NULL;
// Create a region for the circle
hRegiaoClip = ::CreateEllipticRgnIndirect(&rectMask);
// Select circle in the Device context.
::SelectClipRgn(pDC->GetSafeHdc(), hRegiaoClip);
// Call function to draw the image (the one in the question).
DrawImage(pDC, pRect, pImgBytes, pSerial->GetImageBufferSize(), TRUE);
// Clean up
::SelectClipRgn(pDC->GetSafeHdc(), NULL);
::DeleteObject(hRegiaoClip);
相关文章:
- 如何在 direct2d 中使用随其窗口重新缩放的效果绘制图像
- 如何在圆圈内绘制图像
- SDL 不绘制图像
- 如何使用QGraphicsItem绘制图像?
- 使用图像指针绘制图像
- 如何在圆角矩形或圆形内部绘制图像
- 在屏幕上绘制图像后背景发生变化
- 在 Allegro5 中绘制图像/字体的一部分
- C++ WinApi 绘制图像.jpg到新窗口
- 无法从 Direct2D png 使用 DirectX9 绘制图像精灵
- 在中心绘制图像,同时保持纵横比
- 如何在MFC对话框的静态区域中绘制图像
- c++在位图上绘制图像并保存
- 在 Direct2D 中绘制图像的一部分
- wxWidgets:定期在wxFrame中重新绘制图像
- 绘制图像的功能
- 在图片控件中绘制图像
- 你如何从矢量<CvPoints>或矢量绘制图像<Point2f>?
- Visual C++如何使用CPaintDC、CDC在CView中重新绘制图像
- OpenGL绘制图像.PIC库