Fixed ImageTk getimage

This commit is contained in:
Andrew Murray 2019-04-29 23:43:13 +10:00
parent 6d5b8926be
commit d9a3878937
3 changed files with 29 additions and 21 deletions

View File

@ -61,9 +61,8 @@ class TestImageTk(PillowTestCase):
self.assertEqual(im_tk.width(), im.width) self.assertEqual(im_tk.width(), im.width)
self.assertEqual(im_tk.height(), im.height) self.assertEqual(im_tk.height(), im.height)
# _tkinter.TclError: this function is not yet supported reloaded = ImageTk.getimage(im_tk)
# reloaded = ImageTk.getimage(im_tk) self.assert_image_equal(reloaded, im.convert("RGBA"))
# self.assert_image_equal(reloaded, im)
def test_photoimage_blank(self): def test_photoimage_blank(self):
# test a image using mode/size: # test a image using mode/size:

View File

@ -275,10 +275,13 @@ class BitmapImage(object):
def getimage(photo): def getimage(photo):
""" This function is unimplemented """
"""Copies the contents of a PhotoImage to a PIL image memory.""" """Copies the contents of a PhotoImage to a PIL image memory."""
photo.tk.call("PyImagingPhotoGet", photo) im = Image.new("RGBA", (photo.width(), photo.height()))
block = im.im
photo.tk.call("PyImagingPhotoGet", photo, block.id)
return im
def _show(image, title): def _show(image, title):

View File

@ -149,17 +149,18 @@ PyImagingPhotoPut(ClientData clientdata, Tcl_Interp* interp,
return TCL_OK; return TCL_OK;
} }
/* Warning -- this does not work at all */
static int static int
PyImagingPhotoGet(ClientData clientdata, Tcl_Interp* interp, PyImagingPhotoGet(ClientData clientdata, Tcl_Interp* interp,
int argc, const char **argv) int argc, const char **argv)
{ {
Imaging im;
Tk_PhotoHandle photo; Tk_PhotoHandle photo;
Tk_PhotoImageBlock block; Tk_PhotoImageBlock block;
int x, y, z;
if (argc != 2) { if (argc != 3) {
TCL_APPEND_RESULT(interp, "usage: ", argv[0], TCL_APPEND_RESULT(interp, "usage: ", argv[0],
" srcPhoto", (char *) NULL); " srcPhoto destImage", (char *) NULL);
return TCL_ERROR; return TCL_ERROR;
} }
@ -172,21 +173,26 @@ PyImagingPhotoGet(ClientData clientdata, Tcl_Interp* interp,
return TCL_ERROR; return TCL_ERROR;
} }
/* get PIL Image handle */
im = ImagingFind(argv[2]);
if (!im) {
TCL_APPEND_RESULT(interp, "bad name", (char*) NULL);
return TCL_ERROR;
}
TK_PHOTO_GET_IMAGE(photo, &block); TK_PHOTO_GET_IMAGE(photo, &block);
printf("pixelPtr = %p\n", block.pixelPtr); for (y = 0; y < block.height; y++) {
printf("width = %d\n", block.width); UINT8* out = (UINT8*)im->image32[y];
printf("height = %d\n", block.height); for (x = 0; x < block.pitch; x += block.pixelSize) {
printf("pitch = %d\n", block.pitch); for (z=0; z < block.pixelSize; z++) {
printf("pixelSize = %d\n", block.pixelSize); int offset = block.offset[z];
printf("offset = %d %d %d %d\n", block.offset[0], block.offset[1], out[x + offset] = block.pixelPtr[y * block.pitch + x + offset];
block.offset[2], block.offset[3]); }
}
}
TCL_APPEND_RESULT( return TCL_OK;
interp, "this function is not yet supported", (char *) NULL
);
return TCL_ERROR;
} }