[Helma-user] convert image to grayscale

Jonathan Puckey me at jonathanpuckey.com
Wed Nov 1 14:36:59 CET 2006


I needed a function that would convert an image to grayscale, after  
trying 6 different functions this one seems to be the fastest:

function convertToGrayscale(img){
	var img = img.getBufferedImage();
	var w=img.getWidth();
	var h=img.getHeight();
	var type = java.awt.image.BufferedImage.TYPE_BYTE_GRAY;
	var grayImage = new java.awt.image.BufferedImage(w, h, type);
	var g = grayImage.createGraphics();
	g.drawRenderedImage(img, null);
	g.dispose();
	return new Image(grayImage);
}

So I thought I would share..

grts-
Jonathan


More information about the Helma-user mailing list