0

I’m trying to accomplish blending modes in XCode. As far as my research go, I can´t do it using storyboard or standard options.

enter image description here

As you can see on image above, I need to use a overlay layer of a bike in a blurred background. Right now I can do it using hard coded (HardC on image) blending with the following code:

[_pic1.image drawInRect:CGRectMake(_pic1.frame.origin.x, _pic1.frame.origin.y, _pic1.frame.size.width , _pic1.frame.size.height) blendMode:kCGBlendModeOverlhay alpha:1.0];

But for some reason, the bike image ends up smaller, I tried different DPI’s but it still shrinks the image a few points, I can’t understand why.

I would like to compose the layout in the storyboard, I was thinking about putting all the regular images without the blending, and then change the blending when view is loaded. Any ideas on how to blend current UIImage in context, or at least fix the size issue?

Bruno Tereso
  • 227
  • 1
  • 5
  • 15
  • Multiplying y and height by 2 looks weird, why do you do it ? Make sure the code is called after all layout operations. I don't know for sure that it would help, but you could also try to subclass `UIView` (or specifically `UIImageView`) and use something like [this](http://stackoverflow.com/a/3486147/792677) to set the `blendMode` automatically. – A-Live May 13 '14 at 11:21
  • Please show more code. What you've shown is not sufficient to diagnose the problem. For example, how is the current transform matrix set when you get the incorrect drawing? Also, your last question is confusing. You have already drawn the `UIImage` in the current context with blending. Also, what is "HardC"? – user1118321 May 13 '14 at 12:47
  • @A-Live, Still trying to implement it using subclass, it would be great. But UIImageView doesn't call drawRect, and UIView doesn't apply the blending to the image inside. – Bruno Tereso May 13 '14 at 13:07
  • From docs: `This method scales the image as needed to make it fit in the specified rectangle. This method draws the image in the current graphics context, respecting the image’s orientation setting. In the default coordinate system, images are situated down and to the right of the origin of the specified rectangle. This method respects any transforms applied to the current graphics context, however.` What your current graphics context? If it's your image/imageview then need to change rectangle to (0, 0, width, height). – jamapag May 13 '14 at 13:09
  • @user1118321, I changed last past of the question. I would like to use UIImageView on storyboard (normal png), and change the blending when view loads (to overlay). – Bruno Tereso May 13 '14 at 13:10

0 Answers0