| 1 | unit MethodBitmapRawImageData;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | Classes, SysUtils, DrawMethod, FastBitmap, Graphics, GraphType;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | { TMethodBitmapRawImageData }
|
|---|
| 10 |
|
|---|
| 11 | TMethodBitmapRawImageData = class(TDrawMethodImage)
|
|---|
| 12 | constructor Create; override;
|
|---|
| 13 | procedure DrawFrame(FastBitmap: TFastBitmap); override;
|
|---|
| 14 | end;
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | implementation
|
|---|
| 18 |
|
|---|
| 19 | { TMethodBitmapRawImageData }
|
|---|
| 20 |
|
|---|
| 21 | constructor TMethodBitmapRawImageData.Create;
|
|---|
| 22 | begin
|
|---|
| 23 | inherited;
|
|---|
| 24 | Caption := 'TBitmap.RawImage.Data';
|
|---|
| 25 | Description.Add('Custom TFastBitmap data are converted to visible image bitmap raw data. ' +
|
|---|
| 26 | 'Then TImage is responsible for show loaded data.');
|
|---|
| 27 | end;
|
|---|
| 28 |
|
|---|
| 29 | procedure TMethodBitmapRawImageData.DrawFrame(FastBitmap: TFastBitmap);
|
|---|
| 30 | var
|
|---|
| 31 | Y, X: Integer;
|
|---|
| 32 | PixelPtr: PCardinal;
|
|---|
| 33 | RowPtr: PCardinal;
|
|---|
| 34 | P: TPixelFormat;
|
|---|
| 35 | RawImage: TRawImage;
|
|---|
| 36 | BytePerPixel: Integer;
|
|---|
| 37 | BytePerRow: Integer;
|
|---|
| 38 | begin
|
|---|
| 39 | P := Image.Picture.Bitmap.PixelFormat;
|
|---|
| 40 | with FastBitmap do
|
|---|
| 41 | try
|
|---|
| 42 | Image.Picture.Bitmap.BeginUpdate(False);
|
|---|
| 43 | RawImage := Image.Picture.Bitmap.RawImage;
|
|---|
| 44 | RowPtr := PCardinal(RawImage.Data);
|
|---|
| 45 | BytePerPixel := RawImage.Description.BitsPerPixel div 8;
|
|---|
| 46 | BytePerRow := RawImage.Description.BytesPerLine;
|
|---|
| 47 | for Y := 0 to Size.Y - 1 do begin
|
|---|
| 48 | PixelPtr := RowPtr;
|
|---|
| 49 | for X := 0 to Size.X - 1 do begin
|
|---|
| 50 | PixelPtr^ := Pixels[X, Y];
|
|---|
| 51 | Inc(PByte(PixelPtr), BytePerPixel);
|
|---|
| 52 | end;
|
|---|
| 53 | Inc(PByte(RowPtr), BytePerRow);
|
|---|
| 54 | end;
|
|---|
| 55 | finally
|
|---|
| 56 | Image.Picture.Bitmap.EndUpdate(False);
|
|---|
| 57 | end;
|
|---|
| 58 | end;
|
|---|
| 59 |
|
|---|
| 60 | end.
|
|---|
| 61 |
|
|---|