Closed theojarrus closed 1 month ago
@bentrengrove Check this issue please
@theojarrus I created a PR for this https://github.com/google/accompanist/pull/1771 As soon as the review is done, it can be merged
I mentioned this in the PR, but it is up to the drawable implementation how it scales, not the painter. So in this example you shouldn't be using fixed coords for defining your picture, you should be using the sizing information.
Something like:
val halfWidth = width/2f
val pictureCanvas = picture.beginRecording(width, height)
pictureCanvas.drawCircle(halfWidth, halfWidth, halfWidth, Paint())
@bentrengrove Understood your point, but I'm using PictureDrawable to store and share picture data through code. In this case, it is impossible to know exact size of final view. And also it can be changed, for example, by switching landscape orientation, so, in my opinion, the image size should be also changed, like ImageView does
@bentrengrove
Describe the bug
PictureDrawable displayed using Compose Image and Accompanist DrawablePainter doesn't scale
To Reproduce
Expected behavior
Image scales depending on available size and scale strategy
Screenshots
Environment
Additional context
Thoughts about fixing
In search of the reason why my image does not scale, I deepened into the source code. I found, that picture receives size in Picture#beginRecording, then getting long value from Picture#nativeBeginRecording, which also receives picture size, and saves this long value to PictureCanvas. After that, inside Picture#draw, which is called to draw picture on some canvas, Picture#nativeDraw is called. Don't know what magic happens then, but as the result picture is rendered using size recieved in Picture#beginRecording and not Drawable#setBounds. I managed to achieve the desired result using Canvas#scale, I don't know if that can cause performance problems, but at least it works. So, it can be fixed by overwriting DrawablePainter#onDraw for PictureDrawable, here's the example of working code:
Why found this bug
I'm writing library with runtime image generation, it uses Picture to render graphics and pass through app. As the result I want to show it somewhere using Compose Image, so I used accompanist-drawablepainter, but faced this issue.