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