为什么我的图片显示不出来,,,?GDI+配置没问题
下面是代码,,,,
Graphics graphics(dc.GetSafeHdc());
Image img(L"C:\\Users\\john\\Desktop\\图片\\2.jpg");
graphics.DrawImage(&img,100,50,img.GetWidth(),img.GetHeight());
下面是代码,,,,
Graphics graphics(dc.GetSafeHdc());
Image img(L"C:\\Users\\john\\Desktop\\图片\\2.jpg");
graphics.DrawImage(&img,100,50,img.GetWidth(),img.GetHeight());
不要用中文路径,改成英文路径试试,也不要把图片文件放到桌面上应该是你的路径不对造成的
调试看一下img是否有值,img的长宽各是多少!
GetCurrentDirectory(256,path);
CString filepath = path;
filepath += "\\res\\2.JPG";
image.Load(filepath);
HBITMAP hBitmap=image.Detach();
CBitmap bmp;
bmp.Attach(hBitmap); CMainFrame* pframe = (CMainFrame*)AfxGetApp()->m_pMainWnd;
CImgTestView* pview = (CImgTestView*)pframe->GetActiveView();
CDC* pdc = pview->GetDC();
CDC memdc;
memdc.CreateCompatibleDC(pdc);
memdc.SelectObject(&bmp);
pdc->BitBlt(0,0,3000,3000,&memdc,0,0,SRCCOPY);
memdc.DeleteDC();
bmp.DeleteObject();
有可能是这个问题也有可能代码没写对地方。断ondraw里是要的。
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);2.你的dc是啥?
CPaintDC dc(this);
还是GetDC?
对话框要用CPaintDC ,View就用GetDC3.
Image img(L"C:\\Users\\john\\Desktop\\图片\\2.jpg"); 断点看看img是否有内容