Example n.5 - Pixels Handling
Previous  Top  Next

In this example we'll show how drawing shapes on the current image.

// transforming image to monochrome format
nBits:=ImgGetBitsPixel(_CurrentImage);
if nBits>1 then ImgThreshold(_CurrentImage,127);


//extracting width and height
width:=ImgGetWidth(_CurrentImage);
height:=ImgGetHeight(_CurrentImage);
//value for black color
color:=ImgGetBlackValue(_CurrentImage);

// printing a black border around current image
for x:=0 to width-1 do
   begin
      ImgSetPixel(_CurrentImage,x,0,color);
         ImgSetPixel(_CurrentImage,x,height-1,color);
    end;
for y:=0 to height-1 do
   begin
      ImgSetPixel(_CurrentImage,0,y,color);
      ImgSetPixel(_CurrentImage,width-1,y,color);
   end;

ApplicationLog(_CurrentAgent,'Drawing');

The first thing we want to note is that passing _CurrentImage to ImgThreshold we modify the current image, so in output we'll find black and white image. The second step is to require size (ImgGetWidth, ImgGetHeight) and color (ImgBlackValue) information. About the last function, it retrieves the code (either ' 0 ' or ' 1 ') used for representing black color in the current image.
In the final step, implemented with two for cycles, we draw a black rectangle of 1 pixel on the border of the current image; for this purpose we use ImgSetPixel , that (passing image handle, point coordinates and color code) colors a specific pixel.