Mega Code Archive

 
Categories / Delphi / Examples
 

How to move a 2d-array to a image

In article <3pto5f$sgt@nic.tip.net>, christer.strandh@micro.se (Christer Strandh) wrote: > I want to move a 2D-array with picture graylevels to a Image or BMP > object without first save the array to disk!?? > I want to display the image faster on the canvas than I do now by > using canvas.pixels(... its slow! > > Christer Strandh... A solution (not necessarily the best but it works) is as follows: 1. Create a Bitmap (TBitMap) within the TImage. Bitmap := TBitmap.Create; BitMap.Width:=NCol; BitMap.Height:=NRow; ... 2. Create logical palette (grayscale or whatever) and assign it to BitMap.Palette. CreatePalette(MyLogPalette); ... etc. 3. Now draw pixels into the BitMap canvas NOT the image canvas (which is slow...). Use the number of colours in your logical palette to scale the intensity values. 4. Clean up. Free logical palette etc. DeleteObject(Image.Picture.Bitmap.ReleasePalette);