When using the TBitmap shell for a GDI bitmap from a Graphics device, I noticed that when setting up a bitmap with SetSize (w, h), it will always clear the bitmap (using the PatBlt call). When I copy in bits later (see Procedure below), it seems that ScanLine is the fastest feature, not SetDIBits.
function ToBitmap: TBitmap; var i, N, x: Integer; S, D: PAnsiChar; begin Result := TBitmap.Create(); Result.PixelFormat := pf32bit; Result.SetSize( width, height ); S := Src; D := Result.ScanLine[ 0 ]; x := Integer( Result.ScanLine[ 1 ] ) - Integer( D ); N := width * sizeof( longword ); for i := 0 to height - 1 do begin Move( S^, D^, N ); Inc( S, N ); Inc( D, x ); end; end;
The bitmaps I need to work with are quite large (150 MB of RGB memory). With these iomages, it takes 150 ms to simply create an empty raster map and another 140 ms to overwrite its contents.
Is there a way to initialize a TBitmap with the correct size WITHOUT initializing the pixels themselves and leaving the memory of uninitialized pixels (for example, dirty)? Or is there another way to do this. I know that we could work on the pixels in place, but that still leaves 150 ms of inexplicable pixel initialization.
source share