0

I want to blend two UIImages as Fused App is doing:

https://itunes.apple.com/us/app/fused-double-exposure-video/id869117407?mt=8

What Fused is doing, it takes two images (foreground & background) and apply blending in such a way that background remains the same and user can move,rotate & size the foreground image. I attached two images for better understanding. I want to achieve the same behaviour in my app. I have tried all CoreImage & CoreGraphics but I could not achieve this. Help needed from all of you.

First Screen: After applying Overly blend mode.

Image After Blending!

Second Screen: Change the size of foreground image:

Image after arranging the foreground image

My Result: Screenshot of the app

1 Answers1

0

You can achieve what you want by using CHTStickerView, I've used it before and it works great. CHTStickerView is a movable, resizable, rotatable UIView with one finger, which is fully customizable.

Use CHTStickerView as your foreground image and UIImageView as your background image.

So your code should look something like this:

- (void)viewDidLoad {
  [super viewDidLoad];

  //background
  UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.frame];
  [backgroundImageView setImage:@"background.png"];
  [self.view addSubview:backgroundImageView];

  //foreground
  UIImageView *foregroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)];
  [foregroundImageView setImage:[UIImage imageNamed:@"foreground.png"]];

  CHTStickerView *stickerView = [[CHTStickerView alloc] initWithContentView:foregroundImageView]; //set your foreground image as content in CHTStickerView
  stickerView.center = self.view.center;
  stickerView.delegate = self;
  [stickerView setImage:[UIImage imageNamed:@"Close"] forHandler:CHTStickerViewHandlerClose];
  [stickerView setImage:[UIImage imageNamed:@"Rotate"] forHandler:CHTStickerViewHandlerRotate];
  [self.view addSubview:stickerView];
}

UPDATE

Alright I downloaded the app and checked out blend. I think what the app is doing is just getting the opacity value of the foreground image with the slide bar and drawing the foreground image (opacity set) on the background image.

So to set the opacity of a UIImage check this out: How to set the opacity/alpha of a UIImage?

And to draw and image over another check this out: Draw another image on a UIImage

To summarize, what you need to do is:

1) get the position and size of the CHTStickerView after user rotated and resize

2) get the UIImage from CHTStickerView, get the opacity value from slider

3) set opacity to image and draw image on your background image

Hope this helps!

Community
  • 1
  • 1
Ty Lertwichaiworawit
  • 2,950
  • 2
  • 23
  • 42
  • actually this is not the issue. My issue is about image blending. I will be very thankful to you if you can suggest a solution about this. – Muhammad Junaid Butt Oct 24 '15 at 10:52
  • I attached the screenshot of my app too. So you will get a brief understanding what I want to achieve. – Muhammad Junaid Butt Oct 24 '15 at 10:58
  • @MuhammadJunaidButt so you want to draw foreground image on background image? – Ty Lertwichaiworawit Oct 24 '15 at 16:22
  • I want to blend two images like Fused app is doing. I attached three images in my question for more convenience. Fused app blend two images and resultant image stored in foreground image. Surprising thing is that if you move/rotate/scale the foreground image, blend effect will remain the same and foreground image does not have the image of background but have the color reflection. If possible please check the screenshots and also play with Fused App (https://itunes.apple.com/us/app/fused-double-exposure-video/id869117407?mt=8). I'm stuck in this issue and have burnt my 10 days on it. – Muhammad Junaid Butt Oct 24 '15 at 17:20
  • @MuhammadJunaidButt I checked out the app and its quite simple. Check out my updated answer. – Ty Lertwichaiworawit Oct 24 '15 at 17:35
  • Thanks to proactively answer my questions. Unfortunately, this is not the solution that I'm looking for. Can you perform a test scenario for me? 1) Use Fused app and select background & foreground images 2) Apply Overlay blend mode 3) Then select the arrange button and you will be able to change the size of foreground image. As per my knowledge, blend applies on two images and resultant will be a single image. Fused app is applying blend but its resultant image can be resized and it also does not have the reflection of background image. – Muhammad Junaid Butt Oct 24 '15 at 17:59
  • Please check my app screenshot that is the last screenshot and you will see the small image that is the blend of background & foreground image and I resized it but it does not have the same effect as Fused app has. Fused app does not have the reflection of background image but it perfectly applies the blend. Please help me in this regard. – Muhammad Junaid Butt Oct 24 '15 at 18:04