mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-05 05:51:42 +00:00
Merge pull request #283 from andyscott/feature-template-image-mod-block
Add image modification block to render template images w/ tint.
This commit is contained in:
commit
3b8de5cf52
@ -137,4 +137,16 @@ ASDISPLAYNODE_EXTERN_C_BEGIN
|
||||
*/
|
||||
asimagenode_modification_block_t ASImageNodeRoundBorderModificationBlock(CGFloat borderWidth, UIColor *borderColor);
|
||||
|
||||
/**
|
||||
* @abstract Image modification block that applies a tint color à la UIImage configured with
|
||||
* renderingMode set to UIImageRenderingModeAlwaysTemplate.
|
||||
*
|
||||
* @param tintColor The color to tint the image.
|
||||
*
|
||||
* @see <imageModificationBlock>
|
||||
*
|
||||
* @returns An ASImageNode image modification block.
|
||||
*/
|
||||
asimagenode_modification_block_t ASImageNodeTintColorModificationBlock(UIColor *color);
|
||||
|
||||
ASDISPLAYNODE_EXTERN_C_END
|
||||
|
||||
@ -373,3 +373,20 @@ extern asimagenode_modification_block_t ASImageNodeRoundBorderModificationBlock(
|
||||
return modifiedImage;
|
||||
};
|
||||
}
|
||||
|
||||
extern asimagenode_modification_block_t ASImageNodeTintColorModificationBlock(UIColor *color)
|
||||
{
|
||||
return ^(UIImage *originalImage) {
|
||||
UIGraphicsBeginImageContextWithOptions(originalImage.size, NO, originalImage.scale);
|
||||
|
||||
// Set color and render template
|
||||
[color setFill];
|
||||
UIImage *templateImage = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
|
||||
[templateImage drawAtPoint:CGPointZero];
|
||||
|
||||
UIImage *modifiedImage = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
return modifiedImage;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user