0

I have looked at every example I can find in previous questions and nothing works. I am merging two images by copying a cropped image to pasteboard and then pasting it in another image view. That works fine but when I try to save it the image is always squished(may be a scale issue but it seems only the vertical size getting distorted. This is the result of combining the images before trying to save it

enter image description here

This is after saving the image to the photos album

enter image description here

The image will not stay in the translated location and it's distorted. Here is the code when I save the image

    let fullSize:CGSize = photoView.image!.size
    let newSize:CGSize = fullSize
    let scale:CGFloat = newSize.height/fullSize.height
    let offset:CGFloat = (newSize.width - fullSize.width*scale)/2
    let offsetRect:CGRect = CGRect.init(x: offset, y: 0, width: newSize.width - offset*2, height: newSize.height)
            
    UIGraphicsBeginImageContext(newSize);
    self.photoView.image!.draw(in: offsetRect)
            
    self.copiedView.image!.draw(in: CGRect.init(x: 0, y: 0, width: photoView.image!.size.width, height:photoView.image!.size.height))
    let combImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext();
                
    //photoView.image = combImage
    UIImageWriteToSavedPhotosAlbum(combImage, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)    

Any help is appreciated

sonique
  • 4,539
  • 2
  • 30
  • 39
mmoore410
  • 417
  • 1
  • 5
  • 12
  • `fullSize` is equal to `newSize`, so `scale` is _always_ 1, so `offset` is _always_ 0. Are these intended? You don't seem to be storing the transformation applied to the copied image anywhere... – Sweeper Apr 24 '21 at 14:31
  • To be honest I've tried so many things I started looking at examples and that was the last thing I tried. Thanks, that at least gives me an idea of what to try next. – mmoore410 Apr 24 '21 at 17:05
  • Could be a variant of the problem I solve here: https://stackoverflow.com/a/43720791/341994 – matt Apr 25 '21 at 01:29
  • I'll look at that, thanks. I'm pretty sure it has to do with the copiedView imageview. – mmoore410 Apr 25 '21 at 11:51

0 Answers0