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.
-(void)save{
//before going to use this you should have a image in img variable
UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), self);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
NSString *str = @"Saved!!!";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved." message:str delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
I tried like this still I am not getting, I am trying very hard for this plz any one help me…
function OnGUI(){
if(GUI.Button(Rect(0,200,100,100),"ChangeTecture")){
ChangeTexture();
}
}
function GetiPhoneDocumentsPath ()
{
// Your game has read+write access to /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents
// Application.dataPath returns
// /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data
// Strip "/Data" from path
var path = Application.dataPath.Substring (0, Application.dataPath.Length - 5);
// Strip application name
path = path.Substring(0, path.LastIndexOf("/"));
return path + "/Documents/IMG_0155.JPG";
}
function ChangeTexture(){
var www : WWW = new WWW ("GetiPhoneDocumentsPath()");
// Wait for download to complete
yield www;
// assign texture
renderer.material.mainTexture = www.texture;
}
In Xcode
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(img)];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [[NSBundle mainBundle] resourcePath];
if (!documentsDirectory) {
NSLog(@"Documents directory not found!");
}
[imageData writeToFile:documentsDirectory atomically:YES];
Please any one help me I am waiting here for the reply…
[SOLVED]
Finally after a lot of trouble I solved my problem. I wonder, I didn’t get any help form the forum…
Can you please post your solution?
I had same trouble…
Please,
Thanx in advance.
