Rank: Member
Groups: Member
Joined: 10/14/2004(UTC) Posts: 37
|
I want to make a crop mask like the example in VB, the difference is that I'm using Delphi. I translated the Visual Basic code to Delphi code: Code:
procedure TMainForm.TiffViewerDoubleBufferPaint(ASender: TObject;
Hdc: Cardinal);
var X1, Y1, X2, Y2: Integer;
begin
if (TiffViewer.SelectionWidth > 0) and (TiffViewer.SelectionHeight > 0) then
begin
//'Attach graphics object to temporary device context
//'which is used for double buffer painting
TiffViewer.Bitmap.Graphics.Engine := DrawingEngineGdiplus;
TiffViewer.Bitmap.Graphics.Antialiasing := False;
TiffViewer.Bitmap.Graphics.Brush.PrimaryColor := $80FF0000;
//'To shade a part of image which should be cropped,
// 'we will draw four semi-transparent rectangles.
//'Draw top part
// 'Convert bitmap coordinates to control and draw a top rectangle
TiffViewer.BitmapToControlCoords(0, 0, X1, Y1);
TiffViewer.BitmapToControlCoords(TiffViewer.Bitmap.Data.Width, TiffViewer.SelectionTop, X2, Y2);
TiffViewer.Bitmap.Graphics.DrawRectangle(X1, Y1, X2 - X1, Y2 - Y1, False, False, 0);
// 'Draw bottom part
// 'Convert bitmap coordinates to control and draw a bottom rectangle
TiffViewer.BitmapToControlCoords(0, TiffViewer.SelectionTop + TiffViewer.SelectionHeight, X1, Y1);
TiffViewer.BitmapToControlCoords(TiffViewer.Bitmap.Data.Width, TiffViewer.Bitmap.Data.Height, X2, Y2);
TiffViewer.Bitmap.Graphics.DrawRectangle(X1, Y1, X2 - X1, Y2 - Y1, True, False, 0);
// 'Draw left part
// 'Convert bitmap coordinates to control and draw a left rectangle
TiffViewer.BitmapToControlCoords(0, TiffViewer.SelectionTop, X1, Y1);
TiffViewer.BitmapToControlCoords(TiffViewer.SelectionLeft, TiffViewer.SelectionTop + TiffViewer.SelectionHeight, X2, Y2);
TiffViewer.Bitmap.Graphics.DrawRectangle(X1, Y1, X2 - X1, Y2 - Y1, True, False, 0);
// 'Draw right part
// 'Convert bitmap coordinates to control and draw a right rectangle
TiffViewer.BitmapToControlCoords(TiffViewer.SelectionLeft + TiffViewer.SelectionWidth, TiffViewer.SelectionTop, X1, Y1);
TiffViewer.BitmapToControlCoords(TiffViewer.Bitmap.Data.Width, TiffViewer.SelectionTop + TiffViewer.SelectionHeight, X2, Y2);
TiffViewer.Bitmap.Graphics.DrawRectangle(X1, Y1, X2 - X1, Y2 - Y1, True, False, 0);
end;
end;
When I compile, I don't get any error. But when I try to draw a selection rectangle, I get an error: [Image was removed] I mostly use TIFF image's. Thanks in advance... Edited by user Friday, December 18, 2009 8:37:55 PM(UTC)
| Reason: Not specified
|