I am creating app to save images to Photo library from net. now i want to check every time before saving image to PhotoLibrary that image is already there or not?
i fetch the name of images stored in photo library but that name are different than original name so i don't know how to compare current image with already existing images!
please help me!
ALAssetsLibrary *Library=[[ALAssetsLibrary alloc]init];
NSMutableArray *arr_ImagesUrl=[[NSMutableArray alloc]init];
[Library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *Group,BOOL *stop){
[Group enumerateAssetsUsingBlock:^(ALAsset *asset,NSUInteger index,BOOL *stop)
{
NSLog(#"%#",[[asset defaultRepresentation]filename]);
}];
} failureBlock:^(NSError *error){NSLog(#"%#",error.description);}];
Basically theres is no such API in IOS documentation as far as I know.
What you can do, which is not quite the same as you originally wanted, is that in your application store an individual value (*) for every image the user selected throughout the app lifecycle. Based on this array of information you are able to tell whether a new selection is the same as a previous one. But still, you cannot do this for the full PhotoLibrary.
(*) This is an useful thread on SO which about detecting image similarity and/or creating a value (hash) which describes the image and usable for comparing images later.
My favourite is phash.
https://softwareengineering.stackexchange.com/questions/92830/how-to-know-if-two-images-are-the-same
or see this:
Compare two images to check if they are same
Related
I use a custom UICollectionView to display iPhone's photos. I want to reload UICollectionView when app become active after user delete/modify/add one or more photos.
I save PHAsset in a array, [previousAssetsArray isEqual:currentAssetsArray] is not working.
Any idea?
EDIT:
What is the NSObject isEqual: and hash default function?
When I get photos' assets again, its address changed, so previousAsset will not equal to currentAsset even they belong to a photo. [previousAsset isEqual: currentAsset] always NO.
I also use the property hash of PHAsset to check if photos changed. But I found when I just modified(crop) one photo in Photos app, its hash not changed.
try this [previousAssetsArray isEqualToArray:currentAssetsArray]
Example:: BOOL theyAreEqual = [myFirstArray isEqualToArray:mySecondArray];
if you want to compare count of both array
previousAssetsArray.count == currentAssetsArray .count
Apple is encouraging us to use the new PhotosFramework to interact with the camera roll in iOS8. But says nothing about AssetsLibraryFramework not working on iOS8.
So I'm using my pre-existing AssetsLibraryFramework code to do get the list of video ALAssets from the user's camera roll and display it. This works...still.
But when I try to create an album (group) using this AssetsLibraryFramework method:
- (void)addAssetsGroupAlbumWithName:(NSString *)name
resultBlock:(ALAssetsLibraryGroupResultBlock)resultBlock
failureBlock:(ALAssetsLibraryAccessFailureBlock)failureBlock
Where resultBlock looks like this:
typedef void (^ALAssetsLibraryGroupResultBlock)(ALAssetsGroup *group));
The resultBlock is called with a nil group. The docs say that the group will be nil for a name collision, but there's no other album with the specified name. Definitely not a name collision.
I'm trying to determine if this is an error on my part, or evidence that ALAssetsLibrary cannot be trusted on iOS8 and I need to upgrade to PhotosFramework.
Are there other things that could cause the group to be nil? Is this method just not supported on iOS8?
Thanks in advance for any help.
I am VERY new to Xcode and even iOS apps/platform in general. I have a lot of image processing experience using other development platform environments and am looking to apply this toward iOS apps. I have noticed that nothing is mentioned for Xcode in regards to accessing image data and/or directly modifying it. Many people that have made tutorials seem to use an image picker but never have I seen where they say or show how to access the image data.
An answer to this would great. Guidance would be most appreciated. Thanks.
UIImage provides the ability to display images from several different formats, but it's immutable -- you can't change the data it uses and expect to see the image change. Instead, you'll get an image in one of the underlying types and work with that. You'll probably want to read up on both Core Graphics (Quartz) and Core Image. For example, you can use UIImage's -CGImage method to get the image as a CGImage and then use the Core Graphics CGImage...() functions to find out about the image data (format, bit depth, etc) and get the actual bits.
AVAssetLibrary can help you to modify image data.
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc]init];
[assetsLibrary assetForURL:photoUrl resultBlock:resultBlock
failureBlock:nil];
Using above code you will get asset of image in result block.
ALAssetsLibraryAssetForURLResultBlock resultBlock = ^(ALAsset *photoAsset)
{
ALAssetRepresentation *image_representation = [photoAsset defaultRepresentation];
//Do the stuff to get-modify image data from image_representation...
}
Hope this is what you are looking for.
I am developing an iOS app that will have a number of images. These images are associated with Show object and Band objects. I am fairly new to iOS development
On the server, the Shows and Bands are associated with a list of images. Currently I am storing the images with the following info:
height:integer width:integer imageType:string imageData:binary
First question is: should there be more?
Secondly, I am persisting the Show and Band objects using Core Data. I do not want to persist the images because I would quickly run out of memory. I will store them in the cache directory. My second question is: how should the Show and Band objects keep track of the images? Should I have a Image objects in the model with a to many relationship with Shows and Bands. But these Image objects would perhaps only contain height, width, imageType and a path to where the cached image should be. My idea is that if it is not found in the cache directory, it gets the imageData from the server.
What is the right way to do this?
UPDATE
I also plan on pinging the server with HEAD to check if the imageData has been updated before getting the cached version.
you can actually just store the images directly with Core Data and not have to mess with documents at all.
This has been answered in other places but I'll put the code here anyway:
To save:
NSData *imageData = UIImagePNGRepresentation(yourUIImage);
[newManagedObject setValue:imageData forKey:#"image"];
and to load:
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
UIImage *image = [UIImage imageWithData:[selectedObject valueForKey:#"image"]];
[[newCustomer yourImageView] setImage:image];
The way you should model your data depends on what kind of relationship the images will have with bands/shows.
Do shows and bands each relate to multiple images? Can a show have images that are related to multiple bands?
Ultimately you may want to have an Image Core Data entity that will have a one-one or one-many relationship with bands/shows depending on your answers to these questions. You will also want to add the inverse relationship so that for example when you look up a show, you can also access the set of images associated with it.
It might be easier to help you if you provide more detail about the relationships between your objects.
Both writeModifiedImageDataToSavedPhotosAlbum and setImageData methods in ALAsset take both image data (in the form of an NSData object) and metadata (in the form of an NSDictionary object). I've got everything working to inject additional metadata into an ALAsset that's already in the camera roll (obviously written by our app, therefore editable by it), but what I would love to do is to not have to first read the entire image data for the original just to pass it completely unmodified to either of these calls.
Is there any way to modify only the metadata of an ALAsset without paying the memory penalty of reading the entire image data? I've tried passing nil to imageData (despite this not being a documented option) and it did not work.
Berend