2017-12-04 10 views
0

私はUIPinchGestureを使用してイメージを拡大縮小できるようにしたいと思います。画像が望むサイズに拡大縮小されると、高解像度の.pngとしてPhotoLibraryに保存されたUIViewを新しく保存することができます。ここで新しくスケーリングされたイメージをPhotoLibraryに保存します

は私のスケール画像コードであり、私のコードを保存:

//タッチスケール画像のアクション

@IBAction func scaleImage(_ sender: UIPinchGestureRecognizer) { 

    myImageView.transform = CGAffineTransform(scaleX: sender.scale, y: sender.scale) 
} 

//画像機能

@IBAction func saveArtwork(_ sender: AnyObject) { 


    UIGraphicsBeginImageContext(self.myImageView.bounds.size) 

    // The code below may solve your problem 
    myImageView.layer.render(in: UIGraphicsGetCurrentContext()!) 

    let image = UIGraphicsGetImageFromCurrentImageContext() 
    UIGraphicsEndImageContext() 

    let activity = UIActivityViewController(activityItems: [image!], applicationActivities: nil) 
    present(activity, animated: true, completion: nil) 



} 

を保存私はアプリところ作っていますイメージを拡大縮小して新しい縮尺を保存することができます。範囲外になった場合には、サイズを大きくしたり小さくしたりすることができます。スケールされた小さい場合は、私はバックグラウンドを保存して、編集の背景に対して小さな画像を見ることができるようにしたいと思います。 the original image is an instagram square photo. this is the app where i scale the image to be very small. i would like it to appear just this way with the black background as a new photo that is the same resolution and aspect ratio as the screen. so it will appear to be a black portrait rectangle with the new scaled image.my app saves this image to the library it is low resolution, unscaled and the background it looks to be transparent and appears white. not what i want.

私は今取得しています結果は、私はそれを中心に、左と右の画像ビューの境界にトリミングされて保存するときの画像は、その後、スケールするように見えるということです。

答えて

0

AHA!私はそれを持って、私は別のサブビューを作成し、そのビューの子ビューを作成し、その後、新しく作成されたビューにアウトレットを与え、これにコードを変更しました:

@IBAction func saveArtwork(_送信者:AnyObject){

UIGraphicsBeginImageContext(self.captureView.bounds.size) 

    // The code below may solve your problem 
    captureView.layer.render(in: UIGraphicsGetCurrentContext()!) 

    let image = UIGraphicsGetImageFromCurrentImageContext() 
    UIGraphicsEndImageContext() 

    let activity = UIActivityViewController(activityItems: [image!], applicationActivities: nil) 
    present(activity, animated: true, completion: nil) 
} 

新しいビューはキャプチャビューです。

今は動作しますが、それはうんざりのように見えます。それは非常に低い解像度です。私はこのスナップショットをどのように取るかを把握し、それをデバイスの解像度にする必要があります。

関連する問題