Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make "Save With Mark" run successfully #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions imagepy/ui/canvas/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ def update(self, counter = [0,0]):
else:
drawmark(dc, self.to_panel_coor, self.marks[i], k=self.scale)
dc.UnMask()

self.dc = dc

counter[1] += time()-start
if counter[0] == 10:
print('frame rate:',int(10/max(0.001,counter[1])))
Expand Down Expand Up @@ -233,6 +236,41 @@ def to_panel_coor(self, x, y):
y = y * self.scale + self.conbox[1]
return x, y

def save_buffer(self, path):
dcSource = self.dc
# based largely on code posted to wxpython-users by Andrea Gavana 2006-11-08
size = dcSource.Size

# Create a Bitmap that will later on hold the screenshot image
# Note that the Bitmap must have a size big enough to hold the screenshot
# -1 means using the current default colour depth
bmp = wx.Bitmap(size.width, size.height)

# Create a memory DC that will be used for actually taking the screenshot
memDC = wx.MemoryDC()

# Tell the memory DC to use our Bitmap
# all drawing action on the memory DC will go to the Bitmap now
memDC.SelectObject(bmp)

# Blit (in this case copy) the actual screen on the memory DC
# and thus the Bitmap
memDC.Blit( 0, # Copy to this X coordinate
0, # Copy to this Y coordinate
size.width, # Copy this width
size.height, # Copy this height
dcSource, # From where do we copy?
0, # What's the X offset in the original DC?
0 # What's the Y offset in the original DC?
)

# Select the Bitmap out of the memory DC by selecting a new
# uninitialized Bitmap
memDC.SelectObject(wx.NullBitmap)

img = bmp.ConvertToImage()
img.SaveFile(path, wx.BITMAP_TYPE_PNG)

def __del__(self):
self.img = self.back = None
print('========== canvas del')
Expand Down