Save uiimage with custom format - iphone

I want to save an image with ".wai" extension, for send it trough whatsapp.h
ow can I save the image with this format?
The whatsapp site don't have a sample code, for more information this is the link (propbably visiting this link you understand my problem)
http://www.whatsapp.com/faq/en/iphone/23559013

NSData *pngData = UIImagePNGRepresentation(drawimg.image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
filePath = [documentsPath stringByAppendingPathComponent:#"edited.wai"]; //Add the file name
[pngData writeToFile:filePath atomically:YES];

Related

How to get saved image file path in iOS

Hi I am developing an app in which there is an option to pick the photos from iOS photo gallery. I have to upload the selected photos into the server. To upload the images i am using Kaltura SDK so i am in the situation not able to directly send the UIImage to server. i need to send saved image file path.
For that I found an solution, That is saving the selected photos in a particular file path then i will use that file path. But the problem is i do not wish to save photos again in phone memory because those photos are already stored in a particular path.
So Is there any other option to retrive the saved image file path without saving it again?
Try this one:
- (void)saveImage: (UIImage*)image
{
if (image != nil)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
#"test.png" ];
NSData* data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
}
}
- (UIImage*)loadImage
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:
#"test.png" ];
UIImage* image = [UIImage imageWithContentsOfFile:path];
[self sendAction:path];
return image;
}

How to save pdf locally from image view

How to save the pdf locally
I have loaded the pdf doc into imageView. Now i need to save into locally into iPhone device.
Any one advice me how to save the pdf file from image view
#All
Thanks in advance
For saving the pdf in document directory use below code.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:#"data.pdf"];
NSData *thedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:`ADD URL OF PDF DATA`]];
[thedata writeToFile:localFilePath atomically:YES];
For retrieving the pdf use below code.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:#"data.pdf"];
if ( [[NSFileManager defaultManager] fileExistsAtPath:localFilePath] ) {
NSData *data = [NSData dataWithContentsOfFile:localFilePath];
}

iOS Saving Media Picker Selections

I am trying to create an app that saves the user's media selections from a Media Picker to be reused and avoid having to re-pick the items . Is there a way to do this with the Media Picker or any example code for this?
The only way to do this is to save the media selection in the app's sandbox i.e. Documents directory for re-use. Because, you can't access the media without user intervention i.e. you've to present media picker each time whenever you wanna pick something from the gallery. You can use something like this to save an image in app's doc directory:
+(BOOL)saveImageInDocumentsDirectory:(UIImage*)image WithName:(NSString*)name {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:name];
NSData *imageData = UIImagePNGRepresentation(image);
return [imageData writeToFile:savedImagePath atomically:NO];
}
And to retrieve the images:
+(UIImage*)getImageFromDocumentsDirectoryWithName:(NSString*)name {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:name];
return [[[UIImage alloc] initWithContentsOfFile:savedImagePath] autorelease];
}
Hope it'll be helpful.

Adding images into the iPhone application

I have an application where the user should be able to take pictures using camera and save them within the application. By default all the images taken are saved to the photo album.But I want to bring them into my project just like the way we add required images for the project into the Resources folder in Xcode. At the same time I want them to converted into PNG format.
After you have taken image from Camera you can save this image to your application's document directory as,
UIImage *image = imageFromCamera;
NSData *imageData = UIImagePNGRepresentation(image);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fullPathToFile = [documentsDirectory stringByAppendingPathComponent:#"MyImage.png"];
[imageData writeToFile:fullPathToFile atomically:YES];
Its tested code and working absolutely fine.
here is a great tutorial that you should check out http://iosdevelopertips.com/camera/camera-application-to-take-pictures-and-save-images-to-photo-album.html
And here is the documentation from Apple for the UIImagePickerController that you should use https://developer.apple.com/documentation/uikit/uiimagepickercontroller
NSArray *UsrDocPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *DocsDir = [UsrDocPath objectAtIndex:0];
NSString *path = [DocsDir stringByAppendingPathComponent:#"image.jpg"];
//Check if image exists on documents path, if exists removed it, but it depends on your logic, you can add more images in documents path by changing its name...
BOOL success = [FileManager fileExistsAtPath:zipPath];
if(success){
[FileManager removeItemAtPath:path error:&error];
}
[UIImageJPEGRepresentation(image,1.0) writeToFile:path atomically:YES];

saving data in iphone

I am trying to download an image and audio file from the url.. i want to save the downloaded files in specific path is it possible..
please suggest me...
thanks...
save the files in the documents directory of your app.
NSString *documentsDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [documentsDirectoryPath stringByAppendingPathComponent:#"myfile.mp3"];
BOOL success = [myMp3Data writeToFile:path atomically:YES];
Yes, it is possible.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath2 = [NSString stringWithFormat:#"%#/%#.jpg", documentsDirectory, fileName];
NSData* imageData = UIImageJPEGRepresentation(drawImage.image, 1.0);
[imageData writeToFile:filePath2 atomically:NO];