Hello, I would like to ask some help with the following.
I am developing an app, where the canvas needs to be redrawn after a click on a button. The actual display needs to be shifted up by a fixed value (and the bottom part redrawn).
Is there a way to achieve this shift (or in general, to quickly copy part of the canvas to a different location)? I was searching this forum for a similar situation without any success.
It would also help if there were a quick way to put a bitmap (stored as a double array of color values or in any other way) on the canvas to a certain position.
I would appreciate any suggestions (with or without using an extension).
At the moment, I am recalculating every pixel and drawing a point on the canvas. I am not adding my code here, because this is way too slow even for a small phone screen. I am calling canvas.drawpoint a lot of times (for a 300 by 200 canvas I call this 300x200 times and of course it takes also time to calculate the value).
By looking at the titles of the tricks, I am not sure which can be helpful. I will look at them though. I wanted to start with the pixelation one (https://groups.google.com/g/mitappinventortest/c/lJGrMxDAWas/m/o_O7NBuFHAAJ), but the image of the blocks is not there and the video is private. Is there any way to recover the image of the blocks?
I do not really worry about the first draw, it is part of the inicialization. It can take practically any reasonable amount of time. I am calculating the colors of all pixels using a certain algorithm. The important thing is that it should not take too much time to shift the image. The pixel values are already calculated, they just need to be copied to a new location.
If there were an extension containing "copy rectangle(...) to position(...)" it would be useful. Or one like "copy bitmap to position". If not, I will need to learn how to write extensions.
I am trying to implement the "save canvas" and "load as sprite approach", but I have some questions.
I attach here what I have so far and here are the relevant blocks.
When I run the app and press either the + or the - button, the save is successful, the sprite is loaded in the other canvas, but as far as I can tell, it is put in the 0,0 position, not at the position that I specify. What am I doing wrong?
Also, the first canvas is cleared as soon as I save it as an image. Is this the normal behaviour? This is not really important, because I will draw back to the original canvas, I am just curious.
In the companion, when I move from the start screen to the other screen (and change the orientation), the dimensions of the canvas are not read correctly and in the companion the original drawing does not have 1:1 scale. Squares are presented as rectangles. When I install the app, it looks OK, but nevertheless, I am curious what is happening in companion.
Yes, I can see what part of my problem was, and it does copy the image of the canvas to the other canvas. I still don't understand a few things though.
Why is the sprite copied at (0,0) instead of the specified location?
Why is the sprite enlarged? I even tried to move the sprite to canvas 1 (to overwrite what is there) and even there it did not copy in the original size.
I made some modifications:
I copied the sprite back to canvas 1 (so canvas 2 is not used in this version).
I set the size of the sprite to match the canvas size.
I cleared the canvas before setting the sprite image.
If I repeatedly click on the buttons, strange things happen. The image in the canvas is changing, but in a strange way.
Is it possible, that TinyDB is trying to read back the image before it is completely stored?
Is it possible that this behaviour is the consequence of incorrect canvas height and width reading (because of the change in orientation of the screens)? movePatternTrial_2.aia (17.4 KB)
TinyDb only stores the file name. That's an all or nothing event, though the Canvas file save sounds like it should not be depended on to be synchronous. Unfortunately, I do not know of any event to catch completion of that operation.
Yes, the Canvas Height and Width need time to settle.
Try to avoid this by coding value functions instead of global variables for various sizes, to get fresher data.
A Sprite might change size in response to the attributes of its Picture. You might try resetting the Sprite's Height and Width in proportion to an enclosing Arrangement's sizes. This would make a difference if the Canvas were larger than the enclosing Arrangement but centered in it. This is a bit of a stunt.
P.S. I was surprised to learn that the DrawPoint block actually draws a square with size equal to Canvas.LineWidth. So DrawLine would not provide any speedup.