在MFC中图片的读入并显示问题

在MFC中图片的读入并显示问题,第1张

void CTest_bmp2View::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//to locate and select the wanted bitmap file
CString strPath,strTitle;
strtitle="位图文件(bmp)|bmp|所有文件()|";
CFileDialog dlg(TRUE,NULL,NULL,NULL,strTitle,this);
if(!dlgDoModal()==IDOK)return;
strPath=dlgGetPathName();
//to relate the bitmap file to a bitmap varity
CBitmap bitmap;
HBITMAP hBitmap=(HBITMAP)LoadImage(NULL,strPath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
bitmapAttach(hBitmap);
//to set the enviroment for display
CClientDC pDC=new CClientDC(this);
CDC memDC;
memDCCreateCompatibleDC(pDC);
memDCSelectObject(&bitmap);
//to display
BITMAP bitInfo;
bitmapGetObject(sizeof(bitInfo),&bitInfo);
pDC->BitBlt(0,0,bitInfobmWidth,bitInfobmHeight,&memDC,0,0,SRCCOPY);
CView::OnLButtonDblClk(nFlags, point);
}

Lr曝光控制和中间调还原比PS效率高得多,特别对于暗部还原,PS *** 作显得很繁复,“曝光调整层”虽对伽马反差有不错的效果,但对于暗部修复就无能为力,这或是adobe有意的产品划分。再结合Lr的批处理流程,修正曝光的功效显得格外突出。我建议专业人士和高级玩家,先在Lr处理基准曝光然后再导入Ps进入细化处理。量化曝光流程交由lr去干。如果您已这样做;相当明智。

最简单的有个 CBitmapButton 类
或者这样,源码:
((CButton)GetDlgItem(IDC_BUTTON2))->SetIcon(::LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON1)));

((CButton)GetDlgItem(IDC_BUTTON1))->SetBitmap((HBITMAP)::LoadImage(AfxGetApp()->m_hInstance, "J:\\xxbmp",IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTCOLOR));

CFileDialog opendlg (TRUE,_T(""),_T(""),OFN_OVERWRITEPROMPT, _T("位图文件(bmp;)|bmp||"),NULL);   
if (opendlgDoModal()==IDOK)
{
filename=opendlgGetPathName();  
HBITMAP hHandle=(HBITMAP)::LoadImage(NULL,filename,IMAGE_BITMAP,480,360,LR_LOADFROMFILE);
HBITMAP oldb = m_PictureSetBitmap(hHandle);
DeleteObject(oldb);
}

