iphone - Writing orignal image with exif to Document Directory folder from ALAsset object -
i want save alasset imagearray directly document directory exif tried png conversion, jpeg conversion nothing worked creating new image either jpg or png (loss of exif)
i have seen time save nsdata directly folder preserve exif dont know how
i getting metadata alasset object result
nsdictionary *metadata = [[result defaultrepresentation] metadata];
another assets array list of images
alassetsgroupenumerationresultsblock assetenumerator = ^(alasset *result, nsuinteger index, bool *stop) { if(result != null) { [assets addobject:result]; ; nslog(@"assets %i",[assets count]); self.progressview.progress = (float)index / ([assets count]-1); }
saving images document directory folder
-(void)saveimagestodocumentdirectory{ nslog(@"assets count %i",[assets count]); for(int i=0;i<[assets count];i++) { currentimage = [uiimage imagewithcgimage:[[[assets objectatindex:i] defaultrepresentation] fullresolutionimage]]; [self saveimage:currentimage withimagename:[nsstring stringwithformat:@"images %d",i]]; } } - (void)saveimage:(uiimage*)image withimagename:(nsstring*)imagename { nsdata *imagedata = uiimagepngrepresentation(image); //convert image .png format. // nsdata *imagedata = uiimagejpegrepresentation(image,1.0); nsfilemanager *filemanager = [nsfilemanager defaultmanager];//create instance of nsfilemanager nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); //create array , store result of our search documents directory in nsstring *documentsdirectory = [paths objectatindex:0]; //create nsstring object, holds our exact path documents directory nsstring *datapath = [documentsdirectory stringbyappendingpathcomponent:@"myfolder"]; nsstring *fullpath = [datapath stringbyappendingpathcomponent:[nsstring stringwithformat:@"%@.png", imagename]]; //add our image path [filemanager createfileatpath:fullpath contents:imagedata attributes:nil]; //finally save path (image) nslog(@"image saved"); }
this method able write images in document directory folder exif remain intact, hope other users
-(void)writingoutimage{ nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; // documents folder nsstring *documentdatapath = [documentsdirectory stringbyappendingpathcomponent:@"myfolder"]; nslog(@"documentdatapath %@",documentdatapath); (int j=0; j<[assets count]; j++) { alassetrepresentation *representation = [[assets objectatindex:j] defaultrepresentation]; nsstring* filename = [documentdatapath stringbyappendingpathcomponent:[representation filename]]; [[nsfilemanager defaultmanager] createfileatpath:filename contents:nil attributes:nil]; nsoutputstream *outputstream = [nsoutputstream outputstreamtofileatpath:filename append:yes]; [outputstream open]; long long offset = 0; long long bytesread = 0; nserror *error; uint8_t * buffer = malloc(131072); while (offset<[representation size] && [outputstream hasspaceavailable]) { bytesread = [representation getbytes:buffer fromoffset:offset length:131072 error:&error]; [outputstream write:buffer maxlength:bytesread]; offset = offset+bytesread; } [outputstream close]; free(buffer); } }
Comments
Post a Comment