1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
// ExportPage.cpp : implementation file
//
#include "stdafx.h"
#include "ReaderVC.h"
#include "ExportPage.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "ReaderVCView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExportPage dialog
CExportPage::CExportPage(CWnd* pParent /*=NULL*/)
: CDialog(CExportPage::IDD, pParent)
{
//{{AFX_DATA_INIT(CExportPage)
m_nHeight = 0;
m_nPageHeight = 0;
m_nRotate = 0;
m_nWidth = 0;
m_nPageWidth = 0;
//}}AFX_DATA_INIT
m_bitmap = NULL;
}
void CExportPage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExportPage)
DDX_Text(pDX, IDC_EDIT_HEIGHT, m_nHeight);
DDX_Text(pDX, IDC_EDIT_PAGE_HEIGHT, m_nPageHeight);
DDX_Text(pDX, IDC_EDIT_ROTATE, m_nRotate);
DDX_Text(pDX, IDC_EDIT_WIDTH, m_nWidth);
DDX_Text(pDX, IDC_EDIT_PAGE_WIDTH, m_nPageWidth);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExportPage, CDialog)
//{{AFX_MSG_MAP(CExportPage)
ON_BN_CLICKED(IDC_Rander_Page, OnRanderPage)
ON_BN_CLICKED(IDC_Save, OnSave)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExportPage message handlers
void CExportPage::OnRanderPage()
{
if (m_pView)
{
UpdateData(TRUE);
m_page=m_pView->GetPage();
if (!m_page) return;
if (m_nRotate==1 || m_nRotate==3)
{
int temp;
temp=m_nHeight;
m_nHeight=m_nWidth;
m_nWidth=temp;
}
m_bitmap=FPDFBitmap_Create(m_nWidth,m_nHeight,FPDFBitmap_BGRx);
FPDFBitmap_FillRect(m_bitmap,0,0,m_nWidth,m_nHeight,0xff,0xff,0xff,0xff);
FPDF_RenderPageBitmap(m_bitmap,m_page,0,0,200,200,m_nRotate,FPDF_ANNOT);
Invalidate();
if (m_nRotate==1 || m_nRotate==3)
{
int temp;
temp=m_nHeight;
m_nHeight=m_nWidth;
m_nWidth=temp;
}
//FPDFBitmap_Destroy(bitmap);
UpdateData(FALSE);
}
}
void CExportPage::InitDialogInfo(CReaderVCView *pView)
{
m_pView=pView;
if (pView) m_page=pView->GetPage();
SetDlgInfo();
}
void CExportPage::SetDlgInfo()
{
if (!m_page) return;
double height,width;
width=FPDF_GetPageWidth(m_page);
height=FPDF_GetPageHeight(m_page);
UpdateData(TRUE);
m_nPageHeight = (int)height;
m_nPageWidth = (int)width;
m_nWidth=(int)width/3;
m_nHeight=(int)height/3;
UpdateData(FALSE);
}
void CExportPage::OnSave()
{
CFileDialog SavDlg(FALSE,"","",OFN_FILEMUSTEXIST |OFN_HIDEREADONLY,"bmp(*.bmp)|*.bmp||All Files(*.*)|*.*");
if (SavDlg.DoModal()==IDOK)
{
CString strFileName = SavDlg.GetPathName();
BITMAPFILEHEADER bitmapFileHeader;
BITMAPINFOHEADER bitmapInfoHeader;
BITMAP strBitmap;
int wBitCount = 32;
winbmp.GetBitmap(&strBitmap);
DWORD dwBmBitsSize = ((strBitmap.bmWidth * wBitCount+31)/32) * 4 * strBitmap.bmHeight;
bitmapFileHeader.bfType = 0x4D42;
bitmapFileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwBmBitsSize;
bitmapFileHeader.bfReserved1 = bitmapFileHeader.bfReserved2 = 0;
bitmapFileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapInfoHeader.biWidth = strBitmap.bmWidth;
bitmapInfoHeader.biHeight = strBitmap.bmHeight;
bitmapInfoHeader.biPlanes = 1;
bitmapInfoHeader.biBitCount = wBitCount;
bitmapInfoHeader.biClrImportant = BI_RGB;
bitmapInfoHeader.biSizeImage = 0; //strBitmap.bmWidth * strBitmap.bmHeight;
bitmapInfoHeader.biXPelsPerMeter = 0;
bitmapInfoHeader.biYPelsPerMeter = 0;
bitmapInfoHeader.biClrUsed = 0;
bitmapInfoHeader.biCompression = 0;
char* context = new char[dwBmBitsSize];
CWindowDC dc(NULL);
GetDIBits(dc.GetSafeHdc(), (HBITMAP)winbmp.m_hObject, 0, bitmapInfoHeader.biHeight, (LPVOID)context,(BITMAPINFO*)&bitmapInfoHeader, DIB_RGB_COLORS);
CFile file;
file.Open(strFileName, CFile::modeCreate|CFile::modeWrite);
file.Write(&bitmapFileHeader, sizeof(BITMAPFILEHEADER));
file.Write(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER));
file.Write(context, dwBmBitsSize);
file.Close();
delete context;
}
}
void CExportPage::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
if(m_bitmap)
{
// CDC* pDc=GetDC();
int bufsize=FPDFBitmap_GetStride(m_bitmap)*m_nHeight;
void* bmpbuf=FPDFBitmap_GetBuffer(m_bitmap);
CDC MemDC;
CDC *pDc = GetDlgItem(IDC_STATIC_BITMAP)->GetDC(); //ID: picture
CRect rect;
((CWnd *)GetDlgItem(IDC_STATIC_BITMAP))->GetWindowRect(rect);
MemDC.CreateCompatibleDC(pDc);
if((HBITMAP)winbmp != NULL)
winbmp.DeleteObject();
if(HBITMAP(winbmp) == NULL)
{
winbmp.CreateCompatibleBitmap(pDc,m_nWidth,m_nHeight);
winbmp.SetBitmapBits(bufsize,bmpbuf);
}
MemDC.SelectObject(&winbmp);
pDc->BitBlt(0 , 0 , rect.Width(), rect.Height(), &MemDC,0,0,SRCCOPY);
//pDc->StretchBlt(0,0,rect.right-rect.left,rect.bottom-rect.top,&MemDC,0,0,m_nWidth,m_nHeight,SRCCOPY);
MemDC.DeleteDC();
}
// Do not call CDialog::OnPaint() for painting messages
}
|