Problem: drawing an image pixel by pixel

I have a slow device which measures points levels which I have to display in the picture during “scan”. Because the scan process is slow I have to add pixel to the image when the point captured.
I tried to it like so:

ImageProcessor ip = imp.getProcessor(); // ByteProcessor (8-but gray-scale)

int height = imp.getHeight();
for (int i = 0; i < imp.getWidth(); i++) {
	byte lightness = (byte) 255; 
	for (int j = 0; j < height; j++) {
		if (j>10) break;
		lightness--;
		if (lightness < 0) lightness = 0;										
		ip.putPixelValue(i, j, lightness);												
	}	
	imp.updateAndDraw();	
	IJ.wait(10);
}			

imp.updateAndDraw();

I suggested it should draw a pixel and update the image but instead it waits and draws all the image at once.

Hello Dmitriy -

Here is a translation of the code you posted into a complete,
runnable jython (python) script:

import time
from ij import IJ

imp = IJ.createImage ('ramp', '8bit ramp', 256, 256, 1)
imp.show()

ip = imp.getProcessor()  # ByteProcessor (8-but gray-scale)

height = imp.getHeight()
for  i in range (imp.getWidth()):
	lightness = 255
	for  j in range (height):
		if (j>10): break
		lightness -= 1
		if (lightness < 0): lightness = 0
		ip.putPixelValue (i, j, lightness)
	imp.updateAndDraw()
	# IJ.wait(10)
	time.sleep (0.01)

imp.updateAndDraw()

It works for me as I would expect.

Note, as written, the script draws the image column by column,
rather than pixel by pixel. If you want to draw it pixel by pixel,
you would have to move the imp.updateAndDraw() into the
for j loop (from where it is now inside the for i loop, but
outside the for j loop).

Thanks, mm