iPhone application cannot load images from an album - iphone

I have developed a small iPhone application in which a user can choose images from an image picker and that image will appear in a View. When the user first selects an image I have saved the image name to a database and I save that image to a resource folder with that name. When the main view appears I search for images from the resource folder and display that image in the main view.
When I run this application in the iPhone Simulator it successfully runs, but when I actually tried it for testing purposes on my iPhone I am not able to display images in the main view. Anyone have an idea what's wrong with that?

Hi shivang,
I think you are saving the image to NSDocumentDirectory on a first click and trying to reload that.
while retriving the files from the NSDocumentDirectory you better
first check it for the file type like jpg,png,mp3 then give the
exact name to retrive that.
NSDocumentDirectory creates unique memory for every app and its
limited,check for the size of the images u r saving.
better try this code
for (NSString* fileName in [fileManager contentsOfDirectoryAtPath:myfilepath error:nil])
{
if ( [fileName rangeOfString:#".jpg"].location != NSNotFound )
{
// Here fileName is used as a temporary variable to retrive image name
// myfilepath is the path where u stored the images
}
}

Related

How to get path of images with IOS 16 image picker SwiftUI

Good day,
How do I get the path of images from the ios 16 Photos Picker(PhotosUI Library) as I am trying to store the path in a json file to retrieve later to display
I have a form with a image picker and I want to store the path in json file and then later retrieve the path from the json file to show the image on another view.
There are no images and no paths. The photo library is a database.
You can get the photo asset's identifier if you have permissions, and then you can use that elsewhere to fetch the same photo from the database.

ios: cache images in the application folder

I am working on an Iphone application.
The idea of the application is to allow the user to download a picture and to save it on his phone. and he can later open it. (Normal caching system)
What I am doing now is I get the UIIamge from the server and then I save it on the phone using:
UIImageWriteToSavedPhotosAlbum
And then I use the imagePickerController to allow the user to load the image.
My question is:
Is there a way I can save the image in the application folder? The idea is that I don't want to allow the user to delete the image from outside the application(I have a "clear images" button). Is there a place I can cache the images other than the Photo library? maybe in the application bundle or folder?
Thank you
Use either of the following methods to save the UIImage into your app's document directory
[UIImageJPEGRepresentation(image, JPEG_COMPRESSION_QUALITY)
writeToFile:photoPath atomically:YES];
or
[UIImagePNGRepresentation(image) writeToFile:photoPath atomically:YES];

SDWebImage: Prevent to many server request

I'm using SDWebImage framework to download profile images in my iPhone game.
[cell.playerImage setImageWithURL:url placeholderImage: DefaultImage];
This works great, but I'm worried about the server performance. Each time the tableView is reloaded, all the cell will call the the code above to try to get the image. And the tableView is realoaded quite often.
Since most player don't have a profile image, the DefaultImage will be set, but I still want to check from time to time if the opponent player has uploaded a profileImage, so I can get it, but not in each and every tableView reload.
How would you go about doing this?
Thanks in advance
Save player image in document Directory first time when it requests for image from server with names playername.png or playerID.png (varies what unique u want for that).
In SDWebImage setImageWithURL's method add this logic:
if([[NSFileManager defaultManager] fileExistsAtPath:#"Your Player Image Path"])
{
// set image from local Path
}
else
{
//request from server
// save image in document Directory and then set that image
}

Save iPhone Photo Library Path to a Plist

I want to save an image path string for a particular photo from the main iphone photo library in a plist file.
So that later I can call the plist image path string in a web view and see the photo.
I know I need the absolute path which is probably a similar path to the documents directory but:
1.) How do I get the photo name of the particular photo?
2.) Do I need to append the absolute path string to the photo name and then write to the plist?
3.) Will the path change for every install of my app - which would make a hard coded absolute path impossible to use?
Any pros want to tackle this conundrum?
If you are building an app targeting lower than iOS4.0, then you may use UIImagePickerController Class. This will let user pick one image from the phone album, which then, you can save in your app's documents directory and save the corresponding link in the info.plist file. The documents directory gets deleted when your app gets uninstalled, and so you lose the path as well.
A better way, with a disadvantage of restricting this feature (and so your app if its a main feature) to only iOS4.0 and above, would be using ALAssetsLibrary. Each photo in the iphone is represented by a unique URL that you can save, and you can refer to a particular image using that url. There is a nice tutorial blog that can help you get started with it.
Now, in your question, you are talking about a particular photo. You can not just know of any particular photo in the library, unless you let the user pick one. This brings me to answer your last question. The URL is constant for that particular image (till the iphone is reset), but unless you have any way of keeping that information between every install of your app (what exactly do mean here?), I don't know how being a unique URL is going to help you here.
EDIT:
Just saw the tag of sdk 4.0 there, please ignore the first case (the <4.0 part).
OK I think I want to use the UIImagePickerController!
Here is my code:
- (void)viewDidLoad {
self.iconPicker = [[UIImagePickerController alloc] init];
self.iconPicker.allowsEditing = YES;
self.iconPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
self.iconPicker.delegate = self;
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
iconImage.image = [info objectForKey:UIImagePickerControllerEditedImage];
[picker dismissModalViewControllerAnimated:YES];
[picker release];
}
- (IBAction)save {
[plist.data setValue:iconImage.image forKey:#"Icon"];
[plist.data writeToFile:plist.file atomically:YES];
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
How do I save the image name of the edited image in plist string.
I know I don't want to save the CGImage data or whatever because of the load size.
I think I can pass an xcode variable into HTML through putting all my HTML into string objects and then adding variables to the objects where I need includes...
So I can create a path to the photo directory but I need to know how to get the name of the saved edited image from UIImagePickerController???

How do i get the image name of a image in imageView?

Hi i want to upload the image to HTTP server, image upload is working fine but every time the image in the server is replaced with the new image. Can some one help me to implement the commented lines below.
Thanks...
- (IBAction)upload{
//NSString *imagename=imageview.image;
//[self uploadImage:UIImageJPEGRepresentation(imageview.image, 1.0) filename:imagename];
[self uploadImage:UIImageJPEGRepresentation(imageview.image, 1.0) filename:#"facebook.jpg"];
}
To get the image's filename, capture the name during the file picking (but remember, maybe the image in the image view comes directly from the camera).
If the file upload should never overwrite a file already on the server, consider one of the following:
a) generate a unique filename for each upload (preferably in the server code, but if you also control the client, you can do it there too). You could use UUIDs as unique filenames.
OR
b) store the images in a database instead of the filesystem