0

I found a source code about view screenshot. I changed it a little and tried. But this code has a little problem. Screenshot resolution is really bad. I need a good resolution screenshot. I tried to add a comment, but I'm new on stackoverflow. Anyway, what can I do for this ?

Link : Screenshot in swift iOS?

My code :

func textViewSS() {
    //Create the UIImage
    UIGraphicsBeginImageContext(textView.frame.size)
    textView.layer.renderInContext(UIGraphicsGetCurrentContext())
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    //Save it to the camera roll
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}

Sample Result : http://i60.tinypic.com/s4wdn4.png

Community
  • 1
  • 1
jorjj
  • 85
  • 2
  • 12

1 Answers1

0

Trying modifying the first line in your code to pass the scale if you are not satisfied with the resolution

UIGraphicsBeginImageContextWithOptions(textView.frame.size, false, UIScreen.mainScreen().scale)

I don't know the requirement in your case but drawViewHierarchyInRect is quicker/cheaper than renderInContext. You may want to consider that if it is applicable.

Subbu
  • 2,138
  • 14
  • 20
  • Oh that worked ! Thanks. Well, Is this make the screenshot size big ? – jorjj Jul 06 '15 at 21:05
  • Glad it worked :). Yes it would make the size big.. you can try playing around with number values 1,1.5 etc to see if a satisfactory resolution with lesser size.. [Don't forget to accept the answer ;-)] – Subbu Jul 06 '15 at 23:32
  • ok, got it. I have a new question then :) I created a small textview. I want to put a write range limit. How can I do ? – jorjj Jul 06 '15 at 23:39
  • This works well ! :) But I need for textview size limit. When the text out of textview and scroll comes up, then stop. This code just gives me char limit. Right ? – jorjj Jul 07 '15 at 00:06