iPhone에서 OpenGL ES에 문제가 있습니다.iPhone에서 OpenGL ES 컨텍스트에서 투명한 이미지를 얻는 방법
나는 프로젝트에서 일하고 있는데,보기에 무언가를 그리고 나서 이미지를 저장한다. 또한 배경 이미지도 있습니다. 뷰와 배경 이미지에서 이미지를 결합했습니다.
뷰의 불투명 속성을 NO로 설정했지만 뷰에서 이미지가 여전히 불투명 해집니다. 그래서 저는 두 이미지를 결합 할 수 없었습니다. 나는 단지 앞면 이미지 만 볼 수 있었고 배경 이미지는 어디에도 없었다. 이 같은
CAEAGLLayer *EAGLLayer = (CAEAGLLayer *)self.layer;
EAGLLayer.opaque = NO;
가져 오기 이미지 코드 :
- (UIImage *)GetImage
{
CGFloat Width = self.frame.size.width;
CGFloat Height = self.frame.size.height;
GLubyte *TmpBuffer = (GLubyte *)malloc(Width * Height * 4);
glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, TmpBuffer);
GLubyte *Buffer = (GLubyte *)malloc(Width * Height * 4);
for(int y=0; y<Height; y++) {
for(int x=0; x<Width * 4; x++) {
Buffer[((NSInteger)Height - 1 - y) * (NSInteger)Width * 4 + x] = TmpBuffer[y * 4 * (NSInteger)Width + x];
}
}
CGDataProviderRef Provider = CGDataProviderCreateWithData(NULL, Buffer, Width * Height * 4, NULL);
int BitsPerComponent = 8;
int BitsPerPixel = 32;
int BytesPerRow = 4 * 480;
CGColorSpaceRef ColorSpaceRef = CGColorSpaceCreateDeviceRGB();
CGBitmapInfo BitmapInfo = kCGBitmapByteOrderDefault;
CGColorRenderingIntent RenderingIntent = kCGRenderingIntentDefault;
// Make the cgimage.
CGImageRef ImageRef = CGImageCreate(480, 320,
BitsPerComponent,
BitsPerPixel,
BytesPerRow,
ColorSpaceRef,
BitmapInfo,
Provider,
NULL, NO,
RenderingIntent);
return [UIImage imageWithCGImage:ImageRef];
}
이 같은 코드를 결합 :
- (void)Combine:(UIImage *)Back
{
UIGraphicsBeginImageContext(self.frame.size);
CGContextRef aContext = UIGraphicsGetCurrentContext();
CGContextSaveGState(aContext);
CGContextScaleCTM(aContext, 1.0, -1.0);
CGContextTranslateCTM(aContext, 0, -self.frame.size.height);
UIImage *Front = [self GetImage];
CGContextDrawImage(aContext,
CGRectMake(0, 0, self.frame.size.width, self.frame.size.height),
Back.CGImage);
CGContextDrawImage(aContext,
CGRectMake(0, 0, self.frame.size.width, self.frame.size.height),
Front.CGImage);
CGContextRestoreGState(aContext);
UIImageWriteToSavedPhotosAlbum(UIGraphicsGetImageFromCurrentImageContext(), nil, nil, nil);
UIGraphicsEndImageContext();
}
어떻게해야합니까? 어떤 제안이라도 기뻐할 것입니다. 미리 감사드립니다.
그것이 iOS6의와 함께 일하고있다? – GameLoading