How to draw an image in TImage?

How to create an image in TImagein Delphi?

Why do I need this: instead of creating more TImages at runtime, I could create it and save my image there, knowing that it will “fit” until it reaches the height and width of the TImage.

Please suggest any ideas for this.

Thanks!

EDIT: Please note: I am not asking to stretch the image, but filling the canvas, repeating the image.

+3
source share
5 answers

Below is the function that I used, using the existing TImage component and breaking it on top of the target canvas:

procedure TileImage(const Source:tImage;
    Target: TCanvas;
    TargetHeight,TargetWidth:integer);
// Tiles the source image over the given target canvas
var
  X, Y: Integer;
  dX, dY: Integer;
begin
  dX := Source.Width;
  dY := Source.Height;
  Y := 0;
  while Y < TargetHeight do
    begin
      X := 0;
      while X < TargetWidth do
        begin
          Target.Draw(X, Y, Source.Picture.graphic);
          Inc(X, dX);
        end;
      Inc(Y, dY);
    end;
end;

tLabel , , :

TileImage(Image1,Label1.Canvas,Label1.Height,Label1.Width);
+5

, TImage,

procedure TmyForm.Button1Click(Sender: TObject);
    var mybmp:TBitmap;
begin
    mybmp:= TBitmap.Create();
    try
        mybmp.Assign(Image1.Picture.Bitmap);

        Image1.Picture.Bitmap.SetSize(Image1.Width,Image1.Height);
        Image1.Canvas.Brush.Bitmap := mybmp;
        Image1.Canvas.FillRect(Image1.BoundsRect);

        mybmp.FreeImage;
    finally
        FreeandNil(mybmp)
    end;
end;

:

, , .

Image1.Canvas Image1.Picture.Bitmap.Canvas - , .

TImage , , , Image1.Canvas.Brush.Bitmap: = Image1.Picture.Bitmap " ".

+5

canvas.brush.bitmap := . canvas.fillrect(canvas.cliprect), . , , Delphi , , , .

+4

Delphi - "Bitmap" ( ).

:

procedure TBmpForm.FormPaint(Sender: TObject);
var
  x, y: Integer;
begin
  y := 0;
  while y < Height do
  begin
    x := 0;
    while x < Width do
    begin
      // Bitmap is a TBitmap.
      //  form OnCreate looks like this:
      //    Bitmap := TBitmap.Create;
      //    Bitmap.LoadFromFile('bor6.bmp');
      //  or you can use Canvas.Draw(x, y, Image1.Picture.Bitmap),
      //  instead of Canvas.Draw(x, y, Bitmap);
      //
      Canvas.Draw(x, y, Bitmap); //Bitmap is a TBitmap. 
      x := x + Bitmap.Width; // Image1.Picture.Bitmap.Width;
    end;
    y := y + Bitmap.Height; // Image1.Picture.Bitmap.Height;
  end;
end;

, !

+3

"" ""? , TImage . TImage .

0
source

Source: https://habr.com/ru/post/1715014/


All Articles