Search Unity

Get and Display Image form iPhone

Discussion in 'iOS and tvOS' started by murali.vvn, Oct 21, 2010.

  1. murali.vvn

    murali.vvn

    Joined:
    Jun 28, 2010
    Posts:
    53
    I have a requirement that I need to save image in my game and display it at run time. I should do this in Xcode it self. As of now I am able to get the image and saving it in photos app, But I want to save it in my game it self and I have to display it. Please help me any one know about this.


    code to save image to photos folder.
    Code (csharp):
    1.  
    2.  
    3. -(void)save{
    4.    //before going to use this you should have a image in img variable
    5.     UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), self);
    6.  
    7. }
    8.  
    9. - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
    10.  
    11.                         NSString *str = @"Saved!!!";
    12.  
    13.                         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved." message:str delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    14.  
    15.                         [alert show];
    16.  
    17. }
    18.  
     
  2. murali.vvn

    murali.vvn

    Joined:
    Jun 28, 2010
    Posts:
    53
    I tried like this still I am not getting, I am trying very hard for this plz any one help me..

    Code (csharp):
    1.  
    2.  
    3.  
    4. function OnGUI(){
    5.    
    6.     if(GUI.Button(Rect(0,200,100,100),"ChangeTecture")){   
    7.         ChangeTexture();
    8.     }
    9. }
    10.  
    11. function GetiPhoneDocumentsPath ()
    12.         {
    13.                 // Your game has read+write access to /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents
    14.                 // Application.dataPath returns              
    15.                 // /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data
    16.                 // Strip "/Data" from path
    17.                 var path = Application.dataPath.Substring (0, Application.dataPath.Length - 5);
    18.                 // Strip application name
    19.                 path = path.Substring(0, path.LastIndexOf("/"));  
    20.                 return path + "/Documents/IMG_0155.JPG";
    21.         }
    22.        
    23.         function ChangeTexture(){
    24.     var www : WWW = new  WWW ("GetiPhoneDocumentsPath()");
    25.  
    26.     // Wait for download to complete
    27.     yield www;
    28.  
    29.     // assign texture
    30.     renderer.material.mainTexture = www.texture;       
    31.    
    32. }
    33.        
    34.  
    In Xcode

    Code (csharp):
    1.  
    2.  
    3. NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(img)];
    4. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    5. NSString *documentsDirectory = [paths objectAtIndex:0];
    6.  
    7. NSString *filePath = [[NSBundle mainBundle] resourcePath];
    8.  
    9.     if (!documentsDirectory) {
    10.         NSLog(@"Documents directory not found!");
    11.     }
    12.  
    13. [imageData writeToFile:documentsDirectory atomically:YES];
    14.  
    15.  
     
  3. murali.vvn

    murali.vvn

    Joined:
    Jun 28, 2010
    Posts:
    53
    Please any one help me I am waiting here for the reply........
     
  4. murali.vvn

    murali.vvn

    Joined:
    Jun 28, 2010
    Posts:
    53
    [SOLVED]

    Finally after a lot of trouble I solved my problem. I wonder, I didn't get any help form the forum......
     
  5. Dhruvil

    Dhruvil

    Joined:
    Aug 10, 2011
    Posts:
    3
    Can you please post your solution?
    I had same trouble..
    Please,


    Thanx in advance.
    :)