Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd support for image cropping #248
Conversation
| @@ -121,6 +122,10 @@ impl CGImageRef { | |||
| }; | |||
| data_provider.copy_data() | |||
| } | |||
|
|
|||
| pub fn cropped(&self, rect: CGRect) -> CGImage { | |||
| unsafe { CGImage::from_ptr(CGImageCreateWithImageInRect(self.as_ptr(), rect)) } | |||
This comment has been minimized.
This comment has been minimized.
jdm
Aug 14, 2018
Member
This can return null if the rect defines an area that is not in the image: https://developer.apple.com/documentation/coregraphics/1454683-cgimagecreatewithimageinrect .
This comment has been minimized.
This comment has been minimized.
application-developer-DA
Aug 15, 2018
Author
Contributor
Ah, you're totally right. Somehow I've missed that.
080a424
to
e6cd2a0
|
Updated the pull request to take into account the null value which |
|
@bors-servo r+ |
|
|
Add support for image cropping <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/248) <!-- Reviewable:end -->
|
|
|
|
||
| /// Returns a cropped image. If the `rect` specifies a rectangle which lies outside of the | ||
| /// image bounds, the `None` is returned. | ||
| pub fn cropped(&self, rect: CGRect) -> Option<CGImage> { |
This comment has been minimized.
This comment has been minimized.
jrmuizel
Aug 15, 2018
Collaborator
It might be good to include the fact that this uses CGImageCreateWithImageInRect and I'm pretty sure that makes it so that the underlying storage is shared between the two images.
application-developer-DA commentedAug 14, 2018
•
edited by larsbergstrom
This change is