I tried to display it like this:

Picture[] mas_S = new Picture[10]; .................................. canvas.translate(200, 100); canvas.drawPicture(mas_S[0]); 

is displayed, but with an offset, but I just need to output by the specified coordinates (x, y)

  • And со смещением - Is it not alone, as по координатам ? - Vladyslav Matviienko
  • No, because each subsequent output is shifted relative to the first output. canvas.translate (200,100) shifts the output to these coordinates relative to the previous output. Maybe there are some other methods? For example, like the output point of canvas.drawPoint (x, y, p). - kaaa
  • @kaaa After displaying the image, you can reverse the canvas.translate (-200, -100); So you will return to the starting point. - iramm

1 answer 1

Method 1

  Picture picture = mas_S[0]; int pictureWidth = picture.getWidth(); int pictureHeight = picture.getHeight(); Rect rect = new Rect(100, 200, 100 + pictureWidth, 200 + pictureHeight); canvas.drawPicture(picture, rect); 

Method 2

  canvas.translate(200, 100); canvas.drawPicture(mas_S[0]); canvas.translate(-200, -100); 

As a result, you will return to the original canvas .

  • The answers are correct, but I wanted to solve a problem with a single operation. The fact is that you will have to draw a lot and each time arrange the pictures in such a way, I’m afraid it will slow down the application. While I will not note that the answer is given, I will wait for more. If no one else offers the best option, then I will note this. - kaaa
  • @kaaa, it will not slow down if the picture is cached in memory. You have been given the right answer. Yours does not work, because every time you make an offset by vector translate. - Vitalii Obideiko
  • And how to cache pictures in memory? - kaaa