I am new to iphone programming. using google code iphone-exif, i can read/write images tags also i can add custom image tags. But, my problem is that how can see the updated data??? OR is there any way to save image with updated data??
I have used .jpg image from net, is in other resources folder.
Here my code (.m file)
NSString *filePath = #"/.../ProjectName/1.jpg";
NSMutableData *imageData = [NSMutableData dataWithContentsOfFile:filePath];
EXFJpeg* jpegScanner = [[EXFJpeg alloc] init];
[jpegScanner scanImageData: imageData];
EXFMetaData* exifData = jpegScanner.exifMetaData;
//EXFJFIF* jfif = jpegScanner.jfif;
[exifData addTagValue: #"Changed MAke" forKey:[NSNumber numberWithInt:EXIF_Make]];
id val2 = [exifData tagValue:[NSNumber numberWithInt:EXIF_Make]];
NSLog(val2);
NSLog([exifData tagValue:[NSNumber numberWithInt:EXIF_Model]]);
NSLog([exifData tagValue:[NSNumber numberWithInt:EXIF_DateTime]]);
// SAVE THE IMAGE WITH THE NEW TAGS
[jpegScanner populateImageData:imageData];
//[imageData writeToFile:filePath atomically:YES];
After saving your new image data:
NSString *filePath = #"/.../ProjectName/1.jpg";
NSMutableData *imageData = [NSMutableData dataWithContentsOfFile:filePath];
EXFJpeg* jpegScanner = [[EXFJpeg alloc] init];
[jpegScanner scanImageData: imageData];
EXFMetaData* exifData = jpegScanner.exifMetaData;
id myValue = [exifData tagValue:[NSNumber numberWithInt:EXIF_Make]];
NSLog(#"My changedValue is: %#", myValue);
[jpegScanner release];
Related
I have some files, -m4a -mp4 -mp3 etc.
I want to change these details
AVMetadataItem
AVMetadataCommonKeyArtwork
AVMetadataCommonKeyArtist
I can do with AVAssetExportSession, But I need to change the directory. Is there a way I can write directly on the file please?
I found this program, but does not work :(
NSError *error;
AVAssetWriter *assetWrtr = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:self.path] fileType:AVFileTypeAppleM4A error:&error];
NSLog(#"%#",error);
NSArray *existingMetadataArray = assetWrtr.metadata;
NSMutableArray *newMetadataArray = nil;
if (existingMetadataArray)
{
newMetadataArray = [existingMetadataArray mutableCopy]; // To prevent overriding of existing metadata
}
else
{
newMetadataArray = [[NSMutableArray alloc] init];
}
AVMutableMetadataItem *item = [[AVMutableMetadataItem alloc] init];
item.keySpace = AVMetadataKeySpaceCommon;
item.key = AVMetadataCommonKeyArtwork;
item.value = UIImagePNGRepresentation([[UIImage alloc] initWithContentsOfFile:[[NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:#".image"]]);
[newMetadataArray addObject:item];
assetWrtr.metadata = newMetadataArray;
[assetWrtr startWriting];
[assetWrtr startSessionAtSourceTime:kCMTimeZero];
change UIImagePNGRepresentation to UIImageJPEGRepresentation you need jpeg data not png.
Am converting a webpage as a pdf file. I did the following,
NSString *string=[NSString stringWithFormat:#"%#.pdf",[chapersArray objectAtIndex:pageIndex]];
[controller1 addAttachmentData:pdfData mimeType:#"application/pdf" fileName:string];
[self presentModalViewController:controller1 animated:YES];
[controller1 release];
Now how can i convert my NSData into pdf and save in my application memory? Kindly help me with sample codes or suggestions. Thanks all.
Am assuming you have your pdf in documents directory here. You can change it to where ever it actually is. Try this -
//to convert pdf to NSData
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:#"test.pdf"];
NSData *myData = [NSData dataWithContentsOfFile:pdfPath];
Essentially using CGPDFDocumentCreateWithProvider you can convert NSData to pdf,
//to convert NSData to pdf
NSData *data = //some nsdata
CFDataRef myPDFData = (CFDataRef)data;
CGDataProviderRef provider = CGDataProviderCreateWithCFData(myPDFData);
CGPDFDocumentRef pdf = CGPDFDocumentCreateWithProvider(provider);
Don't forget to CFRelease all unused data after you are done.
I got this is in a simple method as follows,
-(IBAction)saveasPDF:(id)sender{
NSString *string=[NSString stringWithFormat:#"%#.pdf",[chapersArray objectAtIndex:pageIndex]];
[controller1 addAttachmentData:pdfData mimeType:#"application/pdf" fileName:string];
[self presentModalViewController:controller1 animated:YES];
[pdfData writeToFile:[self getDBPathPDf:string] atomically:YES];
}
-(NSString *) getDBPathPDf:(NSString *)PdfName {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:PdfName];
}
You can try with this solution:
- (void)saveDataToPDF:(NSData *)pdfDocumentData
{
//Create the pdf document reference
CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFDataRef)pdfDocumentData);
CGPDFDocumentRef document = CGPDFDocumentCreateWithProvider(dataProvider);
//Create the pdf context
CGPDFPageRef page = CGPDFDocumentGetPage(document, 1); //Pages are numbered starting at 1
CGRect pageRect = CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
CFMutableDataRef mutableData = CFDataCreateMutable(NULL, 0);
//NSLog(#"w:%2.2f, h:%2.2f",pageRect.size.width, pageRect.size.height);
CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData(mutableData);
CGContextRef pdfContext = CGPDFContextCreate(dataConsumer, &pageRect, NULL);
if (CGPDFDocumentGetNumberOfPages(document) > 0)
{
//Draw the page onto the new context
//page = CGPDFDocumentGetPage(document, 1); //Pages are numbered starting at 1
CGPDFContextBeginPage(pdfContext, NULL);
CGContextDrawPDFPage(pdfContext, page);
CGPDFContextEndPage(pdfContext);
}
else
{
NSLog(#"Failed to create the document");
}
CGContextRelease(pdfContext); //Release before writing data to disk.
//Write to disk
[(__bridge NSData *)mutableData writeToFile:#"/Users/David/Desktop/test.pdf" atomically:YES];
//Clean up
CGDataProviderRelease(dataProvider); //Release the data provider
CGDataConsumerRelease(dataConsumer);
CGPDFDocumentRelease(document);
CFRelease(mutableData);
}
I am trying to upload the image from my iPhone/iPod touch to my online repository, I have successfully picked the image from Photo Album but i am facing one problem i want to know the name of the image such as image1.jpg or some thing like that. How i would know the name of the picked image.
Instead of using the usual image picker method (UIImage*)[info valueForKey:UIImagePickerOriginalImage] which gives you the selected image as an instance of UIImage, you can use the AssetsLibrary.framework and export the actual source file (including format, name and all metadata). This also has the advantage of the original file format (png or jpg) being preserved.
#import <AssetsLibrary/AssetsLibrary.h>
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissPicker];
// try to get media resource (in case of a video)
NSURL *resourceURL = [info objectForKey:UIImagePickerControllerMediaURL];
if(resourceURL) {
// it's a video: handle import
[self doSomethingWith:resourceURL];
} else {
// it's a photo
resourceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
ALAssetsLibrary *assetLibrary = [ALAssetsLibrary new];
[assetLibrary assetForURL:resourceURL
resultBlock:^(ALAsset *asset) {
// get data
ALAssetRepresentation *assetRep = [asset defaultRepresentation];
CGImageRef cgImg = [assetRep fullResolutionImage];
NSString *filename = [assetRep filename];
UIImage *img = [UIImage imageWithCGImage:cgImg];
NSData *data = UIImagePNGRepresentation(img);
NSString *cacheDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSURL *tempFileURL = [NSURL fileURLWithPath:[cacheDir stringByAppendingPathComponent:filename]];
BOOL result = [data writeToFile:tempFileURL.path atomically:YES];
if(result) {
// handle import
[self doSomethingWith:resourceURL];
// remove temp file
result = [[NSFileManager defaultManager] removeItemAtURL:tempFileURL error:nil];
if(!result) { NSLog(#"Error removing temp file %#", tempFileURL); }
}
}
failureBlock:^(NSError *error) {
NSLog(#"%#", error);
}];
return;
}
}
I guess knowing the exact image name would not be an issue rather getting a unique name for the picked image would solve your purpose so that you can upload the image on server and track it via its name. May be this can help you
NSMutableString *imageName = [[[NSMutableString alloc] initWithCapacity:0] autorelease];
CFUUIDRef theUUID = CFUUIDCreate(kCFAllocatorDefault);
if (theUUID) {
[imageName appendString:NSMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, theUUID))];
CFRelease(theUUID);
}
[imageName appendString:#".png"];
After you pick the image from Picker you can generate a unique name and assign it to the Picked image.
Cheers
I am trying to post image on facebook but not successful yet,
my codes are:
- (void)postToWall{
int im = 1;
NSData *myimgData;
myimgData = [NSData dataWithContentsOfFile:saveImagePath];
//pstimg = myimgData;
NSArray *chunks = [pstimg componentsSeparatedByString: #"."];
NSString *atch= [chunks objectAtIndex: 0];
NSString *filePath = [[NSBundle mainBundle] pathForResource:atch ofType:#"jpg"];
img = [[UIImage alloc] initWithContentsOfFile:filePath];
//start
FBDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
NSString *str = #"Hello";
str = [str stringByReplacingOccurrencesOfString:#" " withString:#"+"];
dialog.cMessage=str;
dialog.userMessagePrompt = #"Enter your message:";
[dialog show];
NSData * findata;
//edited from here
if(im==1)
{
findata = myimgData;
}
else
{
findata = (NSData *)img;
}
NSMutableDictionary * param = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
nil];
FBRequest *uploadPhotoRequest =[FBRequest requestWithDelegate:self] ;
[uploadPhotoRequest call:#"facebook.photos.upload" params:param dataParam:myimgData];
[img release];
}
But it not posted.
To post a photo on Facebook you need to use the iOS SDK from Facebook:
https://github.com/facebook/facebook-ios-sdk
There you'll find sample app with authentication and much more, like posting a photo.
my encryption is working but i cant decrypt kindly suggest what i am doing wrong here
NSString *passphrase = #"hello";
NSStringEncoding myEncoding = NSASCIIStringEncoding;
NSString *alphaStringPlain = #"cell";
NSData *alphaDataPlain = [alphaStringPlain dataUsingEncoding:myEncoding];
NSData *alphaDataCypher = [alphaDataPlain AESEncryptWithPassphrase:passphrase];
NSString *alphaStringCypher = [[NSString alloc] initWithData:alphaDataCypher encoding:myEncoding];
NSLog(alphaStringCypher); // perfeclty encypted i guess
/////// FOR DECRYPTION///////////////
NSData *zCypher = [alphaDataPlain AESDecryptWithPassphrase:alphaStringCypher];
NSString *Cypher = [[NSString alloc] initWithData:zCypher encoding:myEncoding];
NSLog(#" decode %#",[Cypher dataUsingEncoding:NSUTF8StringEncoding]);
NSLog(#" decode %#",Cypher);// not working some garbage value
After struggling i got the ans
NSString *passphrase = #"1234567812345678";
NSStringEncoding myEncoding = NSASCIIStringEncoding;
NSString *alphaStringPlain = #"hello";
NSData *alphaDataPlain = [alphaStringPlain dataUsingEncoding:myEncoding];
NSData *alphaDataCypher = [alphaDataPlain AESEncryptWithPassphrase:passphrase];
NSString *alphaStringCypher = [[NSString alloc] initWithData:alphaDataCypher encoding:myEncoding];
NSLog(alphaStringCypher);
///////
NSData *zCypher = [alphaDataCypher AESDecryptWithPassphrase:passphrase];
NSString *Cypher = [[NSString alloc] initWithData:zCypher encoding:myEncoding];
//NSData *zCypher = [alphaStringCypher AESDecryptWithPassphrase:passphrase];
NSLog(#" hua kya decode %#",cypher);// working
I think you are decrypting wrong value
try with this :
NSData *zCypher = [alphaStringCypher AESDecryptWithPassphrase:passphrase];