Open alfonsotesauro opened 11 months ago
I have replaced Ejecta's original OpenGLES implemention with MetalANGLE. Here is the code that takes a screenshot from MGLKView in Ejecta . Not precisely what you want.
EJCanvasContext *screenCanvasContext = scriptView.screenRenderingContext;
EJCanvasContextWebGLScreen *screenWebGLCanvasContext = (EJCanvasContextWebGLScreen*)screenCanvasContext;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(CGRectGetWidth(screenWebGLCanvasContext.view.frame), CGRectGetHeight(screenWebGLCanvasContext.view.frame)), YES, 0.0);
[screenWebGLCanvasContext.view drawViewHierarchyInRect:screenWebGLCanvasContext.view.bounds afterScreenUpdates:NO];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if(image) {
NSData *raw = UIImagePNGRepresentation(image);
}
Hello, thanks to everybody for the attention. I develop a iOS application that uses a SDK that uses the MetalAngle framework. I need to capture the color of pixels on the frontmost view in my app. For standard UIViewControllers, I use simply:
(UIColor *) GetCurrentPixelColorAtPoint:(CGPoint)point { unsigned char pixel[4] = {0};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast);
CGContextTranslateCTM(context, -point.x, -point.y);
[self.view.layer renderInContext:context];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
NSLog(@"pixel: %d %d %d %d", pixel[0], pixel[1], pixel[2], pixel[3]);
UIColor *color = [UIColor colorWithRed:pixel[0]/255.0 green:pixel[1]/255.0 blue:pixel[2]/255.0 alpha:pixel[3]/255.0];
return color; }
If I try to make the same on my MGLKView I always get a clearColor, regardless of the appearance of the view. I know that point is not transparent, so there must be something weird going on. for MGLKView, I simply do the same:
(UIColor *) GetCurrentPixelColorAtPoint:(CGPoint)point { unsigned char pixel[4] = {0};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(pixel, 1, 1, 8, 4, colorSpace, kCGBitmapAlphaInfoMask & kCGImageAlphaPremultipliedLast);
CGContextTranslateCTM(context, -point.x, -point.y);
[self.glView.glLayer renderInContext:context];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
NSLog(@"pixel: %d %d %d %d", pixel[0], pixel[1], pixel[2], pixel[3]);
UIColor *color = [UIColor colorWithRed:pixel[0]/255.0 green:pixel[1]/255.0 blue:pixel[2]/255.0 alpha:pixel[3]/255.0];
return color; }
So the question is, if you don't want to read the code, how to take a UIImage or a UIColor of a pixel of a MGLKView on iOS ?
Thanks to everybody and sorry for the long message.