2017-12-04 4 views
0

사용자가 UIPinchGesture를 사용하여 이미지의 크기를 조정할 수 있기를 바랍니다. 이미지를 원하는 크기로 조정하면 새로 스케일 된 배경 UIView를 고해상도 .png로 PhotoLibrary에 저장할 수 있습니다. 여기 새로 조정 된 이미지를 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! 나는 그것을 얻었고, 또 다른 Subview를 만들었고, 내 viewView의 자식 뷰를 만든 다음 새로 생성 된 뷰를 콘센트에 지정하고 코드를 다음과 같이 변경했다.

@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) 
} 

새로운보기는 captureView입니다.

이제는 작동하지만 쓰레기처럼 보입니다. 그것은 매우 낮은 해상도입니다. 이 스냅 샷을 가져와 장치의 해상도로 가져 오는 방법을 알아야합니다.

관련 문제