I like to implement image upload functionality in my app.For that I like to give some option for user to choose image.
One of the option is choose image from website.
If the user enter an url link in the text box and click the get images button means. I like to display all the images in that particular link
But I am not having any idea about this.
I have explain my requirement below
1)Enter the url in a text box
2)Click the get images button
3)Parse all the images from that particular url
4)Display all the images in the Imageview
And also to illustrate my requirement I have attached the screenshot below
If anybody work around this functionality means please suggest me some idea
Thanks
Like this ?
- (IBAction)buttonClicked:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://www.yourwebvsite.com/image.png"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData: data];
UIImageView *displayImageView = [[UIImageView alloc] initWithImage:image];
[displayImageView setFrame:CGRectMake(0, 0, 300, 300)];
[displayImageView setContentMode:UIViewContentModeScaleAspectFit];
[self.view addSubview:displayImageView];
}
Or if you want all the images from a web directory. See here and save all the images in an array then display the images in a UIImageView like my code above.
Related
In my first View Controller after a user logs in, there is a quick check to see if the user has uploaded a custom image to his account. (If he has, there's a URL in the user's profile data.)
These images are downloaded correctly in my code and they show up beautifully. The problem comes when there is no custom user image, and the VC tries to set the same UIImageView to a default picture (in xcassets). The picture is being loaded into the bundle, as far as I can tell, and it's a valid PNG file.
Here is the snippet for setting the image. If a custom URL is not found, I set the URL parameter string to "nil."
-(void) setImageWithUrl: (NSString *) Url Imageview: (UIImageView *) image {
if (Url.length > 4) {
NSURL *url = [NSURL URLWithString:Url];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *Profileimage = [UIImage imageWithData:data];
[image setImage:Profileimage];
}
else {
UIImage *Profileimage = [UIImage imageNamed:#"DefaultPicture"];
[image setImage:Profileimage];
}
}
This one's driving me nuts, so all weird ideas are welcome. :-)
Let me know if you want me to post any other parts of the code that you think could be a factor.
It looks like debug-need issue. But why don't you use any image download/cache library, like SDWebImage?
It gonna be much efficient and convenient
I have tried many solutions for this problem before posting but somehow I didn't succeed.
I am using Xcode 6 and I am trying to add programmatically an image to my view. Everything is fine if I load an image beloging to the project, nothing works when I try to load an image resident on some remote server.
I have tried two different way:
1) using the libray SDWEBImage
UIImageView *imgg =[[UIImageView alloc] initWithFrame:CGRectMake(30, 250, 300, 20)];
NSURL *imageURL = [NSURL URLWithString:beaconLogo];
[imgg sd_setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
[self.view addSubview:imgg];
where beaconLogo is a string containing the url of the remote image (when I debug I can see that it has the correct value).
I have imported
#import "uiimageview+webcache.h"
#import "SDWebImageDownloader.h"
not sure if those are the correct headers needed. Anyway, the image is not displayed
2) I tried by using the following code that I found in some answer here on stackoverflow
NSURL *imageURL = [NSURL URLWithString:beaconLogo];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
UIImageView *imgg =[[UIImageView alloc] initWithFrame:CGRectMake(30, 250, 300, 20)];
imgg.image = image;
[self.view addSubview:imgg];
No image is displayed, however I can see that there is something bad going on, because if I debug, I can see that "image" is nil, this line
UIImage *image = [UIImage imageWithData:imageData];
doesn't seem to have the desider effect.
Where am I going wrong? Thanks in advance.
I'm to create a simple app with the following features:
First page of app will display a list of images from server (when we display these images we should pixelate it).
Once user clicks on any pixelated image then it will open in detail view (opens that pixelated image in a new ViewController).
When the user does a single touch on the detail view controller image, then it will reduce its pixelation level, and after some clicks the user can see the real image.
My problem is I am not able to find out a way to pixelate all these things dynamically. Please help me.
The GPUImage Framework has a pixellate filter, since it uses the GPUAcceleration applying the filter on an image is very fast and you can vary the pixellate level at runtime.
UIImage *inputImage = [UIImage imageNamed:<#yourimageame#>];
GPUImagePixellateFilter *filter = [[GPUImagePixellateFilter alloc] init];
UIImage *filteredImage = [filter imageByFilteringImage:inputImage];
An easy way to pixellate an image would be to use the CIPixellate filter from Core Image.
Instructions and sample code for processing images with Core Image filters can be found in the Core Image Programming Guide.
UIImage *yourImage = [UIImage imageNamed:#"yourimage"];
NSData *imageData1 = UIImageJPEGRepresentation(yourImage, 0.2);
NSData *imageData2 = UIImageJPEGRepresentation(yourImage, 0.3);
and so on upto
NSData *imageDataN = UIImageJPEGRepresentation(yourImage, 1);
show the imageData with the help of the below:
UIImage *compressedImage = [UIImage imageWithData:imageData1];
try this. Happy coding
I need show the image from https (ex. https://ton.twitter.com/1.1/ton/data/dm/433966760199725056/433966760212332544/du3THdSe.png) by UIImageView in my iOS app. This image opens in browser, but does not show in UIImageView by using these methods:
NSURL *url = [NSURL URLWithString:#"https://ton.twitter.com/1.1/ton/data/dm/433966760199725056/433966760212332544/du3THdSe.png"];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
imageView.image = image;
or
// using SDWebImage
[imageView setImageWithURL:[NSURL URLWithString:#"https://ton.twitter.com/1.1/ton/data/dm/433966760199725056/433966760212332544/du3THdSe.png"] placeholderImage:nil];
How can I display this image?
It won't display until you login into twitter with your app. The app can only display the image when you have an open Session with Twitter.
Try calling that URL with your Chrome or Safari in Incognito/Private Mode and see what happens!
You will be redirected to the login page of Twitter. Same thing happens with your app.
Hope that helps.
Cheers,
Sebastian
This question already has answers here:
iOS download and save image inside app
(11 answers)
Closed 10 years ago.
How can I download images into the app? Like I want to fetch images from my website and download it into the person's iphone app to be shown in the app? Basically the image won't be shown by url.
More specific:
How do I download the image to the app without using UIImage. I want to fetch the image and download it as the file name "anne.png" then reference it throughout the app using UIImage as anne.png. See - I want to download it first so that when someone visits the app a second time, they see the image, and see a default image in the meantime.. Thanks.?
http://mobiledevelopertips.com/cocoa/download-and-create-an-image-from-a-url.html
URL to Remote Image
We start by creating a URL to the remote resource:
NSURL *url = [NSURL URLWithString: #"http://mobiledevelopertips.com/images/logo-iphone-dev-tips.png"];
Create UIImage from NSData
The next step is to build a UIImage using the data downloaded from the URL, which consists of an NSData object that holds the remote image contents:
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
Putting it Together
Here’s how to wrap it all together, adding the remote image as a subview to an existing view by creating a UIImageView from the above UIImage:
NSURL *url = [NSURL URLWithString:#"http://mobiledevelopertips.com/images/logo-iphone-dev-tips.png"];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
[self.view addSubview:[[UIImageView alloc] initWithImage:image]];
For single image you can use the following. Keep in mind this will block the UI till the image is fully downloaded.
[UIImage imageWithData:[NSData dataWithContentsOfURL:photoURL]];
To download the image without blocking the UI:
dispatch_queue_t downloadQueue = dispatch_queue_create(“image downloader”, NULL);
dispatch_async(downloadQueue, ^{
[NSData dataWithContentsOfURL:photoURL];
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *image = [UIImage imageWithData:imageData];
// Code to show the image in the UI goes here
});
});
To save the image to the phone camera roll you can use UIImageWriteToSavedPhotosAlbum.
To save the image in the app's directory. Use NSData's writeToFile:atomically:
To download several images from a website maybe this can help you:
What's the best way to download multiple images and display multiple UIImageView?