0

My app lets the user take photos, and in every photo there is a small watermark. The problem is: The watermark appears bigger when the photo has been taken with the front camera. I want the watermark to have the same size no matter which camera has been used.

Any ideas?

My code:

UIImage *backgroundImage = image;
UIImage *watermarkImage = [UIImage imageNamed:@"Watermark.png"];

UIGraphicsBeginImageContext(backgroundImage.size);

[backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];

[watermarkImage drawInRect:CGRectMake(backgroundImage.size.width - watermarkImage.size.width, backgroundImage.size.height - watermarkImage.size.height, watermarkImage.size.width, watermarkImage.size.height)];

UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.imageView.image = result;
Yomo
  • 175
  • 2
  • 15

2 Answers2

0

The watermark is the same size. The image is not, since the two cameras have different resolutions. You need to resize the watermark in proportion to the image size. I believe you can use scaleImage:toSize: for this.

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • Isn't this going to be hard since the resolution is different on all the different iPhones? – Yomo Oct 19 '15 at 01:27
  • No, not really. Decide on what relative size you want (e.g. 1/10th of the height of the image), then calculate what the real height of the watermark should be and rescale accordingly. – Amadan Oct 19 '15 at 01:28
  • 1) "Doesn't work" is an useless report. Do you get a watermark of the wrong size? Is the method `scaleImage:toSize:` nonexistent? Does FBI come and confiscate your cameras? 2) Sorry, I am not a Cocoa developer. The answer is conceptual because while I can implement it in another language, I cannot show you how to do it in ObjC. – Amadan Oct 19 '15 at 04:29
  • Your logic would work if there was a way to detect the screens' resolution. I'm sure there is, but I can't seem to find how... @Amadan – Yomo Oct 19 '15 at 04:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92678/discussion-between-simonsayzhi-and-amadan). – Yomo Oct 19 '15 at 04:36
0

Figured out a weird solution. I turned on edit mode: [picker setAllowsEditing:YES]; and now the watermark is the same size no matter what camera you use.

Yomo
  • 175
  • 2
  • 15