-
-
Notifications
You must be signed in to change notification settings - Fork 791
Add drawing bitmap images to Canvas #4047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Not sure if I need to apply the matrix myself.
corranwebster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes on the implementation.
I think this is ready for review.
HalfWhitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HECK YES. I am excited about this!
I haven't had a chance to look at this yet as thoroughly as it deserves, but I have a couple of preliminary questions / comments.
| # Have an UIImage, need a CGImage | ||
| cg_image = ui_image.CGImage | ||
|
|
||
| # Quartz is flipped relative to data, so we: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true on iOS as well? I was under the impression that, unlike macOS, iOS always counts from the top left:
The default coordinate system for views in iOS and OS X differ in the orientation of the vertical axis:
- OS X. The default coordinate system has its origin at the lower left of the drawing area; positive values extend up and to the right from it. You can programmatically “flip” a view’s coordinate system in OS X.
- iOS. The default coordinate system has its origin at the upper left of the drawing area, and positive values extend down and to the right from it. You cannot change the default orientation of a view’s coordinate system in iOS—that is, you cannot “flip” it.
That said, I suppose I can't argue with test results, if this is working...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it has to be, given how it's working. I was a bit surprised on Cocoa that I had to flip the image and that the flipped coordinates flag didn't fix that automatically. I expect that something similar is happening on iOS. I think when you did down deep enough you get to Quartz which is very much a bottom-left origin system (which I think comes from PostScript originally!), no matter what you layer on top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does make sense... seems safe to file this under "Might be interesting to dig deeper on someday, but it works as intended."
johnzhou721
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 small notes here, from a quick look at this it seems that this is great, however I'm not very familiar with this part of the code.
Co-authored-by: John <johnzhou721@gmail.com>
johnzhou721
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked through this PR, and nothing's too concerning. But I'm not sufficiently familiar with Canvas -- let's wait for @HalfWhitt's opinion on this.
HalfWhitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having sat down and looked through this, it looks perfect to me (with the exception of one minor copy-paste error, which I can fix). This is very thorough, thank you!
| # Have an UIImage, need a CGImage | ||
| cg_image = ui_image.CGImage | ||
|
|
||
| # Quartz is flipped relative to data, so we: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does make sense... seems safe to file this under "Might be interesting to dig deeper on someday, but it works as intended."
This adds a
draw_imagemethod to theCanvasclass, along with aDrawImagesubclass ofDrawingObjectthat adds the ability to render anImageintoCanvaswith the current transforms applied. It currently supports the ability to draw an image at a point, or to draw an image into a destination rectangle, but doesn't currently support the ability to draw a slice out of the source image.Has tests, and have added image drawing as one of the options in the Canvas example.
Fixes #955.
To Do:
PR Checklist: