what i am trying to do is save a URL to one of the photo library pictures. then use this URL to set the image on a CCSprite.
this is the URL being saved as a NSString :
[_currentTarget setObject:[[NSString alloc]initWithString:[[info objectForKey:#"UIImagePickerControllerReferenceURL"]absoluteString]] forKey:#"image1Name"];
Then set the a property of a Target object i made
NSString *image1PathName = [[listOfUserMadeTargets objectAtIndex:num]objectForKey:#"image1Name"];
self.normalImage = image1PathName;
this is when the CCSprite is made
Target *target = [[Target alloc] targetThatIsUserMade];
[_targets addObject:target]; // add it to the array
target.position = ccp(spawnX,spawnY);
target.scale = -0.001875 * target.position.y + 1.09375;
[self addChild:target z:1];
UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:target.normalImage]]];
[target setTexture:[[CCTextureCache sharedTextureCache] addCGImage:image.CGImage forKey:#"key" ]];
The problem im having is that the Target is there, but the image is not
I have done this many different ways with no luck
thank you for any help
This is a post (and answer) I made which shows you how to save the NSURL for a UIImage in the CameraRoll, and use it later to get the image back, using a UIImagePickerController. This sample code should also help you in how to access the image. Hope that Helps!
Related
i have one gif image file having 4 images , i like to display these images in UIImage view one by one line image.animation . please guide is it possible to display or shoul i use alternat tell me .
thank you .
FLAnimatedImage is a performant open source animated GIF engine for iOS:
Plays multiple GIFs simultaneously with a playback speed comparable
to desktop browsers
Honors variable frame delays
Behaves gracefully under memory pressure
Eliminates delays or blocking during the first playback loop
Interprets the frame delays of fast GIFs the same way modern browsers do
It's a well-tested component that I wrote to power all GIFs in Flipboard.
it will help you , for gif link..https://github.com/mayoff/uiimage-from-animated-gif more help please feel free to ask
yes it possible in iOS,here i enclosed one URL below.please refer this for your concept,even i did it with help of this link.
https://github.com/mayoff/uiimage-from-animated-gif
hope i held you.
Try like this...
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSBundle mainBundle] URLForResource:#"loading" withExtension:#"gif"];
UIImage *loadingImage = [UIImage animatedImageWithAnimatedGIFData:[NSData dataWithContentsOfURL:url]];
self.dataImageView.animationImages = loadingImage.images;
self.dataImageView.animationDuration = loadingImage.duration;
self.dataImageView.animationRepeatCount = 1;
self.dataImageView.image = loadingImage.images.lastObject;
[self.dataImageView startAnimating];
}
First of all you can add those 4 images in one Plist and do the following code. I hope it will work
NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"PhotesArray" ofType:#"plist"]];
NSArray *imageNames = [picturesDictionary objectForKey:#"Photos"];
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i=0; i<[imageNames count]; i++) {
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}
//Normal animation
self.dataImageView.animationImages = images;
self.dataImageView.animationDuration = 3.0;
[self.dataImageView startAnimating];
I am using SDWebImage for loading a list of images and it was really good but while loading images next time it's loading image from cache if the url is same. But I need to know its coming form cache or web. Any help would be greatly appreciated.
Check SDWebImageManager, it has 2 versions of functions to check whether an URL is already cached or not:
- (BOOL)diskImageExistsForURL:(NSURL *)url;
There's also a version with a block which executes after the check. Hope this helps!
You can check the cache to see if the image in question has already been downloaded like so:
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:URL];
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
use your url
SDWebImageManager *manager = [SDWebImageManager sharedManager];
UIImage *cachedImage = [manager imageWithURL:url];
if (cachedImage)
{
[button setImage:cachedImage];
//image is cashed
}
else
{
[manager downloadWithURL:url delegate:self];
}
and then implement delegate function
- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage*)image {
[button setImage:image];
// new image
}
i have this scroll view, that I'm loading into him few images from URL.
the problem is that the scroll view don't show any of them until that all loaded.
i want to show every image the moment i finished loading her.
my code looks like this:
-(void)loadPhotosToLeftscroll{
for (int count = 0 ; count < [leftPhotoArray count]; count++) {
NSLog(#"nextPhotoHight: %f",nextLeftPhotoHight);
NSMutableDictionary *photoDict;
photoDict = [leftPhotoArray objectAtIndex:count];
float photoHight = [[photoDict objectForKey:#"photos_height"]floatValue];
float photoWide= [[photoDict objectForKey:#"photos_width"]floatValue];
NSString *photoPath = [photoDict objectForKey:#"photos_path"];
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:photoPath]];
UIImage *image = [[UIImage alloc] initWithData:imageData];
UIImageView *photoView = [[UIImageView alloc]initWithFrame:CGRectMake(10 , nextLeftPhotoHight, photoWide, photoHight )];
[photoView setImage:image];
[photoView.layer setMasksToBounds:YES];
[photoView.layer setCornerRadius:6];
nextLeftPhotoHight = photoView.frame.size.height + photoView.frame.origin.y + 10;
[leftBlockScroll addSubview:photoView];
}
}
You better use a asynchronous way to do that.
Relative topic is NSURLConnection, UIImageView.
I have done something similar before.
1. Create a new model inherit to UIView
2. This model will have a UIImageView, NSData
3. When u init the model, pass in a URL
4. Use NSURLConnection to send out AsynchroizedRequest
5. By using NSURLConnection delegate, you will finally get the Data of the image
6. Init a UIImage with these data
7. Init The UIImageView with this Image
8. Add this imageview to this model or directly pointing this model to the imageview
Feel free to ask for more detail :)
I have a list of images retrieve from .xml file and these images are images link from the server e.g. " www.seeimage.com/rice.png"
I am parsing the images everytime I went to that page
-(void)viewdidload{
for (int i = 0; i<[appDelegate.foodItems count];i++) {
NSURL *ZensaiimageSmallURL = [NSURL URLWithString:ZensaiPLUitems.ZensaiimageSmallURL];
NSString *string = [[NSString alloc] initWithFormat:#"%#", ZensaiimageSmallURL];
NSData *simageData = [NSData dataWithContentsOfURL:ZensaiimageSmallURL];
UIImage *itemSmallimage = [UIImage imageWithData:simageData];
[zenbutton2 setImage:itemSmallimage forState:UIControlStateNormal];
[scrollView addSubview:zenbutton2];
}
}
i have been trying out on this tutorial : http://www.iphonedevsdk.com/forum/iphone-sdk-tutorials/13315-image-caching-tutorial.html
but i have no idea on how to implement this in my work.
any idea on how to cache them on the first run and whenever i return to that view ?
i don't want to rerun this method to retrive the images from the website everytime i come to this view.
it takes quite some time to init the images from the website to my UIButton before populating them to the scrollview.
if you do not want to retrieve the images from the website every time then you can download it once and store them e.g. into NSMutableDictionary . And access it whenever you want.
OR
Parse those images in separate thread so that your table view or scroll view will not get paused.
How may I modify, read in an image path from SQLite DB, & display it via an UIImageView? In other words, this application will work in offline mode & i have the images at hand. How will i go about this then, tgt with sqlite? (retrieve images by storing their image path name # sqlite)
Sample code I have for now:
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (SQLAppDelegate *)[[UIApplication sharedApplication] delegate];
//start with index 0
currentStepIndex = 0;
Resolution *resolutionObj = [appDelegate.resolutionArray objectAtIndex:currentStepIndex];
[resolutionDescription setText:resolutionObj.stepDescription];
//checking for null string
//replicate of ifelse #goToNextStep & #goToLastStep (needed for initial load of image)
if (resolutionObj.imageDescription != NULL)
{
//if goes in here, then image description is not null
NSURL *imageURL = [NSURL URLWithString:resolutionObj.imageDescription];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
[resolutionImage setImage:[UIImage imageWithData:imageData]];
}
else
{
//if goes in here, then image description is NULL
//show empty image
[resolutionImage setImage:NULL];
}
}
You are missing a lot the way I see it. If your images are coming from a website then you should use a webView to display it. If you are planning to display images in UIImageView, you should first download them onto your device from the url that points to that image and save it in the sandbox. Then you store the path of this downloaded image in your sqlitedb. Now when you want to load this image you just access this image using the path that you have in your sqlitedb and render it. How do you think by just saving the imageName image013.png and not downloading the image itself will render the image for you in UIImageView. Just think where your UIImageView will go and find this image if it's not already downloaded onto your device. For going and finding on the web directly, you need a UIWebView and not an UIImageView
If you are packaging your images as resources with your app binary, you can load them as shown below:
UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:#"myimagefile" ofType:#"png"]];
[self.testView.imgView setImage:img];
where myimagefile is the name of your file and ofType is the type of image. .png or .jpg or whatever.
If you have anymore doubts. Please come back.