You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.1 KiB
C++
128 lines
3.1 KiB
C++
#include "StdAfx.h"
|
|
#include ".\itemexportfile.h"
|
|
#include "SigmaDoc.h"
|
|
#include "SigmaView.h"
|
|
//#include "ExportSheet.h"
|
|
#include "DrawOperator\imageinsert.h"
|
|
|
|
CItemExportFile::CItemExportFile(CSigmaDoc * ppDoc)
|
|
: CItem(ppDoc)
|
|
{
|
|
}
|
|
|
|
CItemExportFile::~CItemExportFile(void)
|
|
{
|
|
}
|
|
|
|
CMemoryDC* CItemExportFile::ExportImage(CSize sz,UINT bpp)
|
|
{
|
|
if(sz.cx<=0 || sz.cy<=0) return NULL;
|
|
|
|
CMemoryDC *pImageDC = new CMemoryDC;
|
|
if(!pImageDC->Create(sz,bpp))
|
|
{
|
|
delete pImageDC;
|
|
// ::AfxMessageBox("Create Image error!");
|
|
return NULL;
|
|
}
|
|
CDC* pBakDC=GetDC()->GetDC();
|
|
CRect BakRT=GetDC()->GetViewRect();
|
|
|
|
pImageDC->Erase(RGB(255,255,255));
|
|
CRect rect(0,0,sz.cx,sz.cy);
|
|
GetDoc()->SetCDC(pImageDC);
|
|
GetDC()->SetViewRect(rect);
|
|
GetDoc()->OnDraw(*GetDC());
|
|
|
|
GetDoc()->SetCDC(pBakDC);
|
|
GetDC()->SetViewRect(BakRT);
|
|
return pImageDC;
|
|
}
|
|
|
|
|
|
BOOL CItemExportFile::ExportImage(LPCTSTR lpFileName, CSize sz, UINT bpp)
|
|
{
|
|
CMemoryDC *pImageDC=ExportImage(sz,bpp);
|
|
if(pImageDC==NULL)
|
|
return false;
|
|
bool bSuccess = true;
|
|
CImageInsert *pii=new CImageInsert;
|
|
CRect rect(0,0,sz.cx,sz.cy);
|
|
CRect8 rt=GetDC()->GetReal(rect);
|
|
pii->x0=rt.left;
|
|
pii->y0=rt.bottom;
|
|
pii->m_size=rt.GetSize();
|
|
pii->m_pImage=new CImageBase;
|
|
//设置图像分辨率
|
|
/*
|
|
if(GetPreferences().WorkaroundSave.m_nExportModeDPI == 1) //自定义分辨率
|
|
{
|
|
int dpi = (int)GetPreferences().WorkaroundSave.m_dExportDPI;
|
|
pii->m_pImage->SetXDPI(dpi);
|
|
pii->m_pImage->SetYDPI(dpi);
|
|
}
|
|
*/
|
|
pii->m_pImage->CreateFromHBITMAP((HBITMAP)*pImageDC);
|
|
|
|
if(!pii->SaveAs(lpFileName))
|
|
{
|
|
//::AfxMessageBox("Save image Error");
|
|
bSuccess = false;
|
|
}
|
|
|
|
delete pii;
|
|
delete pImageDC;
|
|
return bSuccess;
|
|
}
|
|
|
|
BOOL CItemExportFile::ExportWMF(LPCTSTR lpFileName, CSize sz)
|
|
{
|
|
CDC* pBakDC = GetDC()->GetDC();
|
|
CRect BakRT = GetDC()->GetViewRect();
|
|
|
|
CRect rect, rt;
|
|
rect.SetRect(0, 0, sz.cx, sz.cy);
|
|
|
|
//CFile::Remove(lpFileName);
|
|
DeleteFile(lpFileName);
|
|
|
|
CMetaFileDC wmf;
|
|
wmf.SetMapMode(MM_TEXT);
|
|
|
|
//由像素转换为0.01毫米单位
|
|
double HorzsizePerPixel = (double)(pBakDC->GetDeviceCaps(HORZSIZE)) / (double)pBakDC->GetDeviceCaps(HORZRES);//一个象素的宽度(单位:毫米/象素)
|
|
double VertsizePerPixel = (double)(pBakDC->GetDeviceCaps(VERTSIZE)) / (double)pBakDC->GetDeviceCaps(VERTRES);//一个光栅行(象素)的高度(单位:毫米/象素)
|
|
sz.cx = AfxGetPublicFunction()->FloatToLong(sz.cx*HorzsizePerPixel * 100); //单位为0.01毫米
|
|
sz.cy = AfxGetPublicFunction()->FloatToLong(sz.cy*VertsizePerPixel * 100); //单位为0.01毫米
|
|
//pDC->DPtoHIMETRIC(&sz);
|
|
rt.SetRect(0, 0, sz.cx, sz.cy);
|
|
|
|
if (!wmf.CreateEnhanced(pBakDC, lpFileName, rt, "Golden East\0\0")) return FALSE;
|
|
wmf.SetAttribDC(pBakDC->m_hAttribDC);
|
|
|
|
GetDoc()->SetCDC(&wmf);
|
|
GetDC()->SetViewRect(rect);
|
|
GetDoc()->OnDraw(*GetDC());
|
|
|
|
::DeleteEnhMetaFile(wmf.CloseEnhanced());
|
|
|
|
GetDoc()->SetCDC(pBakDC);
|
|
GetDC()->SetViewRect(BakRT);
|
|
return TRUE;
|
|
}
|
|
|
|
bool CItemExportFile::Export(LPCTSTR lpFileName, CSize sz, UINT bpp)
|
|
{
|
|
CString szFullPathDst, ext;
|
|
szFullPathDst.Format("%s", lpFileName);
|
|
ext = AfxGetPublicFunction()->GetSplitPath(szFullPathDst, "ext");
|
|
|
|
if (ext.Find(".WMF") >= 0 || ext.Find(".EMF") >= 0)
|
|
{
|
|
return ExportWMF(szFullPathDst, sz);
|
|
}
|
|
else
|
|
{
|
|
return ExportImage(szFullPathDst, sz, bpp);
|
|
}
|
|
} |