def test_get_wx_image_type(self): """ Correct wx.BITMAP_TYPE is returned """ self.assertEqual(BITMAP_TYPE_PNG, get_wx_image_type("/blah.png")) self.assertEqual(BITMAP_TYPE_TIF, get_wx_image_type("blah.TifF")) self.assertEqual(BITMAP_TYPE_JPEG, get_wx_image_type("/blah.JPG")) self.assertEqual(BITMAP_TYPE_JPEG, get_wx_image_type("/blah.jpeg"))
def export(self, filename): """ Exports the current view as a file. Select the appropriate wx constant depending on the filetype. gif is buggered for some reason :-/ """ const = get_wx_image_type(filename) self.gui.canvas.deselect_shape() context = wx.MemoryDC(self.gui.canvas.buffer) memory = wx.MemoryDC() x, y = self.gui.canvas.buffer.GetSize() bitmap = wx.EmptyBitmap(x, y, -1) memory.SelectObject(bitmap) memory.Blit(0, 0, x, y, context, 0, 0) memory.SelectObject(wx.NullBitmap) bitmap.SaveFile(filename, const) # write to disk
def save_bitmap_data(self, _zip): """ Will save all Image tools to disk as temporary files, and then removes them. This function is lengthy because it will not save two idential images twice. """ logger.debug("Writing bitmap files to zip") data = {} # list of bitmap data, check if image has been pasted to_remove = [] for canvas in self.gui.get_canvases(): for shape in canvas.shapes: if isinstance(shape, tools.Image): img = shape.image.ConvertToImage() img_data = img.GetData() for key, value in data.items(): if value == img_data: if not shape.filename: shape.filename = key break # the above iteration didn't find any common pastes if not shape.filename: tmp_name = make_filename() + u".png" img.SaveFile(tmp_name, wx.BITMAP_TYPE_PNG) img = wx.Image(tmp_name) name = make_filename() + u".jpg" img.SaveFile(name, wx.BITMAP_TYPE_JPEG) shape.filename = name data[shape.filename] = img_data _zip.write(name, os.path.join(u"data", name)) to_remove.append(name) to_remove.append(tmp_name) else: name = shape.filename if not name in to_remove: data[name] = img_data img.SaveFile(name, get_wx_image_type(name)) _zip.write(name, os.path.join("data", name)) [os.remove(x) for x in to_remove]