UIImage cardboard does not use scale

I create a custom keyboard and I am having problems adding an image to the cardboard and maintaining the appropriate scale and resolution with the inserted image. Let me start with a screenshot of the keyboard to illustrate my problems:

Screenshot example

Thus, the face image in the upper left corner of the keyboard is only UIButton with the original photo set in the background. When the button is pressed, the image changes with the following function:

func imageResize(image:UIImage, size:CGSize)-> UIImage {

    let scale  = UIScreen.mainScreen().scale

    UIGraphicsBeginImageContextWithOptions(size, false, scale)
    var context = UIGraphicsGetCurrentContext()

    CGContextSetInterpolationQuality(context, kCGInterpolationHigh)
    image.drawInRect(CGRect(origin: CGPointZero, size: size))

    let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    return scaledImage
}

UIImage , UIButton , . , , UIImageView, . - , . UIImageView :

func addImageToBottomRight(image: UIImage) {
    var tempImgView = UIImageView(image: image)
    self.view.addSubview(tempImgView)
    tempImgView.frame.offset(dx: 100.0, dy: 50.0)
}

, , , , , :

let pb = UIPasteboard.generalPasteboard()!

var pngType = UIPasteboardTypeListImage[0] as! String
var jpegType = UIPasteboardTypeListImage[2] as! String

pb.image = image
pb.setData(UIImagePNGRepresentation(image), forPasteboardType: pngType)
pb.setData(UIImageJPEGRepresentation(image, 1.0), forPasteboardType: jpegType)

, . - ? , , UIImages .

UIImage , - :

Starting Image Size is (750.0, 750.0)
Size to scale to is: (78.0, 78.0))
Initial Scale: 1.0

Resized Image Size is (78.0, 78.0)
Resized Image Scale: 2.0
+2
1

, , , , . , , iMessages, whatsapp, .., , , , (, 260 ).

, 150x150 image @1x , 260, .

150x150 image is stretched and displayed in a field of 260x260

185 , 520x150. , imessage, 260 , cramming 520x150 260x75, , 75x75 @2x.

Stamp Image

UIImage ,

extension UIImage {
    func addMargin(withInsets inset: UIEdgeInsets) -> UIImage? {
         let finalSize = CGSize(width: size.width + inset.left + inset.right, height: size.height + inset.top + inset.bottom)
         let finalRect = CGRect(origin: CGPoint(x: 0, y: 0), size: finalSize)

            UIGraphicsBeginImageContextWithOptions(finalSize, false, scale)
            UIColor.clear.setFill()
            UIGraphicsGetCurrentContext()?.fill(finalRect)

            let pictureOrigin = CGPoint(x: inset.left, y: inset.top)
            let pictureRect = CGRect(origin: pictureOrigin, size: size)

            draw(in: pictureRect)
            let finalImage = UIGraphicsGetImageFromCurrentImageContext()
            defer { UIGraphicsEndImageContext() }

            return finalImage
 }

}

0

All Articles