Skip to content

Commit 52b3b46

Browse files
committed
Add Winforms screenshots.
1 parent 2628e56 commit 52b3b46

25 files changed

+24
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
coverage.xml
1010
dist
1111
build
12+
logs
1213
_build
1314
distribute-*
1415
docs/env
943 Bytes
Loading
10 KB
Loading
1.52 KB
Loading
6.85 KB
Loading
1.18 KB
Loading
946 Bytes
Loading
7.05 KB
Loading
Loading
1.01 KB
Loading
Loading
467 Bytes
Loading
509 Bytes
Loading
Loading
805 Bytes
Loading
511 Bytes
Loading
Loading
698 Bytes
Loading
5.34 KB
Loading
Loading
1.27 KB
Loading
22.9 KB
Loading
2.42 KB
Loading

winforms/src/toga_winforms/images.py

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def get_width(self):
3333
def get_height(self):
3434
return self.native.Height
3535

36+
def get_data(self):
37+
stream = MemoryStream()
38+
self.native.Save(stream, ImageFormat.Png)
39+
return stream.ToArray()
40+
3641
def save(self, path):
3742
path = Path(path)
3843
try:

winforms/src/toga_winforms/window.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import System.Windows.Forms as WinForms
2-
from System.Drawing import Point, Size
2+
from System.Drawing import Bitmap, Graphics, Point, Size
3+
from System.Drawing.Imaging import ImageFormat
4+
from System.IO import MemoryStream
35

46
from toga.command import GROUP_BREAK, SECTION_BREAK
57

@@ -179,3 +181,18 @@ def resize_content(self):
179181
self.native.ClientSize.Width,
180182
self.native.ClientSize.Height - vertical_shift,
181183
)
184+
185+
def get_image_data(self):
186+
size = Size(self.native_content.Size.Width, self.native_content.Size.Height)
187+
bitmap = Bitmap(size.Width, size.Height)
188+
graphics = Graphics.FromImage(bitmap)
189+
190+
graphics.CopyFromScreen(
191+
self.native_content.PointToScreen(Point.Empty),
192+
Point(0, 0),
193+
size,
194+
)
195+
196+
stream = MemoryStream()
197+
bitmap.Save(stream, ImageFormat.Png)
198+
return stream.ToArray()

0 commit comments

Comments
 (0)