Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jassie303 · Jul 31, 2012 at 10:26 AM · iosscreenshot

Problem with saving screenshot

Hi guys,there is a problem when i saving a screenshot. when i set unity qualitysetting to good level,it can get the shot,but set to fantastic level cannot. please help me out. Here's my code.

 - (UIImage*)snapshot:(UIView*)eaglview{
 
 GLint backingWidth1, backingHeight1;
 // Bind the color renderbuffer used to render the OpenGL ES view
 // If your application only creates a single color renderbuffer which is already bound at this point, 
 // this call is redundant, but it is needed if you're dealing with multiple renderbuffers.
 // Note, replace "_colorRenderbuffer" with the actual name of the renderbuffer object defined in your class.
 glBindRenderbufferOES(GL_RENDERBUFFER_OES, _surface.renderbuffer);
 // Get the size of the backing CAEAGLLayer
 glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth1);
 glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight1);
 //
 NSInteger x = 0, y = 0, width = backingWidth1, height = backingHeight1;
 NSInteger dataLength = width * height * 4;
 GLubyte *data = (GLubyte*)malloc(dataLength * sizeof(GLubyte));
 // Read pixel data from the framebuffer
 glPixelStorei(GL_PACK_ALIGNMENT, 4);
 glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
 // Create a CGImage with the pixel data
 // If your OpenGL ES content is opaque, use kCGImageAlphaNoneSkipLast to ignore the alpha channel
 // otherwise, use kCGImageAlphaPremultipliedLast
 CGDataProviderRef ref = CGDataProviderCreateWithData(NULL, data, dataLength, NULL);
 CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
 CGImageRef iref = CGImageCreate(width, height, 8, 32, width * 4, colorspace, kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast,
                                 ref, NULL, true, kCGRenderingIntentDefault);
 
 // OpenGL ES measures data in PIXELS
 // Create a graphics context with the target size measured in POINTS
 NSInteger widthInPoints, heightInPoints;
 if (NULL != UIGraphicsBeginImageContextWithOptions) {
     // On iOS 4 and later, use UIGraphicsBeginImageContextWithOptions to take the scale into consideration
     // Set the scale parameter to your OpenGL ES view's contentScaleFactor
     // so that you get a high-resolution snapshot when its value is greater than 1.0
     CGFloat scale = eaglview.contentScaleFactor;
     widthInPoints = width / scale;
     heightInPoints = height / scale;
     UIGraphicsBeginImageContextWithOptions(CGSizeMake(widthInPoints, heightInPoints), NO, scale);
 }
 else {
     // On iOS prior to 4, fall back to use UIGraphicsBeginImageContext
     widthInPoints = width;
     heightInPoints = height;
     UIGraphicsBeginImageContext(CGSizeMake(widthInPoints, heightInPoints));
 }
 
 CGContextRef cgcontext = UIGraphicsGetCurrentContext();
 // UIKit coordinate system is upside down to GL/Quartz coordinate system
 // Flip the CGImage by rendering it to the flipped bitmap context
 // The size of the destination area is measured in POINTS
 CGContextSetBlendMode(cgcontext, kCGBlendModeCopy);
 CGContextDrawImage(cgcontext, CGRectMake(0.0, 0.0, widthInPoints, heightInPoints), iref);
 // Retrieve the UIImage from the current context
 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 // Clean up
 free(data);
 CFRelease(ref);
 CFRelease(colorspace);
 CGImageRelease(iref);
 return image;

}

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jassie303 · Aug 01, 2012 at 02:11 AM 0
Share

Solved! Turn off anti aliasing and get snapshot,then turn on anti aliasing.

avatar image jassie303 · Aug 01, 2012 at 02:12 AM 0
Share

Any better idear?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does Application.CaptureScreenshot leak memory? (iOS) 0 Answers

Is it possible to trigger the iPad screenshot functionality from an application without button combination? 0 Answers

Screenshot on iOS and Android not working 1 Answer

how can i take a screenshot (by UiButton) and save it in CameraRoll (Gallery in iOS)? 0 Answers

Javascript command for taking a screenshot then saving it to a folder directory?? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges