用了CImage类,Load进图片并Save,但时得到的图片的分辨率是96,怎么能改到300?
打算做一个排版的软件,保存Jpg有问题,代码如下:
CString strFilter;
CString strFileName;
CString strExection;
COLORREF color = RGB(255, 255, 255);
CBrush brush;
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
LeftView* pLeftView = (LeftView*)pFrame->GetSplitterLeftWnd()->GetPane(0, 0);
CImage tmpImage;
if(!brush.CreateSolidBrush(color))
return;
CRect rect;
rect.left = 0;
rect.top = 0;
rect.bottom = 4430;
rect.right = 2010;
if(pLeftView->m_pImageNameList->GetSize() < 1)
{
if(!tmpImage.IsNull())
tmpImage.Destroy();
return;
}
CDC* pImageCDC = CDC::FromHandle(m_image.GetDC());
//pImageCDC->SetViewportExt(2010*300/96, 4430*300/96);
HDC hDC = pImageCDC->m_hDC;
//pImageCDC->SetMapMode(MM_ANISOTROPIC);
pImageCDC->FillRect(&rect, &brush);
CString strTemp;
LeftBottomView* pView = (LeftBottomView*)pFrame->GetSplitterLeftWnd()- >GetPane(1, 0);
TCHAR* str = new TCHAR(20);
int lenth = pView->m_pMyEdit->GetWindowText(str, 20);
int index = 0;
POSITION pos;
pos = pLeftView->m_pImageNameList->GetHeadPosition();
while(index < pLeftView->m_pImageNameList->GetSize())
{
tmpImage.Load(pLeftView->m_pImageNameList->GetAt(pos).c_str());
for(int i = 0; i < 8; i++){
tmpImage.Draw(hDC, 40+(i%2)*(30+PHOTO_WIDTH_V) + index%2* 1000, 100+i/2*(45+PHOTO_HEIGHT_V)+ index/2 * 1430/*, PHOTO_WIDTH_V, PHOTO_HEIGHT_V*/);
MyDrawText(pImageCDC, 40+(i%2)*(30+PHOTO_WIDTH_V)+90+index%2* 1000, 100+i/2*(45+PHOTO_HEIGHT_V)+PHOTO_HEIGHT_V+index/2 * 1430, str);
}
pLeftView->m_pImageNameList->GetNext(pos);
index++;
}
CFileDialog dlg(FALSE, NULL, NULL, OFN_OVERWRITEPROMPT | OFN_EXPLORER, "File(*.jpg)|*.jpg||");
dlg.DoModal(); strExection= ".jpg";
strFileName = dlg.m_ofn.lpstrFile;
strFileName = strFileName + strExection; if(strFileName == ".jpg")
return;
m_image.Save(strFileName);
打算做一个排版的软件,保存Jpg有问题,代码如下:
CString strFilter;
CString strFileName;
CString strExection;
COLORREF color = RGB(255, 255, 255);
CBrush brush;
CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
LeftView* pLeftView = (LeftView*)pFrame->GetSplitterLeftWnd()->GetPane(0, 0);
CImage tmpImage;
if(!brush.CreateSolidBrush(color))
return;
CRect rect;
rect.left = 0;
rect.top = 0;
rect.bottom = 4430;
rect.right = 2010;
if(pLeftView->m_pImageNameList->GetSize() < 1)
{
if(!tmpImage.IsNull())
tmpImage.Destroy();
return;
}
CDC* pImageCDC = CDC::FromHandle(m_image.GetDC());
//pImageCDC->SetViewportExt(2010*300/96, 4430*300/96);
HDC hDC = pImageCDC->m_hDC;
//pImageCDC->SetMapMode(MM_ANISOTROPIC);
pImageCDC->FillRect(&rect, &brush);
CString strTemp;
LeftBottomView* pView = (LeftBottomView*)pFrame->GetSplitterLeftWnd()- >GetPane(1, 0);
TCHAR* str = new TCHAR(20);
int lenth = pView->m_pMyEdit->GetWindowText(str, 20);
int index = 0;
POSITION pos;
pos = pLeftView->m_pImageNameList->GetHeadPosition();
while(index < pLeftView->m_pImageNameList->GetSize())
{
tmpImage.Load(pLeftView->m_pImageNameList->GetAt(pos).c_str());
for(int i = 0; i < 8; i++){
tmpImage.Draw(hDC, 40+(i%2)*(30+PHOTO_WIDTH_V) + index%2* 1000, 100+i/2*(45+PHOTO_HEIGHT_V)+ index/2 * 1430/*, PHOTO_WIDTH_V, PHOTO_HEIGHT_V*/);
MyDrawText(pImageCDC, 40+(i%2)*(30+PHOTO_WIDTH_V)+90+index%2* 1000, 100+i/2*(45+PHOTO_HEIGHT_V)+PHOTO_HEIGHT_V+index/2 * 1430, str);
}
pLeftView->m_pImageNameList->GetNext(pos);
index++;
}
CFileDialog dlg(FALSE, NULL, NULL, OFN_OVERWRITEPROMPT | OFN_EXPLORER, "File(*.jpg)|*.jpg||");
dlg.DoModal(); strExection= ".jpg";
strFileName = dlg.m_ofn.lpstrFile;
strFileName = strFileName + strExection; if(strFileName == ".jpg")
return;
m_image.Save(strFileName);
你为什么用m_image.Save(strFileName)呢。
改为
tmpImage .Save(strFileName)试试吧。
试过的,也是不行,好像一和CDC绑定或是一载入图片就会使分辨率降低