Skip to content

Conversation

daisy1754
Copy link

Currently, if users scale an image smaller than bounds area, a padding area is filled with black color. This PR change the behaviour to filling padding with a color of the background view. The result should be more WYSIWYG for users.

@daisy1754
Copy link
Author

I made another commit to answer discussion above. Please have a look 😄

@adahan
Copy link

adahan commented Jan 20, 2015

Hi, I tried to replace "blackColor" by "clearColor". This doesn't change anything. Someone could give me a hint about how I can get a clear background? Thanks in advance

Edit: I found the answer. My source hadn't any alpha chanel.
=> Solution to add alpha canal to add in -(CGIImageRef)newTransformedImage method

//ADD ALPHA CHANEL
{
CGImageAlphaInfo alpha = CGImageGetAlphaInfo(source);
BOOL hasAlpha = (alpha == kCGImageAlphaFirst || alpha == kCGImageAlphaLast || alpha == kCGImageAlphaPremultipliedFirst || alpha == kCGImageAlphaPremultipliedLast);

if (!hasAlpha) {
    size_t width = CGImageGetWidth(source);
    size_t height = CGImageGetHeight(source);

    CGContextRef offscreenContext = CGBitmapContextCreate(NULL,
                                                          width,
                                                          height,
                                                          CGImageGetBitsPerComponent(source),
                                                          0,
                                                          CGImageGetColorSpace(source),
                                                          kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);

    CGContextDrawImage(offscreenContext, CGRectMake(0, 0, width, height), source); 
    source = CGBitmapContextCreateImage(offscreenContext);

    CGContextRelease(offscreenContext);
}

//ADD ALPHA CHANEL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants