Please enable JavaScript to view this site.

KOL/MCK - User Guide

Image in Memory - TBitmap

 

It is natural to continue the discussion of graphics with objects for representing images in RAM. The first and one of the most important of these is the TBitmap object type. It is intended for loading raster images from files (files with the .bmp extension), resources or other sources, for storing them in memory and modification, for drawing (on the canvas) and for saving - to files, streams. In the Windows environment, bitmaps (i.e., images that are stored in memory point by point, pixel by pixel, without any compression) play an important role due to their high processing speed. There are many API functions on Windows that are specifically designed to work with such images. The KOL library organizes a convenient object interface to these functions, enriching it with its extensions.

 

Bitmap object of type TBitmap is created by constructors

NewBitmap(W, H) - creates a "device-dependent" bitmap (DDB - Device Dependent Bitmap) of width W and height H pixels;

NewDIBBitmap(W, H, PixelFormat) - creates a "device independent" image (DIB - Device Independent Bitmap), specifying the pixel format (i.e., color depth, one of the values ​​in the list: pf1bit, pf4bit, pf8bit, pf15bit, pf16bit , pf24bit, pf32bit). The pixel format affects how many different colors can be represented in an image and how much memory you have to allocate to store the image.

 

For pf1bit, pf4bit and pf8bit formats, images with a "palette" are created, i.e. a pixel value of 1, 4, or 8 bits is actually a corresponding bit number representing the color index of a point in the image's palette. The peculiarity of KOL when working with such images is that the palette is not assigned by default, and if you just create such an image and draw something on its canvas, then you will not see anything but a black square (I hope Malevich did not use KOL to become famous?). In order for the palette to appear in the image, you must either assign it with your own code (DIBPalEntries property), or load the original image from some source, for example, from a file or from a resource.

 

With other formats, the situation is simpler: the pixel no longer stores the index in the palette, but the packed color R, G, B in a certain way (in this case, unlike the structure of the TColor variable, the B channel is stored in the low-order bits of the pixel, and R in the high-order ones) ... An object of type TBitmap has properties that allow you to directly access pixels in memory and modify them at will (ScanLine), this is the fastest possible way to modify images.

 

In any case, immediately after the image is created, it is a black rectangle of width W and height H pixels (since memory for the image is initialized with zeros). To fill the entire image with the desired color, it is convenient to use the canvas, and having assigned the desired brush color (Brush.Color: = clGreen, for example), call the canvas method FillRect.

 

KOL / MCK User Guide - Created by Carl Peeraer - Diamant Soft, based on the work of Vladimir Kladov - Artwerp.be

  

Keyboard Navigation

F7 for caret browsing
Hold ALT and press letter

This Info: ALT+q
Nav Header: ALT+n
Page Header: ALT+h
Topic Header: ALT+t
Topic Body: ALT+b
Exit Menu/Up: ESC