| 1 | unit UMethodBitmapRawImageDataPaintBox;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | {$IFDEF windows}Windows,{$ENDIF}Classes, SysUtils, Controls, UDrawMethod, UFastBitmap, Graphics, LCLType,
|
|---|
| 9 | FPimage, IntfGraphics, GraphType;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 12 | { TMethodBitmapRawImageDataPaintBox }
|
|---|
| 13 |
|
|---|
| 14 | TMethodBitmapRawImageDataPaintBox = class(TDrawMethodPaintBox)
|
|---|
| 15 | TempBitmap: TBitmap;
|
|---|
| 16 | constructor Create; override;
|
|---|
| 17 | procedure Init(Parent: TWinControl; Size: TPoint; PixelFormat: TPixelFormat); override;
|
|---|
| 18 | procedure Done; override;
|
|---|
| 19 | procedure Paint(Sender: TObject); override;
|
|---|
| 20 | procedure DrawFrame(FastBitmap: TFastBitmap); override;
|
|---|
| 21 | end;
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 | implementation
|
|---|
| 25 |
|
|---|
| 26 | { TMethodBitmapRawImageDataPaintBox }
|
|---|
| 27 |
|
|---|
| 28 | constructor TMethodBitmapRawImageDataPaintBox.Create;
|
|---|
| 29 | begin
|
|---|
| 30 | inherited;
|
|---|
| 31 | Caption := 'TBitmap.RawImage.Data PaintBox';
|
|---|
| 32 | PaintObject := poPaintBox;
|
|---|
| 33 | Description.Add('Custom TFastBitmap data are converted to bitmap data compatible with screen. ' +
|
|---|
| 34 | 'Then data is sent to PaintBox by Draw method.');
|
|---|
| 35 | end;
|
|---|
| 36 |
|
|---|
| 37 | procedure TMethodBitmapRawImageDataPaintBox.Init(Parent: TWinControl; Size: TPoint;
|
|---|
| 38 | PixelFormat: TPixelFormat);
|
|---|
| 39 | begin
|
|---|
| 40 | inherited;
|
|---|
| 41 | TempBitmap := TBitmap.Create;
|
|---|
| 42 | TempBitmap.PixelFormat := PixelFormat;
|
|---|
| 43 | TempBitmap.SetSize(Size.X, Size.Y);
|
|---|
| 44 | end;
|
|---|
| 45 |
|
|---|
| 46 | procedure TMethodBitmapRawImageDataPaintBox.Done;
|
|---|
| 47 | begin
|
|---|
| 48 | FreeAndNil(TempBitmap);
|
|---|
| 49 | inherited Done;
|
|---|
| 50 | end;
|
|---|
| 51 |
|
|---|
| 52 | procedure TMethodBitmapRawImageDataPaintBox.Paint(Sender: TObject);
|
|---|
| 53 | var
|
|---|
| 54 | hPaint, hBmp: HDC;
|
|---|
| 55 | begin
|
|---|
| 56 | hBmp := TempBitmap.Canvas.Handle;
|
|---|
| 57 | hPaint := PaintBox.Canvas.Handle;
|
|---|
| 58 | //PaintBox.Canvas.CopyRect(Rect(0, 0, PaintBox.Width, PaintBox.Height), TempBitmap.Canvas,
|
|---|
| 59 | // Rect(0, 0, TempBitmap.Width, TempBitmap.Height));
|
|---|
| 60 | PaintBox.Canvas.Draw(0, 0, TempBitmap);
|
|---|
| 61 | //BitBlt(hPaint, 0, 0, TempBitmap.Width, TempBitmap.Height, hBmp, 0, 0, srcCopy);
|
|---|
| 62 | end;
|
|---|
| 63 |
|
|---|
| 64 | procedure TMethodBitmapRawImageDataPaintBox.DrawFrame(FastBitmap: TFastBitmap);
|
|---|
| 65 | var
|
|---|
| 66 | Y, X: Integer;
|
|---|
| 67 | PixelPtr: PCardinal;
|
|---|
| 68 | RowPtr: PCardinal;
|
|---|
| 69 | P: TPixelFormat;
|
|---|
| 70 | RawImage: TRawImage;
|
|---|
| 71 | BytePerPixel: Integer;
|
|---|
| 72 | BytePerRow: Integer;
|
|---|
| 73 | begin
|
|---|
| 74 | P := TempBitmap.PixelFormat;
|
|---|
| 75 | with FastBitmap do
|
|---|
| 76 | try
|
|---|
| 77 | TempBitmap.BeginUpdate(False);
|
|---|
| 78 | RawImage := TempBitmap.RawImage;
|
|---|
| 79 | RowPtr := PCardinal(RawImage.Data);
|
|---|
| 80 | BytePerPixel := RawImage.Description.BitsPerPixel div 8;
|
|---|
| 81 | BytePerRow := RawImage.Description.BytesPerLine;
|
|---|
| 82 | for Y := 0 to Size.Y - 1 do begin
|
|---|
| 83 | PixelPtr := RowPtr;
|
|---|
| 84 | for X := 0 to Size.X - 1 do begin
|
|---|
| 85 | PixelPtr^ := Pixels[X, Y];
|
|---|
| 86 | Inc(PByte(PixelPtr), BytePerPixel);
|
|---|
| 87 | end;
|
|---|
| 88 | Inc(PByte(RowPtr), BytePerRow);
|
|---|
| 89 | end;
|
|---|
| 90 | finally
|
|---|
| 91 | TempBitmap.EndUpdate(False);
|
|---|
| 92 | end;
|
|---|
| 93 | PaintBox.Repaint;
|
|---|
| 94 | end;
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 | end.
|
|---|
| 98 |
|
|---|