Copy Pillow Gif to windows Clipboard
我已经使用枕头从一些图像中创建了一个 gif,我正在尝试将这个存储为 BytesIO 对象的 gif 复制到剪贴板,以作为 gif 图像保存到演示文稿中。下面的代码;其中 imageList = [] 是图像文件名列表。
任何从 python 复制 gif 到剪贴板的方法都会有帮助吗?!谢谢
1 2 3 4 5 6 7 8 9 10 11 | def copyGif(self): imageList = [] gif = BytesIO() imageList[0].save(gif, format='GIF', save_all=True, append_images=imageList[1:], optimize=False, duration=1000, loop=0) win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(win32clipboard.CF_DIB, gif.getvalue()) win32clipboard.CloseClipboard() |
试试看:
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 | import sys from PyQt5.Qt import * class MainWindow(QMainWindow): def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.setGeometry(50, 50, 600, 600) # Create a URL. url1 = QUrl.fromLocalFile('Loader.gif') url2 = QUrl.fromLocalFile('animated-dancing-image-0028.gif') # Create MIME data with URL. mime_data = QMimeData() mime_data.setUrls([url1, url2]) self.labelList = [ i for i in range(len([url1, url2]))] # Copy the MIME data to the clipboard. clipboard = QApplication.clipboard() clipboard.setMimeData(mime_data) cm = clipboard.mimeData() for i, m in enumerate(cm.urls()): self.labelList[i] = QMovie(m.toLocalFile()) self.labelList[i].frameChanged.connect(self.repaint) self.labelList[i].start() def paintEvent(self, event): currentFrame1 = self.labelList[0].currentPixmap() currentFrame2 = self.labelList[1].currentPixmap() frameRect2 = currentFrame2.rect() frameRect2.moveCenter(self.rect().center()) if frameRect2.intersects(event.rect()): painter = QPainter(self) painter.drawPixmap(frameRect2.left(), frameRect2.top(), currentFrame2) frameRect1 = currentFrame1.rect() frameRect1.moveCenter(self.rect().center()) if frameRect1.intersects(event.rect()): painter.drawPixmap(frameRect1.left(), frameRect1.top(), currentFrame1) if __name__ == '__main__': app = QApplication(sys.argv) ex = MainWindow() ex.show() QTimer.singleShot(10000, app.quit) sys.exit(app.exec_()) |