给你个函数吧,用法:
CBitmap bmp;
bmpLoadBitmap(IDB_BITMAP1);
HRGN rgn;
rgn = BitmapToRegion((HBITMAP)bmp, RGB(127, 127, 127));
SetWindowRgn(rgn, TRUE);
bmpDeleteObject();
以下是函数
原型:
static HRGN BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance = RGB(0,0,0));
定义:
// BitmapToRegion : create a region from the "non-transparent" pixels of a bitmap
// hBmp : source bitmap
// cTransparentColor : color base for the "transparent" pixels (default is black)
// cTolerance : color tolerance for the "transparent" pixels
// a pixel is assumed to be transparent if the value of each of its 3 components (blue, green and red) is
// greater or equal to the corresponding value in cTransparentColor and is lower or equal to the
// corresponding value in cTransparentColor + cTolerance
HRGN CYourDlg::BitmapToRegion(HBITMAP hBmp, COLORREF cTransparentColor, COLORREF cTolerance)
{
HRGN hRgn = NULL;
if (hBmp)
{
// Create a memory DC inside which we will scan the bitmap content
HDC hMemDC = CreateCompatibleDC(NULL);
if (hMemDC)
{
// Get bitmap size
BITMAP bm;
GetObject(hBmp, sizeof(bm), &bm);
// Create a 32 bits depth bitmap and select it into the memory DC
BITMAPINFOHEADER RGB32BITSBITMAPINFO = {
sizeof(BITMAPINFOHEADER), // biSize
bmbmWidth, // biWidth;
bmbmHeight, // biHeight;
1, // biPlanes;
32, // biBitCount
BI_RGB, // biCompression;
0, // biSizeImage;
0, // biXPelsPerMeter;
0, // biYPelsPerMeter;
0, // biClrUsed;
0 // biClrImportant;
};
VOID pbits32;
HBITMAP hbm32 = CreateDIBSection(hMemDC,
(BITMAPINFO )&RGB32BITSBITMAPINFO, DIB_RGB_COLORS, &pbits32, NULL, 0);
if (hbm32)
{
HBITMAP holdBmp = (HBITMAP)SelectObject(hMemDC, hbm32);
// Create a DC just to copy the bitmap into the memory DC
HDC hDC = CreateCompatibleDC(hMemDC);
if (hDC)
{
// Get how many bytes per row we have for the bitmap bits (rounded up to 32 bits)
BITMAP bm32;
GetObject(hbm32, sizeof(bm32), &bm32);
while (bm32bmWidthBytes % 4)
bm32bmWidthBytes++;
// Copy the bitmap into the memory DC
HBITMAP holdBmp = (HBITMAP)SelectObject(hDC, hBmp);
BitBlt(hMemDC, 0, 0, bmbmWidth, bmbmHeight, hDC, 0, 0, SRCCOPY);
// For better performances, we will use the ExtCreateRegion() function to create the
// region This function take a RGNDATA structure on entry We will add rectangles by
// amount of ALLOC_UNIT number in this structure
#define ALLOC_UNIT 100
DWORD maxRects = ALLOC_UNIT;
HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + (sizeof(RECT) maxRects));
RGNDATA pData = (RGNDATA )GlobalLock(hData);
pData->rdhdwSize = sizeof(RGNDATAHEADER);
pData->rdhiType = RDH_RECTANGLES;
pData->rdhnCount = pData->rdhnRgnSize = 0;
SetRect(&pData->rdhrcBound, MAXLONG, MAXLONG, 0, 0);
// Keep on hand highest and lowest values for the "transparent" pixels
BYTE lr = GetRValue(cTransparentColor);
BYTE lg = GetGValue(cTransparentColor);
BYTE lb = GetBValue(cTransparentColor);
BYTE hr = min(0xff, lr + GetRValue(cTolerance));
BYTE hg = min(0xff, lg + GetGValue(cTolerance));
BYTE hb = min(0xff, lb + GetBValue(cTolerance));
// Scan each bitmap row from bottom to top (the bitmap is inverted vertically)
BYTE p32 = (BYTE )bm32bmBits + (bm32bmHeight - 1) bm32bmWidthBytes;
for (int y = 0; y < bmbmHeight; y++)
{
// Scan each bitmap pixel from left to right
for (int x = 0; x < bmbmWidth; x++)
{
// Search for a continuous range of "non transparent pixels"
int x0 = x;
LONG p = (LONG )p32 + x;
while (x < bmbmWidth)
{
BYTE b = GetRValue(p);
if (b >= lr && b <= hr)
{
b = GetGValue(p);
if (b >= lg && b <= hg)
{
b = GetBValue(p);
if (b >= lb && b <= hb)
// This pixel is "transparent"
break;
}
}
p++;
x++;
}
if (x > x0)
{
// Add the pixels (x0, y) to (x, y+1) as a new rectangle in the region
if (pData->rdhnCount >= maxRects)
{
GlobalUnlock(hData);
maxRects += ALLOC_UNIT;
hData = GlobalReAlloc(hData, sizeof(RGNDATAHEADER) + (sizeof(RECT) maxRects), GMEM_MOVEABLE);
pData = (RGNDATA )GlobalLock(hData);
}
RECT pr = (RECT )&pData->Buffer;
SetRect(&pr[pData->rdhnCount], x0, y, x, y+1);
if (x0 < pData->rdhrcBoundleft)
pData->rdhrcBoundleft = x0;
if (y < pData->rdhrcBoundtop)
pData->rdhrcBoundtop = y;
if (x > pData->rdhrcBoundright)
pData->rdhrcBoundright = x;
if (y+1 > pData->rdhrcBoundbottom)
pData->rdhrcBoundbottom = y+1;
pData->rdhnCount++;
// On Windows98, ExtCreateRegion() may fail if the number of rectangles is too
// large (ie: > 4000) Therefore, we have to create the region by multiple steps
if (pData->rdhnCount == 2000)
{
HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) maxRects), pData);
if (hRgn)
{
CombineRgn(hRgn, hRgn, h, RGN_OR);
DeleteObject(h);
}
else
hRgn = h;
pData->rdhnCount = 0;
SetRect(&pData->rdhrcBound, MAXLONG, MAXLONG, 0, 0);
}
}
}
// Go to next row (remember, the bitmap is inverted vertically)
p32 -= bm32bmWidthBytes;
}
// Create or extend the region with the remaining rectangles
HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) maxRects), pData);
if (hRgn)
{
CombineRgn(hRgn, hRgn, h, RGN_OR);
DeleteObject(h);
}
else
hRgn = h;
// Clean up
GlobalFree(hData);
SelectObject(hDC, holdBmp);
DeleteDC(hDC);
}
DeleteObject(SelectObject(hMemDC, holdBmp));
}
DeleteDC(hMemDC);
}
}
return hRgn;
}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12979137.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-29
下一篇 2023-05-29

发表评论

登录后才能评论

评论列表(0条)

保存