2012-11-07 59 views
0

如何將3D轉換圖像保存到相冊上?我正在使用CATransform3DRotate更改轉換。我無法保存圖像。圖像保存代碼。如何在執行3D變換後將圖像保存到相冊中?

UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil); 

是否可以保存3D轉換圖像?請幫助我。提前感謝。

+0

看到此鏈接http://parasjoshi3.blogspot.in/2012/05/save-image-in-library-with-only-in-one.html –

+0

請參閱這個鏈接這個我的問題http://stackoverflow.com/questions/12421850/how-merge-the-perspective-of-the-image-on-the-background-image-view – Mani

回答

0
-(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); 
} 

另請參閱完整教程以保存openGL在photoAlbum中的圖像從this link

,也看到我的博客這個帖子.. captureimagescreenshot-of-view

2。還使用ALAssetsLibrary保存圖像

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]; 
+0

謝謝帕拉斯喬希。此代碼僅支持3D變換圖像不支持的2D變換。 – Mani

+0

@Mani,看我編輯的答案..可能是你得到一些想法或解決你的問題..我希望如此.. :) –

+0

謝謝。我沒有使用OPenGL。我會試試這個。你有任何想法使用coregraphics來解決這個問題。 – Mani

0
UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo); 

如果你想在圖像保存完成時得到通知,你只需要completionTarget,completionSelector和contextInfo,否則你可以傳入nil。

OK,然後嘗試這樣的..

UIGraphicsBeginImageContext(YOUR_VIEW.frame.size); 
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 

它會捕捉你的觀點像截圖並保存到相冊

  • YOUR_VIEW = PAAS您編輯圖像的上海華..
+0

完美的圖像保存。我的問題是3D轉換圖像。請參閱rhis鏈接這是我的問題http://stackoverflow.com/questions/12421850/how-merge-the-perspective-of-the-image-on-the-background-image-view – Mani

+0

您是否清除我的問題? – Mani

+0

我已編輯ans現在嘗試 –

相關問題