source: trunk/Methods/UMethodBitmapRawImageDataPaintBox.pas

Last change on this file was 2, checked in by chronos, 5 years ago
File size: 2.7 KB
Line 
1unit UMethodBitmapRawImageDataPaintBox;
2
3{$mode delphi}
4
5interface
6
7uses
8 {$IFDEF windows}Windows,{$ENDIF}Classes, SysUtils, Controls, UDrawMethod, UFastBitmap, Graphics, LCLType,
9 FPimage, IntfGraphics, GraphType;
10
11type
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
24implementation
25
26{ TMethodBitmapRawImageDataPaintBox }
27
28constructor TMethodBitmapRawImageDataPaintBox.Create;
29begin
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.');
35end;
36
37procedure TMethodBitmapRawImageDataPaintBox.Init(Parent: TWinControl; Size: TPoint;
38 PixelFormat: TPixelFormat);
39begin
40 inherited;
41 TempBitmap := TBitmap.Create;
42 TempBitmap.PixelFormat := PixelFormat;
43 TempBitmap.SetSize(Size.X, Size.Y);
44end;
45
46procedure TMethodBitmapRawImageDataPaintBox.Done;
47begin
48 FreeAndNil(TempBitmap);
49 inherited Done;
50end;
51
52procedure TMethodBitmapRawImageDataPaintBox.Paint(Sender: TObject);
53var
54 hPaint, hBmp: HDC;
55begin
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);
62end;
63
64procedure TMethodBitmapRawImageDataPaintBox.DrawFrame(FastBitmap: TFastBitmap);
65var
66 Y, X: Integer;
67 PixelPtr: PCardinal;
68 RowPtr: PCardinal;
69 P: TPixelFormat;
70 RawImage: TRawImage;
71 BytePerPixel: Integer;
72 BytePerRow: Integer;
73begin
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;
94end;
95
96
97end.
98
Note: See TracBrowser for help on using the repository browser.