forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveImage.pyx
More file actions
92 lines (79 loc) · 2.52 KB
/
SaveImage.pyx
File metadata and controls
92 lines (79 loc) · 2.52 KB
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
#
# Browser.SaveImage()
#
cpdef py_bool SaveImage(self, py_string filePath,
str imageType="bitmap"):
assert IsThread(TID_UI), (
"Browser.SaveImage(): this method should only be called "
"on the UI thread")
cdef tuple size = self.GetSize(PET_VIEW)
cdef int width, height
if size:
(width, height) = size
else:
return False
# The charFilePath pointer is tied to the lifetime
# of the filePath string. strlen() is a C function.
cdef char* charFilePath = filePath
cdef int filePathLength = strlen(charFilePath)
cdef wchar_t* widecharFilePath = <wchar_t*>calloc(
filePathLength, wchar_t_size)
CharToWidechar(charFilePath, widecharFilePath, filePathLength)
cdef void* bits
cdef BITMAPINFOHEADER bitmapInfoHeader
bitmapInfoHeader.biSize = sizeof(BITMAPINFOHEADER)
bitmapInfoHeader.biWidth = width
bitmapInfoHeader.biHeight = -height # minus means top-down bitmap
bitmapInfoHeader.biPlanes = 1
bitmapInfoHeader.biBitCount = 32
bitmapInfoHeader.biCompression = BI_RGB # no compression
bitmapInfoHeader.biSizeImage = 0
bitmapInfoHeader.biXPelsPerMeter = 1
bitmapInfoHeader.biYPelsPerMeter = 1
bitmapInfoHeader.biClrUsed = 0
bitmapInfoHeader.biClrImportant = 0
cdef BITMAPINFO* bitmapInfo
bitmapInfo = <BITMAPINFO*>calloc(1, sizeof(BITMAPINFO))
bitmapInfo.bmiHeader = bitmapInfoHeader
cdef HDC screen_dc = GetDC(NULL)
cdef HBITMAP bitmap = CreateDIBSection(
screen_dc, bitmapInfo, DIB_RGB_COLORS, &bits, NULL, 0)
ReleaseDC(NULL, screen_dc)
cdef PaintBuffer
if bitmap:
# cefclient_win.cpp > UIT_RunGetImageTest
# TODO...
free(widecharFilePath)
free(bitmapInfo)
return True
#
# windows.pxd:
#
ctypedef struct BITMAPINFOHEADER:
DWORD biSize
LONG biWidth
LONG biHeight
WORD biPlanes
WORD biBitCount
DWORD biCompression
DWORD biSizeImage
LONG biXPelsPerMeter
LONG biYPelsPerMeter
DWORD biClrUsed
DWORD biClrImportant
ctypedef struct RGBQUAD:
pass
ctypedef struct BITMAPINFO:
BITMAPINFOHEADER bmiHeader
RGBQUAD bmiColors[1]
cdef DWORD BI_RGB
cdef HDC GetDC(HWND hWnd)
cdef HBITMAP CreateDIBSection(
HDC hdc,
BITMAPINFO *pbmi,
UINT iUsage,
void **ppvBits,
HANDLE hSection,
DWORD dwOffset)
cdef UINT DIB_RGB_COLORS
cdef int ReleaseDC(HWND hWnd,HDC hDC)