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.
I'm trying to get a profile picture and show it in full screen in iOS
Tried using the object FBProfilePictureView, I can't seem to be able to customize the size of the image, it's always the same maximum size
If I try changing the image with other profileIDs, I get different sizes for different profiles
Also tried
uPhoto.pictureCropping = FBProfilePictureCroppingSquare;
But it doesn't make anything better
Should I be using an UIImageView and load the data from a URL like this
https://graph.facebook.com/someuser/picture?width=XXX&height=YYY
Or are there better options ?
FBProfilePictureView allocates a UIImageView in its implementation. There is nothing you can set on FBProfilePictureView that will change the way it scales the UIImageView. So, yes you could allocate your own UIImageView and load a URL. The correct way to get the URL is like this:
NSDictionary *imageQueryParam = #{#"type":#"large"};
NSString *graphPath = [NSString stringWithFormat:#"%#/picture",self.profileID];
FBRequest *fbRequest = [[FBRequest alloc] initWithSession:nil graphPath:graphPath parameters:imageQueryParam HTTPMethod:nil];
FBRequestConnection *requestConnection = [[FBRequestConnection alloc] init];
[requestConnection addRequest:fbRequest completionHandler:nil];
NSURL *url = requestConnection.urlRequest.URL;
This is adapted from my updated version of FBProfilePictureView... DBFBProfilePictureView which was based on Facebook's original.
Problem Resume:
I take a photo with camera or chose one from the library, then add some UITextFields to it (next to UIImageView with the chosen picture), create one UIImage of it all, and then I want to share this, particularly on Facebook and on Twitter. I am able to do this, however the quality of the image drops significantly. How can I adjust the code so that the quality stays on top?
Long description with code and images
First of all, I chose between camera and library. Then, after I pick an image in some way, I get it with
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
method, where I assign the image to my global UIImage *chosenImage, with which I use it afterwards.
Then, I add the chosenImage to the UIImageView, and as a sibling, I add an UITextField, like this:
UIImageView *chosenImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, actualHeight - 50)];
[chosenImageView setBackgroundColor:[UIColor clearColor]];
[chosenImageView setContentMode:UIViewContentModeScaleAspectFill];
[chosenImageView setClipsToBounds:YES];
[chosenImageView setImage:chosenImage];
UITextField *textFieldName = [[UITextField alloc] initWithFrame:CGRectMake(15, 15, 290, 30)];
[textFieldName setBackgroundColor:[UIColor blueColor]];
[textFieldName setDelegate:self];
[textFieldName setTag:-1];
[textFieldName setText:textName];
[textFieldName sizeToFit];
[textFieldName setContentScaleFactor:2.0];
[pageView addSubview:textFieldName];
[pageView addSubview:chosenImageView];
After this, I have a 'share this!' button which, after clicked, presents the possibility to share the image to Facebook and Twitter. I then get the UIImage *imageToShare with this method to convert the UIView to UIImage (which seems to be working alright, imho):
- (UIImage *)changeViewToImage:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions([view bounds].size, NO, 0);
[[view layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
It seems that the quality of the shared picture is the same for Facebook and Twitter, and the same in this case means really bad.
the code I use for twitter sharing:
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#""];
[tweetSheet addImage:imageToShare];
[tweetSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
[self presentViewController:tweetSheet animated:YES completion:nil];
and the code I use for Facebook share:
NSDictionary *params = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:UIImagePNGRepresentation(imageToShare), imageDescription, nil] forKeys:[NSArray arrayWithObjects:#"source", #"message", nil]];
[FBRequestConnection startWithGraphPath:#"me/photos" parameters:params HTTPMethod:#"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
[[[UIAlertView alloc] initWithTitle:#"Success!" message:#"Your photo was successfully posted to your Facebook Wall" delegate:nil cancelButtonTitle:#"Ok :)" otherButtonTitles:nil, nil] show];
[self returnFromShareView];
}];
However, I've added some code to save the imageToShare to the documents:
NSData *data = UIImagePNGRepresentation(imageToShare);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *filePath = [documentsPath stringByAppendingPathComponent:#"currentImage.png"]; //Add the file name
[data writeToFile:filePath atomically:YES]; //Write the file
and when I look it up there, it looks fairly fine! Which really makes me wonder why I don't use an envelope with printed picture (the one saved to the documents, of course!), and don't send it to Menlo Park, CA and South of Market, CA instead of trying to solve this ridiculous issue.
Now come the pictures!
umh.. So after I tried to upload the images here, the uploading thingy turned the .png image to horrible quality as well!!! Aagh, I thought stackOverflow is with me!
Anyways, here are the pictures (uploaded here), and corresponding links, which shows the actual images, on my server (which I hope won't destroy them as well)
Picture uploaded to Facebook: Facebook image on my server
Picture uploaded to Twitter: Twitter image on my server
Picture from the documents: Picture from the documents on my server (there is a huge difference!)
So, does anybody know what settings should I chose for the image in the code to make the quality (even after .jpg compression, which is done everywhere it seems, even here) at least somehow better? And as it seems to me, it happens only on the solid background with text on it (when I tried to upload an image without the background, it looked better, but there must be a way how to make it look better with background as well)
Thanks!
EDIT
As it turns out, the problem might not be with the sharing stuff, but with the jpeg compression itself. As it states here in the answer: Facebook: Ways to preserve image quality of uploaded images?,
"JPEG is not suitable for images with text, large blocks of color, or simple shapes, because crisp lines will blur and colors can shift. http://graphicssoft.about.com/od/graphicformats/f/summary.htm "
So I guess there is no solution, as Facebook, Twitter and even stack.imgur use jpeg compression, and as long as there will be an 'image with text, large blocks of color, or simple shapes', it'll come badly. Too bad.
JPEG compression works best for continuous tone imagery such as photos. It dos not work well with areas of solid color and sharp traditions such as text. Png/Gif works much better. There are some formats that deal with this better such as Google WebP which Facebook considered using but abandoned.
You best best is to stick with JPEG and play with the JPEG encoding setting but there are a few things you can do. Adjust your font either with the built in iOS fonts or use your own custom font. Since sharp transition of solid color cause a problem, avoid using Serif fonts. Also the fatter the font and larger it is the better. IOS supports custom fonts so play around with different open source fonts and find one at the biggest size you can accept. Follow this article
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/.
Another thing that help is anti aliasing. This is where the edge colors are blurred making the text seem more readable(over simplification). The text will not be anti aliased and you can not easily force anti aliasing but you could fake it. Create the text at a larger size (2 to 3x) in a separate image with transparency and scale it down before adding it over the picture. The image interpolation will blur the images giving you a poor mans anti aliasing.
I'm using Sharekit2.0 to share images to facebook and twitter.
Here is the code used for sharing the image in facebook.
SHKItem *sharerItem = [SHKItem image:image title:#""];
SHKTwitter *sharer = [[SHKTwitter alloc] init];
[sharer setItem:sharerItem];
[sharer share];
But this not showing any preview of the image when sharing (like twitter is showing). just a text view to enter title for image.
My question would be: is it possible to show to image preview when sharing to facebook ?
Thanks
Try:
SHKItem * sharerItem = [SHKItem image:image title:#"P"];
[SHKTwitter shareItem:sharerItem];
Does anyone know how to set a default sentence when the user shares something on his wall? Im not asking about the the user's text. I'm asking how to show the tagline "... took a photo with ...".
Refer this link.
UIImage *image = [UIImage imageNamed:#"Image.jpg"]; // You Image that u want to share
SHKItem *item = [SHKItem image:image title:#"XXX : took a photo with Instagram"];
[SHKFacebook shareItem:item];
Hope it worked for You.