16 #include <mrpt/config.h> 42 const std::string& targetFileName,
int scaleFactor)
43 : m_scale(scaleFactor), m_targetFile(targetFileName)
47 CreateEnhMetaFileA(
nullptr, targetFileName.c_str(),
nullptr,
nullptr);
72 DeleteEnhMetaFile(CloseEnhMetaFile((HDC)
m_hdc.
get()));
89 LPBITMAPINFO pBmpInfo = (LPBITMAPINFO)
new unsigned char 90 [
sizeof(BITMAPINFOHEADER) + (256 *
sizeof(RGBQUAD))];
94 unsigned int imgWidth = (
unsigned int)img.
getWidth();
95 unsigned int imgHeight = (
unsigned int)img.
getHeight();
97 pBmpInfo->bmiHeader.biSize =
sizeof(BITMAPINFOHEADER);
98 pBmpInfo->bmiHeader.biWidth = imgWidth;
99 pBmpInfo->bmiHeader.biHeight = imgHeight;
100 pBmpInfo->bmiHeader.biPlanes = 1;
102 pBmpInfo->bmiHeader.biBitCount = 8;
103 pBmpInfo->bmiHeader.biCompression = BI_RGB;
104 pBmpInfo->bmiHeader.biSizeImage = 0;
105 pBmpInfo->bmiHeader.biXPelsPerMeter =
106 pBmpInfo->bmiHeader.biYPelsPerMeter = 0;
107 pBmpInfo->bmiHeader.biClrUsed = 0;
108 pBmpInfo->bmiHeader.biClrImportant = 0;
111 for (
unsigned char i = 0; i < 255; i++)
113 pBmpInfo->bmiColors[i].rgbRed = i;
114 pBmpInfo->bmiColors[i].rgbGreen = i;
115 pBmpInfo->bmiColors[i].rgbBlue = i;
116 pBmpInfo->bmiColors[i].rgbReserved = 0;
120 unsigned int lineBytes = imgWidth;
121 if (lineBytes % 2) lineBytes++;
122 if (lineBytes % 4) lineBytes += 2;
124 BYTE* ptrBits =
new BYTE[lineBytes * imgHeight];
126 for (
unsigned int py = 0; py < imgHeight; py++)
127 for (
unsigned int px = 0; px < imgWidth; px++)
128 ptrBits[(py * lineBytes + px) + 0] = *img(px, py);
130 HBITMAP hBitmap = CreateDIBitmap(
131 (HDC)
m_hdc.
get(), &pBmpInfo->bmiHeader, CBM_INIT, ptrBits, pBmpInfo,
137 GetObject(hBitmap,
sizeof(bm), &bm);
139 HDC hdcMem = CreateCompatibleDC((HDC)
m_hdc.
get());
140 HBITMAP hbmT = (HBITMAP)SelectObject(hdcMem, hBitmap);
144 (int)(
m_scale * imgHeight), hdcMem, 0, 0, SRCCOPY);
146 SelectObject(hdcMem, hbmT);
151 DeleteObject(hBitmap);
177 HPEN hPen = CreatePen(penStyle, width, (
unsigned int)color);
179 HPEN hOldPen = (HPEN)SelectObject((HDC)
m_hdc.
get(), hPen);
181 MoveToEx((HDC)
m_hdc.
get(), x0, y0,
nullptr);
184 SelectObject((HDC)
m_hdc.
get(), hOldPen);
201 ::SetBkMode((HDC)
m_hdc.
get(), TRANSPARENT);
202 ::SetTextColor((HDC)
m_hdc.
get(), (
unsigned int)color);
204 ::TextOutA((HDC)
m_hdc.
get(), x0, y0, str.c_str(), (int)str.size());
214 [[maybe_unused]]
const std::string& fontName, [[maybe_unused]]
int fontSize,
215 [[maybe_unused]]
bool bold, [[maybe_unused]]
bool italic)
218 HFONT hFont, oldFont;
221 lpf.lfHeight = fontSize;
223 lpf.lfEscapement = 0;
224 lpf.lfOrientation = 0;
225 lpf.lfWeight = bold ? 700 : 400;
226 lpf.lfItalic = italic ? 1 : 0;
229 lpf.lfCharSet = DEFAULT_CHARSET;
230 lpf.lfOutPrecision = OUT_DEFAULT_PRECIS;
231 lpf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
232 lpf.lfQuality = DEFAULT_QUALITY;
233 lpf.lfPitchAndFamily = DEFAULT_PITCH;
234 os::strcpy(lpf.lfFaceName, LF_FACESIZE, fontName.c_str());
236 hFont = ::CreateFontIndirectA(&lpf);
238 oldFont = (HFONT)::SelectObject((HDC)
m_hdc.
get(), hFont);
240 if (oldFont) ::DeleteObject(oldFont);
266 int x0,
int y0,
int x1,
int y1,
TColor color,
unsigned int width)
268 line(x0, y0, x1, y0, color, width);
269 line(x1, y0, x1, y1, color, width);
270 line(x1, y1, x0, y1, color, width);
271 line(x0, y1, x0, y0, color, width);
#define MRPT_TRY_END
The end of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an ex...
TPenStyle
Definition of pen styles.
#define THROW_EXCEPTION(msg)
size_t getHeight() const override
Returns the height of the image in pixels.
char * strcpy(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcpy.
#define MRPT_TRY_START
The start of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an ...
#define ASSERT_(f)
Defines an assertion mechanism.
size_t getWidth() const override
Returns the width of the image in pixels.
virtual void selectTextFont(const std::string &fontName)
Select the current font used when drawing text.
virtual void filledRectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color)
Draws a filled rectangle.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class for storing images as grayscale or RGB bitmaps.