Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何在执行3D变换后将图像保存在相册上?_Iphone - Fatal编程技术网

Iphone 如何在执行3D变换后将图像保存在相册上?

Iphone 如何在执行3D变换后将图像保存在相册上?,iphone,Iphone,如何在相册上保存3D转换后的图像?我正在使用CATTransformerM3dRotate更改转换。我无法保存图像。图像保存代码 UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil); 是否可以保存3D转换后的图像?请帮帮我,先谢谢你 UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *cont

如何在相册上保存3D转换后的图像?我正在使用
CATTransformerM3dRotate
更改转换。我无法保存图像。图像保存代码

UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
是否可以保存3D转换后的图像?请帮帮我,先谢谢你

UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
如果您希望在图像保存完成时收到通知,则只需要completionTarget、completionSelector和contextInfo,否则可以传递nil

好吧,那就这样试试

UIGraphicsBeginImageContext(YOUR_VIEW.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
它会像截图一样捕获您的视图并保存到相册中

  • YOUR_VIEW=paas编辑图像的superview

完美地保存图像。我的问题是3D转换图像。请看rhis链接这是我的问题,谢谢Irshad Mansuri。已尝试此操作,但不适用于三维变换。还有别的想法吗。请帮助我。查看此链接请查看此链接此问题谢谢。此代码仅支持二维变换,而不支持三维变换的图像。@Mani,请参阅我编辑的答案。。也许你会有一些想法或者解决你的问题。。我希望如此……)非常感谢。我没有使用OPenGL。我试试这个。您是否有使用coregraphics解决此问题的想法。我认为您可以使用此代码获得图像bcoz您使用3d,这里还可以使用imageRef获得每个核心图形上下文,因此请尝试使用此代码,并根据您的要求更改一些代码..]谢谢你,乔希。我试试看。
-(UIImage *) glToUIImage {
    NSInteger myDataLength = 320 * 480 * 4;

    // allocate array and read pixels into it.
    GLubyte *buffer = (GLubyte *) malloc(myDataLength);
    glReadPixels(0, 0, 320, 480, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

    // gl renders "upside down" so swap top to bottom into new array.
    // there's gotta be a better way, but this works.
    GLubyte *buffer2 = (GLubyte *) malloc(myDataLength);
    for(int y = 0; y < 480; y++)
    {
        for(int x = 0; x < 320 * 4; x++)
        {
            buffer2[(479 - y) * 320 * 4 + x] = buffer[y * 4 * 320 + x];
        }
    }

    // make data provider with data.
    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, myDataLength, NULL);

    // prep the ingredients
    int bitsPerComponent = 8;
    int bitsPerPixel = 32;
    int bytesPerRow = 4 * 320;
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

    // make the cgimage
    CGImageRef imageRef = CGImageCreate(320, 480, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);

    // then make the uiimage from that
    UIImage *myImage = [UIImage imageWithCGImage:imageRef];
    return myImage;
}

-(void)captureToPhotoAlbum {
    UIImage *image = [self glToUIImage];
    UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
}
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

    [library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
    if (error) {
    // TODO: error handling
    } else {
    // TODO: success handling
    }
}];
[library release];