Image Viewing & Manupilation

showImage(Image image {, int width, int height } )

showImage() displays an image in a window. When width and height are specified and the image size is larger than that, a scroll bar appears within the frame.

e.g.
im = Toolkit::getDefaultToolkit().getImage("test.jpg")
showImage(im)
readImage(InputStream input { , String mimeType } ) or
(URL url { , String mimeType } ) or
(String path { , String mimeType } )

readImage() reads an image from file, URL, or InputStream.

e.g.
im = readImage("test.png")
showImage(im)

This function depends on JIMI package.

writeImage(Image image, String path ) or
(Image image, File file ) or
(Image image, String mimeType, OutputStream output )

writeImage() writes the specified image to a file or an OutputStream.

e.g.
im = readImage("test.png")
writeImage(im, "test.bmp")

This function depends on JIMI package.

makeImage(int width, int height, PnutsFunction drawFunc {, int imageType })

A Image object of the size width x height is created and the function drawFunc is called to draw something.

drawFunc(Graphics graphics)

imageType can be one of the constants: BufferedImage::TYPE_XXX_YYY.

e.g.
import("java.awt.Color")
im = makeImage(100, 100, function (g){
        g.setColor(Color::white)
        g.fillRect(0, 0, 100, 100)
        g.setColor(Color::blue)
        g.fillOval(0, 0, 100, 100)
     })
showImage(im)

Back