Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TPACentralize(var TPA: TPointArray; area: TBox);
- var
- o: TPoint;
- b: TBox;
- begin
- if (Length(TPA) > 0) then
- begin
- b := GetTPABounds(TPA);
- o := Point(((Round(area.X1 + ((area.X2 - area.X1) / 2)) - (((b.X2 - b.X1) + 1) div 2)) - b.X1), ((Round(area.Y1 + ((area.Y2 - area.Y1) / 2)) - (((b.Y2 - b.Y1) + 1) div 2)) - b.Y1));
- OffsetTPA(TPA, o);
- end;
- end;
- procedure ZoomTPA(var TPA: TPointArray; Times: Integer);
- var
- w, h, l, i, x, y, width, height: Integer;
- m: array of TBoolArray;
- b: TBox;
- begin
- if (times <> 0) then
- begin
- l := Length(TPA);
- if (l > 0) then
- begin
- b := GetTPABounds(TPA);
- w := ((b.X2 - b.X1) + 1);
- h := ((b.Y2 - b.Y1) + 1);
- if (times > 0) then
- begin
- width := (w * times);
- height := (h * times);
- end else
- begin
- times := Abs(times);
- width := (w div times);
- height := (h div times);
- end;
- SetLength(m, w);
- for x := 0 to (w - 1) do
- begin
- SetLength(m[x], h);
- for y := 0 to (h - 1) do
- m[x][y] := False;
- end;
- for i := 0 to (l - 1) do
- m[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] := True;
- SetLength(TPA, 0);
- l := 0;
- for y := 0 to (height - 1) do
- for x := 0 to (width - 1) do
- if m[((x * w) div width)][((y * h) div height)] then
- begin
- SetLength(TPA, (l + 1));
- TPA[l] := Point((x + b.X1), (y + b.Y1));
- Inc(l);
- end;
- end;
- end;
- end;
- procedure SetPixels(bmp: Integer; TPA: TPointArray; color: Integer);
- var
- a, b, w, h: Integer;
- begin
- b := High(TPA);
- if (b > -1) then
- begin
- try
- GetBitmapSize(bmp, w, h);
- except
- Exit;
- end;
- for a := 0 to b do
- if ((TPA[a].X > -1) and (TPA[a].Y > -1) and (TPA[a].X < w) and (TPA[a].Y < h)) then
- FastSetPixel(bmp, TPA[a].X, TPA[a].Y, color);
- end;
- end;
- var
- zoomed, original: TPointArray;
- bmp: Integer;
- b: TBox;
- const
- ZOOM = 3;
- begin
- bmp := CreateBitmap(500, 500);
- original := [Point(211, 212), Point(213, 214), Point(215, 216), Point(217, 218)];
- zoomed := CopyTPA(original);
- ZoomTPA(zoomed, ZOOM);
- b := GetTPABounds(original);
- TPACentralize(zoomed, b);
- SetPixels(bmp, zoomed, 255);
- SetPixels(bmp, original, 16777215);
- DisplayDebugImgWindow(500, 500);
- DrawBitmapDebugImg(bmp);
- end.
Advertisement
Add Comment
Please, Sign In to add comment