Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Scale filter makes the image as red with the "color blended layers" option #65

Closed
Vinzius opened this issue Dec 22, 2015 · 3 comments
Closed
Assignees
Milestone

Comments

@Vinzius
Copy link

Vinzius commented Dec 22, 2015

Hi !

First, thank you for this great library, I really appreciate its design.

I noticed that when I'm using a scaling method of AlamofireImage (e.g. af_imageAspectScaledToFillSize), I see its container (basic UIImageView) as red in the "color blended layers". But if I'm using my "own", then the color is green.

I'm putting below the code I used to create the image/imageView (nothing special):

// instanciate image view
let imageView = UIImageView()
imageView.frame = CGRectMake(10.0, 10.0, 50.0, 50.0)
self.view.addSubview(imageView)

// add image
if let image = UIImage(named: "image-test")?.af_imageAspectScaledToFillSize(CGSizeMake(50.0, 50.0)) {
    image.af_inflate()
    imageView.image = image
}

I'm not sure if it's a big performance issue or not.
The resizing code I'm using is from this blog, which I converted to Swift.

1/ Do you want an Xcode project to reproduce the issue?
2/ Do you think it would be worth updating the scaling method? I could manage a pull-request if you want.

Notes: Xcode 7.2, iOS 9.2

Cheers,
Vincent

@Vinzius
Copy link
Author

Vinzius commented Dec 23, 2015

It seems the problem is more simple than I anticipated.

The uiimageview is red because the scaled image isn't fully opaque.

The culprit is here:
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)

Should we find a way to specify a fully opaque image?

cnoon added a commit that referenced this issue Jan 3, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…ble.
@cnoon cnoon added this to the 2.3.0 milestone Jan 3, 2016
@cnoon
Copy link
Member

cnoon commented Jan 3, 2016

Thank you for reporting this @Vinzius!

I spent a bunch of time trying to figure out how to elegantly solve this problem. After several different approaches, I'm fairly happy with what I came up with. I added some alpha component inspection properties in 86602b2. Then I used those new properties to be smarter about specifying the opaque property in UIGraphicsBeginImageContextWithOptions in cd072e3.

What these changes will do is to automatically set the opaque flag to true when the image being resized is already opaque. In all the cases where transparent padding is used, we need to continue to set the opaque flag to false, otherwise that can result in undesired colored padding.

I also added some additional information to the public docstring of the af_imageAspectScaledToFitSize method to make it a bit easier to understand how the method behaves.

Hopefully these changes help make things easier for you.

Thanks again! 🍻

@cnoon cnoon closed this as completed Jan 3, 2016
@cnoon cnoon self-assigned this Jan 3, 2016
@Vinzius
Copy link
Author

Vinzius commented Jan 3, 2016

Thanks Christian!
It seems to be a good balance between solution and (end user) implementation ^^
Happy new year ;)

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants