source: GraphicTest/Methods/MethodBitmapRawImageDataPaintBox.pas

Last change on this file was 573, checked in by chronos, 5 months ago
  • Modified: Build with Lazarus 3.4.
  • Modified: Removed U prefix from unit names.
File size: 2.7 KB
Line 
1unit MethodBitmapRawImageDataPaintBox;
2
3interface
4
5uses
6 {$IFDEF windows}Windows,{$ENDIF}Classes, SysUtils, Controls, DrawMethod,
7 FastBitmap, Graphics, LCLType, FPimage, IntfGraphics, GraphType;
8
9type
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
22implementation
23
24{ TMethodBitmapRawImageDataPaintBox }
25
26constructor TMethodBitmapRawImageDataPaintBox.Create;
27begin
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.');
33end;
34
35procedure TMethodBitmapRawImageDataPaintBox.Init(Parent: TWinControl; Size: TPoint;
36 PixelFormat: TPixelFormat);
37begin
38 inherited;
39 TempBitmap := TBitmap.Create;
40 TempBitmap.PixelFormat := PixelFormat;
41 TempBitmap.SetSize(Size.X, Size.Y);
42end;
43
44procedure TMethodBitmapRawImageDataPaintBox.Done;
45begin
46 FreeAndNil(TempBitmap);
47 inherited;
48end;
49
50procedure TMethodBitmapRawImageDataPaintBox.Paint(Sender: TObject);
51var
52 hPaint, hBmp: HDC;
53begin
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);
60end;
61
62procedure TMethodBitmapRawImageDataPaintBox.DrawFrame(FastBitmap: TFastBitmap);
63var
64 Y, X: Integer;
65 PixelPtr: PCardinal;
66 RowPtr: PCardinal;
67 P: TPixelFormat;
68 RawImage: TRawImage;
69 BytePerPixel: Integer;
70 BytePerRow: Integer;
71begin
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;
92end;
93
94end.
95
Note: See TracBrowser for help on using the repository browser.