13 #pragma comment(lib, "Msimg32.lib")
17 #define AC_SRC_ALPHA 0x01
99 TParam(
const SIZE& s) : size(s), work(s.cx * s.cy)
104 size.cx = size.cy = 0;
115 CRawData(
const SIZE& s) : m_pParam(new TParam(s)) { }
121 bool IsValid(
void)
const {
return m_pParam->size.cx != 0; }
126 const SIZE&
GetSize(
void)
const {
return m_pParam->size; }
131 size_t GetLineBytes(
void)
const {
return m_pParam->size.cx *
sizeof(RGBQUAD); }
139 RGBQUAD*
Refer(
void) {
return m_pParam->work; }
147 const RGBQUAD*
Refer(
void)
const {
return m_pParam->work; }
157 if ( y >=
static_cast<UINT
>(m_pParam->size.cy) ) {
return NULL; }
158 return Refer() + (m_pParam->size.cy - y - 1) * m_pParam->size.cx;
169 if ( y >=
static_cast<UINT
>(m_pParam->size.cy) ) {
return NULL; }
170 return Refer() + (m_pParam->size.cy - y - 1) * m_pParam->size.cx;
175 CBitmapImage(
void) : m_bmp(), m_pRgb(NULL), m_backDC(NULL), m_backBmp(NULL)
176 , m_hWnd(NULL), m_nStretchMode(DEFAULT_STRETCHMODE)
187 , m_hWnd(NULL), m_nStretchMode(DEFAULT_STRETCHMODE)
199 , m_hWnd(other.m_hWnd), m_size(other.m_size), m_nStretchMode(other.m_nStretchMode)
214 m_pRgb = other.m_pRgb;
215 m_size = other.m_size;
216 m_hWnd = other.m_hWnd;
217 m_nStretchMode = other.m_nStretchMode;
282 m_nStretchMode = nStretchMode;
283 if ( m_backDC != NULL )
286 ::SetBrushOrgEx(m_backDC, 0, 0, NULL);
318 ASSERT0( !
IsEmpty(),
"CBitmapImage::GetSize()",
"画像を持っていないオブジェクトからサイズを取得しようとしています。" );
331 if ( ::GetObject(m_bmp,
sizeof(BITMAP), &bp) > 0 )
333 ::ZeroMemory(&_head,
sizeof(BITMAPINFOHEADER));
334 _head.biSize =
sizeof(BITMAPINFOHEADER);
335 _head.biWidth = bp.bmWidth;
336 _head.biHeight = bp.bmHeight;
337 _head.biPlanes = bp.bmPlanes;
338 _head.biBitCount = bp.bmBitsPixel;
339 _head.biCompression = BI_RGB;
340 _head.biSizeImage = bp.bmWidthBytes * bp.bmHeight;
394 bool Set(
int cx,
int cy, COLORREF color = CLR_INVALID)
396 CWorkDC workDC(m_hWnd);
397 RGBQUAD* pRgb = NULL;
398 HBITMAP h = ms_CreateBitmap(pRgb, workDC, cx, cy);
399 if ( h != NULL && m_Set(h, pRgb) )
401 ASSERT( m_pRgb != NULL );
422 bool SetEx(HDC hDC,
int cx,
int cy, COLORREF color = CLR_INVALID)
424 HBITMAP h = ::CreateCompatibleBitmap(hDC, cx, cy);
425 bool r = ( h != NULL && m_Set(h) );
443 RGBQUAD* pRgb = NULL;
458 if ( cx == 0 && cy == 0 )
460 return Set(bmpimg.m_bmp);
462 bmpimg.m_CheckSize(cx, cy);
468 bool r = bmpimg.
StretchBlt(dc, 0, 0, SRCCOPY, cx, cy);
489 const SIZE& size = rawData.
GetSize();
490 if (
Set(size.cx, size.cy) )
492 ASSERT( m_pRgb != NULL );
493 MemCopy(m_pRgb, rawData.
Refer(), m_size.cy * m_size.cx);
509 bool SetFromDC(HDC hdc,
const RECT& rect,
int cx = 0,
int cy = 0)
513 if ( ms_CheckSize(s, rect) &&
Set(s.cx, s.cy) )
518 if ( cx <= 0 || cy <= 0 )
520 ::BitBlt(dc, 0, 0, s.cx, s.cy, hdc, rect.left, rect.top, SRCCOPY);
524 ::StretchBlt(dc, 0, 0, cx, cy, hdc, rect.left, rect.top, s.cx, s.cy, SRCCOPY);
545 ::GetIconInfo(hIcon, &ii);
548 if ( ! biColor.
Set(ii.hbmColor) || ! biMask.
Set(ii.hbmMask) )
552 const SIZE& size = biColor.
GetSize();
553 bool r =
Set(size.cx, size.cy, backColor);
554 r &=
Insert(0, 0, biMask, SRCAND);
555 r &=
Insert(0, 0, biColor, SRCPAINT);
576 bool SetFromClient(HWND hWnd,
const RECT& rect, COLORREF backColor = CLR_INVALID)
578 if (
Set(rect.right - rect.left, rect.bottom - rect.top, backColor) )
584 ::SetWindowOrgEx(dc, rect.left, rect.top, NULL);
585 WPARAM w =
reinterpret_cast<WPARAM
>(dc);
586 if ( backColor == CLR_AUTOSELECT )
588 ::SendMessage(hWnd, WM_ERASEBKGND, w, 0);
590 ::SendMessage(hWnd, WM_PRINTCLIENT, w, PRF_CLIENT);
616 if ( ::GetClientRect(hWnd, &rect) )
652 LPARAM mode = PRF_CLIENT | PRF_ERASEBKGND | PRF_NONCLIENT | PRF_OWNED)
655 if ( ::GetWindowRect(hWnd, &rect) &&
Set(rect.right - rect.left, rect.bottom - rect.top, backColor) )
660 ::SendMessage(hWnd, WM_PRINT,
reinterpret_cast<WPARAM
>(dc), mode);
683 bool InsertEx(
int x,
int y, HBITMAP hBitmap, UINT uExFlag = DSS_NORMAL)
688 LPARAM l =
reinterpret_cast<LPARAM
>(hBitmap);
689 bool r = !! ::DrawState(dc, NULL, NULL, l, 0, x, y, 0, 0, DST_BITMAP | uExFlag);
748 bool Insert(
int x,
int y,
const CBitmapImage& bmpimg, DWORD raster = SRCCOPY,
int cx = 0,
int cy = 0)
755 bool r = bmpimg.
StretchBlt(dc, x, y, raster, cx, cy);
814 bool r = bmpimg.
AlphaBlend(dc, x, y, parsent, cx, cy);
861 bool Fill(COLORREF color,
const RECT& rect)
866 COLORREF c = ::GetBkColor(dc);
867 ::SetBkColor(dc, color);
868 bool r = !! ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
885 RECT rect = { 0, 0, m_size.cx, m_size.cy };
886 return Fill(color, rect);
914 size.cx = pRect->right - pRect->left;
915 size.cy = pRect->bottom - pRect->top;
928 if ( size.cx > 0 && size.cy > 0 )
931 bi.
Set(size.cx, size.cy);
932 ASSERT( bi.m_pRgb != NULL );
933 int r1 = GetRValue(color1);
934 int g1 = LOBYTE((color1 >> 8) & 0xFF);
935 int b1 = GetBValue(color1);
936 int r2 = GetRValue(color2);
937 int g2 = LOBYTE((color2 >> 8) & 0xFF);
938 int b2 = GetBValue(color2);
940 if ( a <= 0 ) { a = 1; }
943 bi.m_pRgb[i].rgbRed =
static_cast<BYTE
>((r1 * (a - i) / a) + (r2 * i / a));
944 bi.m_pRgb[i].rgbGreen =
static_cast<BYTE
>((g1 * (a - i) / a) + (g2 * i / a));
945 bi.m_pRgb[i].rgbBlue =
static_cast<BYTE
>((b1 * (a - i) / a) + (b2 * i / a));
950 ::SetBrushOrgEx(dc, pRect->left, pRect->top, NULL);
952 ::SetBrushOrgEx(dc, 0, 0, NULL);
956 RECT rect = { 0, 0, m_size.cx, m_size.cy };
976 bool GradationFill(COLORREF color1, COLORREF color2,
bool boIsHorizontal,
const RECT* pRect = NULL)
993 bool GradientFill(
const PTRIVERTEX pVertex, DWORD dwNumVertex,
const PGRADIENT_RECT pMesh, DWORD dwNumMesh,
bool boIsHorizontal)
998 DWORD dwMode = boIsHorizontal ? GRADIENT_FILL_RECT_H : GRADIENT_FILL_RECT_V;
999 bool r = !!
::GradientFill(dc, pVertex, dwNumVertex, pMesh, dwNumMesh, dwMode);
1017 loop ( i, m_size.cx * m_size.cy )
1019 m_pRgb[i].rgbReserved = alpha;
1039 colorEx = (colorEx & 0x0000ff00) | (colorEx & 0x00ff0000) >> 16 | (colorEx & 0x000000ff) << 16;
1040 RGBQUAD* pRgba = m_pRgb;
1041 loop ( i, m_size.cx * m_size.cy )
1043 if ( (*(
reinterpret_cast<COLORREF*
>(pRgba)) & 0x00FFFFFF) == colorEx )
1045 pRgba->rgbReserved = alphaEx;
1049 pRgba->rgbReserved = alpha;
1068 if ( ! bi.
Set(bmp) )
1072 if ( ! m_CheckDib() || ! bi.m_CheckDib() )
1076 if ( bi.m_size.cx < m_size.cx || bi.m_size.cy < m_size.cy )
1080 loop ( y, m_size.cy )
1084 loop ( x, m_size.cx )
1086 pBase->rgbReserved = pSrc->rgbRed;
1107 targetColor = (targetColor & 0x0000ff00) | (targetColor & 0x00ff0000) >> 16 | (targetColor & 0x000000ff) << 16;
1108 drawColor = (drawColor & 0x0000ff00) | (drawColor & 0x00ff0000) >> 16 | (drawColor & 0x000000ff) << 16;
1109 COLORREF* pRgba =
reinterpret_cast<COLORREF*
>(m_pRgb);
1110 loop ( i, m_size.cx * m_size.cy )
1112 if ( ((*pRgba) & 0x00FFFFFF) == targetColor )
1145 TRGB* R =
reinterpret_cast<TRGB*
>(&r);
1146 TRGB* G =
reinterpret_cast<TRGB*
>(&g);
1147 TRGB* B =
reinterpret_cast<TRGB*
>(&b);
1148 RGBQUAD* P = m_pRgb;
1149 loop ( i, m_size.cx * m_size.cy )
1151 int rr = P->rgbRed * R->rgbRed + P->rgbGreen * R->rgbGreen + P->rgbBlue * R->rgbBlue;
1152 int gg = P->rgbRed * G->rgbRed + P->rgbGreen * G->rgbGreen + P->rgbBlue * G->rgbBlue;
1153 int bb = P->rgbRed * B->rgbRed + P->rgbGreen * B->rgbGreen + P->rgbBlue * B->rgbBlue;
1154 P->rgbRed =
static_cast<BYTE
>(min(rr / 255, 255));
1155 P->rgbGreen =
static_cast<BYTE
>(min(gg / 255, 255));
1156 P->rgbBlue =
static_cast<BYTE
>(min(bb / 255, 255));
1176 if ( ms_CheckSize(s, rect) )
1178 ms_CheckSize(cx, cy, s);
1179 CWorkDC workDC(m_hWnd);
1180 CTempDC dc(workDC, m_bmp);
1182 HDC tempDc = bi.
GetDC();
1183 if ( tempDc != NULL )
1185 bool r = !!
::StretchBlt(tempDc, 0, 0, cx, cy, dc, rect.left, rect.top, s.cx, s.cy, SRCCOPY);
1210 if ( !
IsEmpty() && m_backDC == NULL )
1212 CWorkDC workDC(m_hWnd);
1213 m_backDC = ::CreateCompatibleDC(workDC);
1214 m_backBmp = ::SelectObject(m_backDC, m_bmp);
1216 ::SetBrushOrgEx(m_backDC, 0, 0, NULL);
1230 if ( m_backDC != NULL )
1251 HBITMAP hMonoBitmap = ::CreateBitmap(m_size.cx, m_size.cy, 1, 1, NULL);
1252 CTempBitmapDC hdc(m_hWnd, hMonoBitmap);
1253 RGBQUAD aColors[2] = { {0, 0, 0, 0}, {255, 255, 255, 0} };
1254 ::SetDIBColorTable(hdc, 0, 2, aColors);
1255 RECT rect = { 0, 0, m_size.cx, m_size.cy };
1256 if ( ! boIsReverse )
1258 ::FillRect(hdc, &rect,
static_cast<HBRUSH
>(::GetStockObject(WHITE_BRUSH)));
1259 ::FillRgn(hdc, rgn,
static_cast<HBRUSH
>(::GetStockObject(BLACK_BRUSH)));
1263 ::FillRect(hdc, &rect,
static_cast<HBRUSH
>(::GetStockObject(BLACK_BRUSH)));
1264 ::FillRgn(hdc, rgn,
static_cast<HBRUSH
>(::GetStockObject(WHITE_BRUSH)));
1280 if ( !
IsEmpty() && m_backDC == NULL )
1282 if ( m_pRgb == NULL )
1284 RGBQUAD* pRgb = NULL;
1314 if ( transColor == CLR_INVALID )
1316 return ::CreateRectRgn(0, 0, m_size.cx, m_size.cy);
1319 if ( ! bi.m_CheckDib() )
1324 transColor = (transColor & 0xff00ff00) |
1325 (transColor & 0x00ff0000) >> 16 |
1326 (transColor & 0x000000ff) << 16;
1328 CWorkMem rgbWork(
sizeof(RGNDATAHEADER) +
sizeof(RECT) * bi.m_size.cx * bi.m_size.cy);
1329 LPRGNDATA pRgnData =
reinterpret_cast<LPRGNDATA
>(rgbWork.
Ref());
1330 LPRECT pRect =
reinterpret_cast<LPRECT
>(pRgnData->Buffer);
1334 const COLORREF* pScanData =
reinterpret_cast<const COLORREF*
>(bi.
GetRgbDataPtr(y));
1335 if ( transColor == CLR_AUTOSELECT )
1337 transColor = pScanData[0];
1340 loop ( x, bi.m_size.cx )
1342 if ( pScanData[x] == transColor )
1347 pRect->left = down_cast<long>(x);
1348 for ( ; x < static_cast<size_t>(bi.m_size.cx); x++ )
1350 if ( pScanData[x] == transColor ) {
break; }
1353 pRect->right =
static_cast<LONG
>(x);
1354 pRect->top =
static_cast<LONG
>(y);
1355 pRect->bottom =
static_cast<LONG
>(y + 1);
1361 pRgnData->rdh.dwSize =
sizeof(RGNDATAHEADER);
1362 pRgnData->rdh.iType = RDH_RECTANGLES;
1363 pRgnData->rdh.nRgnSize =
sizeof(RGNDATAHEADER) +
sizeof(RECT) * nCntRect;
1364 pRgnData->rdh.nCount = nCntRect;
1365 pRgnData->rdh.rcBound.top = 0;
1366 pRgnData->rdh.rcBound.left = 0;
1367 pRgnData->rdh.rcBound.bottom = bi.m_size.cy;
1368 pRgnData->rdh.rcBound.right = bi.m_size.cx;
1369 hRgn = ::ExtCreateRegion(NULL, pRgnData->rdh.nRgnSize, pRgnData);
1372 _GetLastError(
"ExtCreateRegion");
1386 bool Draw(HDC hdc,
int x = 0,
int y = 0)
const
1400 bool Draw(HDC hdc,
const POINT& po)
const
1402 return Draw(hdc, po.x, po.y);
1418 HBRUSH brush = ::CreatePatternBrush(m_bmp);
1419 bool r = !! ::FillRect(hdc, &rect, brush);
1420 _DeleteObject(brush);
1472 bool BitBlt(HDC hdc,
int x,
int y, DWORD raster = SRCCOPY)
const
1476 CTempBitmapDC dc(m_hWnd, m_bmp);
1477 return !!
::BitBlt(hdc, x, y, m_size.cx, m_size.cy, dc, 0, 0, raster);
1499 bool StretchBlt(HDC hdc,
int x,
int y, DWORD raster = SRCCOPY,
int cx = 0,
int cy = 0)
const
1503 m_CheckSize(cx, cy);
1504 CTempBitmapDC dc(m_hWnd, m_bmp);
1505 return !!
::StretchBlt(hdc, x, y, cx, cy, dc, 0, 0, m_size.cx, m_size.cy, raster);
1525 bool TransparentBit(HDC hdc,
int x,
int y, COLORREF color = CLR_AUTOSELECT,
int cx = 0,
int cy = 0)
const
1529 m_CheckSize(cx, cy);
1530 CTempBitmapDC dc(m_hWnd, m_bmp);
1531 color = m_CheckColor(dc, color);
1532 if ( ! IS_RGBVALUE(color) )
1534 return !!
::StretchBlt(hdc, x, y, cx, cy, dc, 0, 0, m_size.cx, m_size.cy, SRCCOPY);
1536 return !! ::TransparentBlt(hdc, x, y, cx, cy, dc, 0, 0, m_size.cx, m_size.cy, color);
1555 bool AlphaBlend(HDC hdc,
int x,
int y,
int parsent = 100,
int cx = 0,
int cy = 0)
const
1559 m_CheckSize(cx, cy);
1560 CTempBitmapDC dc(m_hWnd, m_bmp);
1561 BLENDFUNCTION blend;
1562 blend.BlendOp = AC_SRC_OVER;
1563 blend.BlendFlags = 0;
1566 blend.SourceConstantAlpha =
static_cast<BYTE
>(parsent * 255 / 100);
1567 blend.AlphaFormat = 0;
1571 blend.SourceConstantAlpha = 255;
1572 blend.AlphaFormat = AC_SRC_ALPHA;
1574 #if ! defined(_WIN32_WCE) || (_WIN32_WCE > 0x500)
1575 return !!
::AlphaBlend(hdc, x, y, cx, cy, dc, 0, 0, m_size.cx, m_size.cy, blend);
1600 if ( parsent >= 100 )
1604 else if ( color == CLR_INVALID )
1611 RECT rc = { x, y, x + m_size.cx, y + m_size.cy };
1615 if ( ! biBase.m_CheckDib() || ! biOver.m_CheckDib() )
1621 parsent = parsent * 255 / 100;
1623 loop ( py, biOver.m_size.cy )
1627 if ( py == 0 && color == CLR_AUTOSELECT )
1629 color = RGB(pOver->rgbRed, pOver->rgbGreen, pOver->rgbBlue);
1632 loop ( px, biOver.m_size.cx )
1634 if ( ! IS_RGBVALUE(color) || color != RGB(pOver->rgbRed, pOver->rgbGreen, pOver->rgbBlue) )
1639 d = pOver->rgbReserved;
1641 tmp = (pBase->rgbBlue * (255 - d)) + (pOver->rgbBlue * d);
1642 pBase->rgbBlue =
static_cast<BYTE
>((tmp > 255 * 255) ? 255 : (tmp / 255));
1643 tmp = (pBase->rgbGreen * (255 - d)) + (pOver->rgbGreen * d);
1644 pBase->rgbGreen =
static_cast<BYTE
>((tmp > 255 * 255) ? 255 : (tmp / 255));
1645 tmp = (pBase->rgbRed * (255 - d)) + (pOver->rgbRed * d);
1646 pBase->rgbRed =
static_cast<BYTE
>((tmp > 255 * 255) ? 255 : (tmp / 255));
1652 return biBase.
BitBlt(hdc, x, y);
1662 return m_pRgb != NULL;
1673 if ( m_pRgb == NULL )
1677 return m_pRgb != NULL;
1690 if ( m_pRgb != NULL )
1696 INT_PTR yy = (m_size.cy - 1) - y;
1697 return &m_pRgb[yy * m_size.cx];
1712 if ( m_pRgb != NULL )
1718 INT_PTR yy = (m_size.cy - 1) - y;
1719 return &m_pRgb[yy * m_size.cx];
1732 if ( m_pRgb == NULL )
1736 const SIZE& sz = m_size;
1738 bi.
Set(sz.cy, sz.cx);
1743 const RGBQUAD* p1 = &m_pRgb[y1 * sz.cx];
1764 if ( m_pRgb == NULL )
1768 const SIZE& sz = m_size;
1770 bi.
Set(sz.cx, sz.cy);
1774 INDEX y2 = isVertical ? (sz.cy - 1) - y1 : y1;
1775 const RGBQUAD* p1 = &m_pRgb[y1 * sz.cx];
1780 bi.m_pRgb[y2 * sz.cx + x1] = *p1++;
1787 bi.m_pRgb[y2 * sz.cx + x1] = *p1++;
1802 if ( m_pRgb == NULL )
1806 const SIZE& sz = m_size;
1808 bi.
Set(sz.cx, sz.cy);
1812 const RGBQUAD* p = &m_pRgb[y1 * sz.cx];
1816 BYTE g = p->rgbGreen;
1817 BYTE b = p->rgbBlue;
1818 int a = (r * 30 + g * 59 + b * 11) / 100;
1824 q.rgbRed =
static_cast<BYTE
>(a);
1825 q.rgbGreen =
static_cast<BYTE
>(a);
1826 q.rgbBlue =
static_cast<BYTE
>(a);
1827 bi.m_pRgb[y1 * sz.cx + x1] = q;
1842 return m_DilationErosion(
true);
1853 return m_DilationErosion(
false);
1864 if ( m_pRgb == NULL )
1870 br.
Set(sz.cx, sz.cy);
1881 if ( x == 0 || y == 0 ||
static_cast<int>(x) == sz.cx - 1 ||
static_cast<int>(y) == sz.cy - 1 )
1887 vb[0] = po1[x - 1].rgbBlue;
1888 vb[1] = po1[x].rgbBlue;
1889 vb[2] = po1[x + 1].rgbBlue;
1890 vb[3] = po[x - 1].rgbBlue;
1891 vb[4] = po[x].rgbBlue;
1892 vb[5] = po[x + 1].rgbBlue;
1893 vb[6] = po2[x - 1].rgbBlue;
1894 vb[7] = po2[x].rgbBlue;
1895 vb[8] = po2[x + 1].rgbBlue;
1896 ::qsort(vb, 9,
sizeof(BYTE), ms_DeSub);
1897 pr[x].rgbBlue = vb[5];
1899 vb[0] = po1[x - 1].rgbRed;
1900 vb[1] = po1[x].rgbRed;
1901 vb[2] = po1[x + 1].rgbRed;
1902 vb[3] = po[x - 1].rgbRed;
1903 vb[4] = po[x].rgbRed;
1904 vb[5] = po[x + 1].rgbRed;
1905 vb[6] = po2[x - 1].rgbRed;
1906 vb[7] = po2[x].rgbRed;
1907 vb[8] = po2[x + 1].rgbRed;
1908 ::qsort(vb, 9,
sizeof(BYTE), ms_DeSub);
1909 pr[x].rgbRed = vb[5];
1911 vb[0] = po1[x - 1].rgbGreen;
1912 vb[1] = po1[x].rgbGreen;
1913 vb[2] = po1[x + 1].rgbGreen;
1914 vb[3] = po[x - 1].rgbGreen;
1915 vb[4] = po[x].rgbGreen;
1916 vb[5] = po[x + 1].rgbGreen;
1917 vb[6] = po2[x - 1].rgbGreen;
1918 vb[7] = po2[x].rgbGreen;
1919 vb[8] = po2[x + 1].rgbGreen;
1920 ::qsort(vb, 9,
sizeof(BYTE), ms_DeSub);
1921 pr[x].rgbGreen = vb[5];
1942 if ( x < 0 || y < 0 || x >= m_size.cx || y >= m_size.cy )
1946 y = (m_size.cy - 1) - y;
1951 pi.rgbBase = m_pRgb[x + y * m_size.cx];
1952 pi.rgb.rgbBlue = GetBValue(c);
1953 pi.rgb.rgbRed = GetRValue(c);
1954 pi.rgb.rgbGreen = GetGValue(c);
1955 if ( ! pi.IsEqualBase(pi.rgb) )
1959 DWORD i = m_PaintSub(x, y, &pi);
1960 if ( i == DWORD_MAX )
break;
1976 DWORD
Save(LPCTSTR lpszFileName, WORD bitsPixel = 0)
1995 static HBITMAP _deprecated
Load(LPCTSTR lpszFileName,
int cx = 0,
int cy = 0, UINT fuLoad = LR_CREATEDIBSECTION)
2012 static HBITMAP _deprecated
Load(UINT uBitmapResourceId,
int cx = 0,
int cy = 0, UINT fuLoad = LR_CREATEDIBSECTION)
2027 if ( ::GetObject(hBitmap,
sizeof(BITMAP), &bm) > 0 )
2029 _size.cx = bm.bmWidth;
2030 _size.cy = bm.bmHeight;
2033 _GetLastError(
"GetObject");
2050 SIZE sz = { CalcScaleX(orgSize.cx), CalcScaleY(orgSize.cy) };
2051 if ( sz.cx != orgSize.cx || sz.cy != orgSize.cy )
2054 bi.
Set(sz.cx, sz.cy);
2055 bi.
Insert(0, 0, bmp, 13369376, sz.cx, sz.cy);
2071 int ly = srcSize.cy * dstSize.cx / srcSize.cx;
2072 if ( dstSize.cy >= ly )
2074 int d = (dstSize.cy - ly) / 2;
2075 ::SetRect(&_rect, 0, d, dstSize.cx, ly + d);
2078 int lx = srcSize.cx * dstSize.cy / srcSize.cy;
2079 int d = (dstSize.cx - lx) / 2;
2080 ::SetRect(&_rect, d, 0, lx + d, dstSize.cy);
2099 CWorkDC(HWND hWnd) : m_hWnd(hWnd), m_dc(::
GetDC(hWnd))
2101 ASSERT0( m_dc != NULL,
"GetDC",
"失敗しました。" );
2105 if ( !
::ReleaseDC(m_hWnd, m_dc) ) { ASSERT0(
false,
"ReleaseDC",
"失敗しました。" ); }
2107 operator HDC(
void) {
return m_dc; }
2115 CTempDC(HDC dc, HBITMAP bmp) : m_dc(::CreateCompatibleDC(dc)), m_bmp(::SelectObject(m_dc, bmp))
2117 ASSERT0( m_dc != NULL,
"CreateCompatibleDC",
"失敗しました。" );
2118 ASSERT0( m_bmp != NULL,
"SelectObject",
"失敗しました。" );
2122 if ( ::SelectObject(m_dc, m_bmp) == NULL ) { ASSERT0(
false,
"SelectObject",
"失敗しました。" ); }
2123 if ( ! ::DeleteDC(m_dc) ) { ASSERT0(
false,
"DeleteDC",
"失敗しました。" ); }
2125 operator HDC(
void) {
return m_dc; }
2133 CTempBitmapDC(HWND hWnd, HBITMAP bmp) : m_workDC(hWnd), m_tempDC(m_workDC, bmp) { }
2134 operator HDC(
void) {
return m_tempDC; }
2151 bool IsEqualBase(
const RGBQUAD& q)
const
2153 if ( rgbBase.rgbBlue != q.rgbBlue )
return false;
2154 if ( rgbBase.rgbRed != q.rgbRed )
return false;
2155 if ( rgbBase.rgbGreen != q.rgbGreen )
return false;
2165 bool IsEqualBase(DWORD x, DWORD y)
const
2167 return IsEqualBase(pRgb[x + y * size.cx]);
2172 enum { DEFAULT_STRETCHMODE = STRETCH_HALFTONE };
2174 enum { DEFAULT_STRETCHMODE = BILINEAR };
2178 static size_t ms_ChoiceMin(
size_t a,
size_t b)
2180 return (a < b) ? a : b;
2183 static void ms_SetBitmapInfoHeader(BITMAPINFOHEADER& _bi,
int cx,
int cy, WORD bit = 32)
2186 _bi.biSize =
sizeof(BITMAPINFOHEADER);
2190 _bi.biBitCount = bit;
2191 _bi.biCompression = BI_RGB;
2194 static HBITMAP ms_CreateBitmap(RGBQUAD*& _pRgb, HDC dc,
int cx,
int cy)
2197 if ( cx > 0 && cy > 0 )
2199 BITMAPINFOHEADER bm = { 0 };
2200 ms_SetBitmapInfoHeader(bm, cx, cy, 32);
2201 return ::CreateDIBSection(dc,
reinterpret_cast<BITMAPINFO*
>(&bm), DIB_RGB_COLORS,
reinterpret_cast<void **
>(&_pRgb), NULL, 0);
2206 static bool ms_CheckSize(SIZE& _size,
const RECT& rect)
2208 _size.cx = rect.right - rect.left;
2209 _size.cy = rect.bottom - rect.top;
2210 return (_size.cx > 0 && _size.cy > 0);
2212 static void ms_CheckSize(
int& _cx,
int& _cy,
const SIZE& s)
2214 if ( _cx <= 0 ) { _cx = s.cx; }
2215 if ( _cy <= 0 ) { _cy = s.cy; }
2217 void m_CheckSize(
int& _cx,
int& _cy)
const
2219 ms_CheckSize(_cx, _cy, m_size);
2222 void m_ReleaseDC(
void)
2224 if ( m_backDC != NULL )
2226 if ( ::SelectObject(m_backDC, m_backBmp) == NULL )
2228 ASSERT0(
false,
"SelectObject",
"失敗しました。" );
2230 if ( ! ::DeleteDC(m_backDC) )
2232 ASSERT0(
false,
"DeleteDC",
"失敗しました。" );
2238 COLORREF m_CheckColor(HDC hdc, COLORREF color)
const
2240 if ( color == CLR_AUTOSELECT )
2242 color = ::GetPixel(hdc, 0, m_size.cy - 1);
2264 static int ms_DeSub(
const void* a,
const void* b)
2266 return *(BYTE*)a - *(BYTE*)b;
2270 static inline BYTE ms_GG(
const RGBQUAD* p,
int cx,
int x)
2272 return (x < 0 || x >= cx) ?
static_cast<BYTE
>(0) : p[x].rgbGreen;
2276 static inline BYTE ms_max(
size_t len, BYTE* p)
2281 if ( r < p[i + 1] ) r = p[i + 1];
2287 static inline BYTE ms_min(
size_t len, BYTE* p)
2292 if ( r > p[i + 1] ) r = p[i + 1];
2302 CBitmapImage m_DilationErosion(
bool isDilation =
true)
const
2304 if ( m_pRgb == NULL )
2310 b2.
Set(sz.cx, sz.cy);
2314 RGBQUAD rgb = { 0 };
2322 const RGBQUAD* p2 = (
static_cast<int>(y) == sz.cy - 1) ? dp :
GetRgbDataPtr(y + 1);
2326 b[0] = ms_GG(p0, sz.cx, x - 1);
2327 b[1] = ms_GG(p0, sz.cx, x + 0);
2328 b[2] = ms_GG(p0, sz.cx, x + 1);
2329 b[3] = ms_GG(p1, sz.cx, x - 1);
2330 b[4] = ms_GG(p1, sz.cx, x + 0);
2331 b[5] = ms_GG(p1, sz.cx, x + 1);
2332 b[6] = ms_GG(p2, sz.cx, x - 1);
2333 b[7] = ms_GG(p2, sz.cx, x + 0);
2334 b[8] = ms_GG(p2, sz.cx, x + 1);
2335 BYTE r = isDilation ? ms_max(9, b) : ms_min(9, b);
2350 DWORD m_PaintSub(
int x,
int y, TPaintInfo* p)
2352 if ( ! p->IsEqualBase(x, y) )
2359 if ( p->size.cx <= x + i || ! p->IsEqualBase(x + i, y) )
2366 if ( 0 > x - j || ! p->IsEqualBase(x - j, y) )
2371 RGBQUAD* q = &(p->pRgb[y * p->size.cx]);
2372 loop ( xx , j + i - 1 )
2374 q[x - j + 1 + xx] = p->rgb;
2376 p->count += j + i - 1;
2381 if ( p->size.cy > y + 1 )
2385 if ( ! p->IsEqualBase(x + i, y + 1) )
2389 if ( p->IsEqualBase(x + i, y + 1) )
2397 if ( ! p->IsEqualBase(x + i, y + 1) )
2406 for ( i = 0; i < j; )
2408 if ( ! p->IsEqualBase(x + i, y - 1) )
2410 for ( ; i < j; i++ )
2412 if ( p->IsEqualBase(x + i, y - 1) )
2420 if ( ! p->IsEqualBase(x + i, y - 1) )
2428 for ( i = 0; i < j; i++ )
2430 if ( p->size.cy > y + 1 && p->IsEqualBase(x + i, y + 1) )
2434 return (x + i) + (y + 1) * 0x10000;
2440 DWORD i = m_PaintSub(xx, yy, p);
2441 if ( i == DWORD_MAX )
break;
2446 if ( 0 <= y - 1 && p->IsEqualBase(x + i, y - 1) )
2450 return (x + i) + (y - 1) * 0x10000;
2456 DWORD i = m_PaintSub(xx, yy, p);
2457 if ( i == DWORD_MAX )
break;
2467 bool m_CheckDib(
void)
2469 if ( !
IsEmpty() && m_pRgb == NULL )
2473 if ( bi.m_pRgb == NULL )
2476 if ( ::GetObject(bi.m_bmp,
sizeof(BITMAP), &bp) > 0 && bp.bmBitsPixel == 32 )
2478 bi.m_pRgb =
static_cast<RGBQUAD*
>(bp.bmBits);
2481 if ( bi.m_pRgb == NULL )
2483 bi.
Set(*
this, m_size.cx, m_size.cy);
2484 ASSERT( bi.m_pRgb != NULL );
2488 return (m_pRgb != NULL);
#define loop_dn(VAR, CNT)
loop構文.
#define loop(VAR, CNT)
loop構文.
bool GetSize(SIZE &_size) const
[取得] ビットマップサイズ取得.
DWORD Save(LPCTSTR lpszFileName, WORD bitsPixel=0)
[作成] BMPファイル作成.
bool Draw(HDC hdc, int x=0, int y=0) const
[処理] イメージ描画.
static HBITMAP Load(UINT uBitmapResourceId, int cx=0, int cy=0, UINT fuLoad=LR_CREATEDIBSECTION)
[読込] リソース読込み
static HBITMAP Create32bitDibSection(HBITMAP hbm, RGBQUAD *&_pRgb, BITMAPINFOHEADER *pHeader=NULL)
[作成] 32bitビットマップ作成.
size_t GetLineBytes(void) const
[取得] 一ラインBYTE数取得
RGBQUAD * Refer(void)
[取得] データ参照.
const RGBQUAD * Refer(void) const
[取得] データ参照.
bool IsValid(void) const
[確認] 有効確認.
const SIZE & GetSize(void) const
[取得] サイズ取得
const RGBQUAD * operator[](INDEX y) const
[取得] ラインデータ参照.
RGBQUAD * operator[](INDEX y)
[取得] ラインデータ参照.
CRawData(const SIZE &s)
コンストラクタ
bool DrawTile(HDC hdc, const RECT &rect) const
[処理] イメージタイル描画.
bool CustomizeAlpha(CBitmapHandle bmp)
[処理] アルファチャネル操作.
bool SetFromClient(HWND hWnd, const RECT &rect, COLORREF backColor=CLR_INVALID)
[設定] クライアントからイメージ設定.
CBitmapHandle Detach(void)
[設定] デタッチ.
bool Set(CBitmapHandle bmp)
[設定] イメージ設定.
DWORD Paint(int x, int y, COLORREF c)
[描画] ペイント.
bool IsEmpty(void) const
[確認] Empty状態確認.
bool ChangePixelColor(COLORREF r, COLORREF g, COLORREF b)
[処理] カラー変更.
CBitmapImage CreateReverseImage(bool isVertical, bool isHorizontal) const
[作成] 反転画像作成.
bool GradationFill(COLORREF color1, COLORREF color2, EDirection direction, const RECT *pRect=NULL)
[処理] グラデーション描画.
bool Fill(COLORREF color, const RECT &rect)
[処理] 四角描画.
bool InsertEx(int x, int y, HBITMAP hBitmap, UINT uExFlag=DSS_NORMAL)
[挿入] イメージ挿入.
bool Set(const CBitmapImage &bmpimg, int cx=0, int cy=0)
[設定] イメージ設定.
bool SetEx(HDC hDC, int cx, int cy, COLORREF color=CLR_INVALID)
[設定] 拡張イメージ設定.
bool CustomizeAlpha(BYTE alpha, COLORREF colorEx, BYTE alphaEx)
[処理] アルファチャネル操作.
CBitmapImage(CBitmapHandle bmp)
代入コンストラクタ
bool Insert(int x, int y, const CBitmapImage &bmpimg, DWORD raster=SRCCOPY, int cx=0, int cy=0)
[挿入] イメージ挿入.
RGBQUAD * GetRgbDataPtr(INT_PTR y=-1)
[取得] RGBデータアドレス取得.
bool BitBlt(HDC hdc, int x, int y, DWORD raster=SRCCOPY) const
[表示] イメージ描画.
HRGN CreateRgn(COLORREF transColor=CLR_AUTOSELECT) const
[作成] リージョン作成.
bool SetFromIcon(HICON hIcon, COLORREF backColor)
[作成] ICONからイメージ設定.
int ChangePixelColor(COLORREF targetColor, COLORREF drawColor)
[処理] カラー変更.
CBitmapImage & operator=(const CBitmapImage &other)
コピーオペレータ
bool Fill(COLORREF color)
[処理] 四角描画.
CBitmapImage CreateDilationBitmap(void) const
[作成] 膨張画像作成.
HDC GetDC(void)
[取得]デバイスコンテキストハンドル取得.
bool SetFromClient(HWND hWnd, COLORREF backColor=CLR_INVALID)
[設定] クライアントからイメージ設定.
bool Attach(CBitmapHandle bmp)
[設定] アタッチ.
static void CalcAdjustRect(RECT &_rect, const SIZE &dstSize, const SIZE &srcSize)
[計算] 表示位置調整.
bool InsertOnTransparent(int x, int y, const CBitmapImage &bmpimg, COLORREF color=CLR_AUTOSELECT, int cx=0, int cy=0)
[挿入] 透過処理付イメージ挿入.
CBitmapImage CreateGrayscaleBitmap(void) const
[作成] グレイスケール画像作成.
bool CustomizeAlpha(BYTE alpha)
[処理] アルファチャネル操作.
CBitmapImage Cut(const RECT &rect, int cx=0, int cy=0) const
[取得] イメージ取り出し.
bool SetFromWindow(HWND hWnd, COLORREF backColor=CLR_INVALID, LPARAM mode=PRF_CLIENT|PRF_ERASEBKGND|PRF_NONCLIENT|PRF_OWNED)
[設定] ウィンドウからイメージ設定.
bool _deprecated Set(const CRawData &rawData)
[設定] 生データからイメージ設定.
virtual ~CBitmapImage(void)
デストラクタ
const SIZE & GetSize(void) const
[取得] イメージサイズ取得.
static bool GetBitmapSize(SIZE &_size, HBITMAP hBitmap)
[取得] ビットマップサイズ取得.
const RGBQUAD * GetRgbDataPtr(INT_PTR y=-1) const
[取得] RGBデータアドレス取得.
void SetWorkWnd(HWND h)
[設定] ワークデバイスコンテキスト設定.
bool Set(int cx, int cy, COLORREF color=CLR_INVALID)
[設定] イメージ設定.
bool StretchBlt(HDC hdc, int x, int y, DWORD raster=SRCCOPY, int cx=0, int cy=0) const
[表示] イメージ描画.
bool GradationFill(COLORREF color1, COLORREF color2, bool boIsHorizontal, const RECT *pRect=NULL)
[処理] グラデーション描画.
bool SetFromDC(HDC hdc, const RECT &rect, int cx=0, int cy=0)
[設定] DCからイメージ設定.
CBitmapImage CreateRotateImage(void) const
[作成] 回転画像作成.
CBitmapImage(void)
コンストラクタ
HBITMAP CreateMaskBitmap(bool boIsReverse=false, COLORREF transColor=CLR_AUTOSELECT) const
[作成] マスクパターンビットマップ作成.
DWORD Save(LPCTSTR lpszFileName, WORD bitsPixel=0)
[作成] BMPファイル作成.
static HBITMAP _deprecated Load(UINT uBitmapResourceId, int cx=0, int cy=0, UINT fuLoad=LR_CREATEDIBSECTION)
[読込] リソース読込み
CBitmapImage CreateErosionBitmap(void) const
[作成] 収縮画像作成.
CBitmapHandle GetBitmapHandle(void)
[取得] ビットマップハンドル取得
bool ReleaseDC(void)
[設定] デバイスコンテキストハンドル返却.
bool ToHaveRgbData(void)
[設定] RGBデータ準備.
bool Draw(HDC hdc, int x=0, int y=0) const
[処理] イメージ描画.
CBitmapImage Clone(void) const
[複製] クローン作成
static HBITMAP _deprecated Load(LPCTSTR lpszFileName, int cx=0, int cy=0, UINT fuLoad=LR_CREATEDIBSECTION)
[読込] BMPファイル読込み.
bool GradientFill(const PTRIVERTEX pVertex, DWORD dwNumVertex, const PGRADIENT_RECT pMesh, DWORD dwNumMesh, bool boIsHorizontal)
[処理] グラデーション描画.
CBitmapImage(const CBitmapImage &other)
コピーコンストラクタ
CBitmapImage MedianFilter(void) const
[作成] メディアンフィルター画像作成.
void SetStretchBltMode(int nStretchMode)
[設定] ビットマップ伸縮モード設定.
bool TransparentBit(HDC hdc, int x, int y, COLORREF color=CLR_AUTOSELECT, int cx=0, int cy=0) const
[表示] 透過処理付イメージ描画.
bool SemitransparectBlt(HDC hdc, int x, int y, int parsent=100, COLORREF color=CLR_AUTOSELECT) const
[挿入] 半透明,透過イメージ描画.
bool InsertOnAlphaBlend(int x, int y, const CBitmapImage &bmpimg, int parsent=100, int cx=0, int cy=0)
[挿入] 半透過処理付イメージ挿入.
CRawData _deprecated CreateRawData(void) const
[作成] 生データ作成.
bool HasRgbData(void) const
[確認] RGBデータ有無.
bool GetBitmapInfo(BITMAPINFOHEADER &_head) const
[取得] BITMAPINFOHEADER 取得.
bool Draw(HDC hdc, const POINT &po) const
[処理] イメージ描画.
bool AlphaBlend(HDC hdc, int x, int y, int parsent=100, int cx=0, int cy=0) const
[描画] 半透明処理付イメージ描画.
static CBitmapHandle ChangeByDpi(CBitmapHandle bmp)
[作成] 画像縮小拡大
bool InsertOnSemitransparect(int x, int y, const CBitmapImage &bmpimg, int parsent=100, COLORREF color=CLR_AUTOSELECT)
[挿入] 半透明イメージ挿入(透過色付).
bool IsNull(void) const
[確認] NULLチェック
const TYP * Ref(void) const
[取得] ポインタ取得
void Zero(V &value)
[設定] ゼロクリア.
void MemCopy(T *_pDst, const void *pSrc, size_t len)
[複製] メモリコピー