Title: | Simple Image Viewer for R Using the 'tcltk' Package |
---|---|
Description: | A 'Tcl/Tk' Graphical User Interface (GUI) to display images than can be zoomed and panned using the mouse and keyboard shortcuts. 'tkImgR' read and write different image formats (PPM/PGM, PNG and GIF) using the standard 'Tcl/Tk' distribution (>=8.6), but other formats (JPEG, TIFF, CR2) can be handled using the 'tkImg' package for 'Tcl/Tk'. |
Authors: | Filipe Campelo [aut, cre]
|
Maintainer: | Filipe Campelo <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.5 |
Built: | 2025-02-09 02:43:52 UTC |
Source: | https://github.com/cran/tkImgR |
Functions to zoom and pan the canvas, and add the bind to the canvas.
canvasAddBinds(W) canvasControlButton4(W) canvasControlDown(W) canvasControlUp(W) canvasSpace(W, ...) canvasSpaceRelease(W) canvasMotion(W, ...) canvasLeft(W) canvasRight(W) canvasUp(W) canvasDown(W) canvasControlRight(W) canvasMouseWheel(W, ...) canvasControlLeft(W) canvasControlMouseWheel(W, ...) canvasPlus(W, ...) canvasMinus(W, ...) canvasShiftButton4(W, ...) canvasShiftButton5(W, ...) canvasShiftMouseWheel(W, ...)
canvasAddBinds(W) canvasControlButton4(W) canvasControlDown(W) canvasControlUp(W) canvasSpace(W, ...) canvasSpaceRelease(W) canvasMotion(W, ...) canvasLeft(W) canvasRight(W) canvasUp(W) canvasDown(W) canvasControlRight(W) canvasMouseWheel(W, ...) canvasControlLeft(W) canvasControlMouseWheel(W, ...) canvasPlus(W, ...) canvasMinus(W, ...) canvasShiftButton4(W, ...) canvasShiftButton5(W, ...) canvasShiftMouseWheel(W, ...)
W |
tktoplevel object with the canvas displaying the image |
... |
further arguments. |
These functions define the keyboard and mouse controls for the toplevel window.
No return value, called for side effects
## Not run: file_path <- system.file("img", "example.png", package = "tkImgR") tt <- tkImShow(file_path) Sys.sleep(0.25) canvasLeft(tt) Sys.sleep(0.25) canvasControlLeft(tt) Sys.sleep(0.25) canvasRight(tt) Sys.sleep(0.25) tcltk::tkdestroy(tt) ## End(Not run)
## Not run: file_path <- system.file("img", "example.png", package = "tkImgR") tt <- tkImShow(file_path) Sys.sleep(0.25) canvasLeft(tt) Sys.sleep(0.25) canvasControlLeft(tt) Sys.sleep(0.25) canvasRight(tt) Sys.sleep(0.25) tcltk::tkdestroy(tt) ## End(Not run)
These commands create, read, copy, write, and delete images using the 'tcltk' package.
tkimageRead(imageName = NULL, fileName, ...) tkimageCreate(imageName = NULL, ...) tkimageCopy(imageName, sourceImage, ...) tkimageWrite(imageName, fileName, ...) tkimageDelete(imageName)
tkimageRead(imageName = NULL, fileName, ...) tkimageCreate(imageName = NULL, ...) tkimageCopy(imageName, sourceImage, ...) tkimageWrite(imageName, fileName, ...) tkimageDelete(imageName)
imageName |
Specifies the name for the image; if is NULL then Tk picks a name of the form image#, where # is an integer. |
fileName |
The path for the image file. |
... |
Further arguments. |
sourceImage |
The name (or the tcl object) of the image to be copied. |
tclObj with the image if the function is tkimageCreate
, tkimageRead
, and tkimageCopy
or no value for tkimageWrite
or tkimageDelete
#tkimageRead file_path <- system.file("img", "example.png", package = "tkImgR") im01 <- tkimageRead("tkImage01", file_path) "tkImage01" %in% as.character(tcltk::.Tcl("image names")) tkimageDelete(im01) #tkimageCreate file_path <- system.file("img", "example.png", package = "tkImgR") im1 <- tkimageCreate("tkImage01") tkimage.height(im1) #0 im1 <- tkimageCreate("tkImage01", file_path) tkimage.height(im1) #2824 "tkImage01" %in% as.character(tcltk::.Tcl("image names")) tkimageDelete(im1) #tkimageCopy file_path <- system.file("img", "example.png", package = "tkImgR") im1 <- tkimageCreate("tkImage01", file_path) im3 <- tkimageCreate("tkImage03") tkimageCopy(im3, "tkImage01") c("tkImage01","tkImage03") %in% as.character(tcltk::.Tcl("image names")) tkimageDelete(im1) tkimageDelete(im3) #tkimageWrite file_path <- system.file("img", "example.png", package = "tkImgR") im1 <- tkimageCreate("tkImage01", file_path) file_path_crop_image <- file.path(tempdir(check = TRUE), "crop.png") #if is possible to write the file if (file.access(file_path_crop_image)==0){ tkimageWrite(im1, file_path_crop_image, from=c(0,1500)) im1_crop <- tkimageRead("tkImage01_crop", file_path_crop_image) print(tkimage.height(im1)) #2824 print(tkimage.height(im1_crop)) #1324 = 2824 - 1500 tkimageDelete(im1_crop) } #tkimageDelete file_path <- system.file("img", "example.png", package = "tkImgR") im1 <- tkimageCreate("tkImage01", file_path) "tkImage01" %in% as.character(tcltk::.Tcl("image names")) tkimageDelete(im1) "tkImage01" %in% as.character(tcltk::.Tcl("image names"))
#tkimageRead file_path <- system.file("img", "example.png", package = "tkImgR") im01 <- tkimageRead("tkImage01", file_path) "tkImage01" %in% as.character(tcltk::.Tcl("image names")) tkimageDelete(im01) #tkimageCreate file_path <- system.file("img", "example.png", package = "tkImgR") im1 <- tkimageCreate("tkImage01") tkimage.height(im1) #0 im1 <- tkimageCreate("tkImage01", file_path) tkimage.height(im1) #2824 "tkImage01" %in% as.character(tcltk::.Tcl("image names")) tkimageDelete(im1) #tkimageCopy file_path <- system.file("img", "example.png", package = "tkImgR") im1 <- tkimageCreate("tkImage01", file_path) im3 <- tkimageCreate("tkImage03") tkimageCopy(im3, "tkImage01") c("tkImage01","tkImage03") %in% as.character(tcltk::.Tcl("image names")) tkimageDelete(im1) tkimageDelete(im3) #tkimageWrite file_path <- system.file("img", "example.png", package = "tkImgR") im1 <- tkimageCreate("tkImage01", file_path) file_path_crop_image <- file.path(tempdir(check = TRUE), "crop.png") #if is possible to write the file if (file.access(file_path_crop_image)==0){ tkimageWrite(im1, file_path_crop_image, from=c(0,1500)) im1_crop <- tkimageRead("tkImage01_crop", file_path_crop_image) print(tkimage.height(im1)) #2824 print(tkimage.height(im1_crop)) #1324 = 2824 - 1500 tkimageDelete(im1_crop) } #tkimageDelete file_path <- system.file("img", "example.png", package = "tkImgR") im1 <- tkimageCreate("tkImage01", file_path) "tkImage01" %in% as.character(tcltk::.Tcl("image names")) tkimageDelete(im1) "tkImage01" %in% as.character(tcltk::.Tcl("image names"))
Open and display an image in a canvas that can be zoomed and panned using the mouse and keyboard shortcuts
tkImShow(file, zoom = NULL, title = NULL)
tkImShow(file, zoom = NULL, title = NULL)
file |
path to image file |
zoom |
the zoom factor (ratio), for zoom = 1 the image is shown with no zoom (original size), when zoom is < (>) than 1 the image is zoomed out (in). The default value of zoom is NULL. |
title |
the window title |
The tkwin
object returned by tkImShow
is a toplevel window with a canvas that contains several variables (canvasAllowZoom, canvasScrollWidth) and tkwin
objects (canvas, canvasScrollHorizontal, canvasScrollVertical) placed in the env
, which could be used to implement further methods.
file_path <- system.file("img", "example.png", package = "tkImgR") tt <- tkImShow(file_path) if (!identical(tcltk::tclRequire("Img", warn = FALSE),FALSE)){ file_path1 <- system.file("img", "example.jpg", package = "tkImgR") tt <- tkImShow(file_path1) }
file_path <- system.file("img", "example.png", package = "tkImgR") tt <- tkImShow(file_path) if (!identical(tcltk::tclRequire("Img", warn = FALSE),FALSE)){ file_path1 <- system.file("img", "example.jpg", package = "tkImgR") tt <- tkImShow(file_path1) }