prøv så den her :
unit JBitmap;
interface
uses windows;
type
TJColor = record
blue,green,red,unused : byte;
end;
TPixels = array[0..0] of TJColor;
PPixels = ^TPixels;
TJBitMap = class
private
handle : THandle;
fpixels : PPixels;
fheight, fwidth : integer;
JmpTbl : array [ 0..10000 ] of integer;
function GetPixel(x, y: integer): TJColor;
procedure SetPixel(x, y: integer; const Value: TJColor);
public
DC : hDC;
Scanlines : array [ 0..10000] of pointer;
Constructor Create (width, height : integer );
procedure Draw ( DestDC : hDC; x,y : integer);
procedure StretchDraw ( DestDC : hDC; x1,y1,x2,y2 : integer);
property pixels [ x,y : integer ] : TJColor read GetPixel write SetPixel;
property width:integer read fwidth;
property height:integer read fheight;
end;
implementation
{ TJBitMap }
constructor TJBitMap.Create (width, height : integer );
var
bmInfo : TBitmapInfo;
bmheader : TBitmapInfoHeader;
p : pointer;
x : integer;
begin
inherited create;
fWidth := width;
fHeight := height;
with bmHeader do
begin
biSize := SizeOf(bmHeader);
biWidth := Width;
biHeight := Height;
biPlanes := 1;
biBitCount := 32;
biCompression := BI_RGB;
end;
bmInfo.bmiHeader := bmHeader;
Handle := CreateDIBSection(0, bmInfo, DIB_RGB_COLORS, p, 0, 0);
fPixels := p;
DC:=CreateCompatibleDC(0);
SelectObject(DC,Handle);
for x := 0 to height-1 do
JmpTbl [ x ] := x*width;
for x := 0 to height-1 do
scanlines [x] := @fPixels[x * width];
end;
procedure TJBitMap.Draw(DestDC: hDC; x, y: integer);
begin
BitBlt( DestDC,x,y,fWidth,fHeight,DC,0,0,SRCCOPY);
end;
function TJBitMap.GetPixel(x, y: integer): TJColor;
begin
result := fpixels [ y * fwidth + x ];
end;
procedure TJBitMap.SetPixel(x, y: integer; const Value: TJColor);
begin
fpixels [ JmpTbl[y] + x ] := Value;
end;
procedure TJBitMap.StretchDraw(DestDC: hDC; x1, y1, x2, y2: integer);
begin
StretchBlt( DestDC,x1,y1,x2-x1+1,y2-y1+1,DC,0,0,fwidth,fheight,SRCCOPY);
end;
end.
Jens B