facebook full screen picture - ios

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.

Related

UIActivityViewController share to Facebook

I want to use UIActivityViewController to share something to Facebook, and I want to customize my "image card space", So I can click the blue area and direct to other website
the image is from Facebook, and it say the blue area is image card space
this is a screen shot from other app, this app use UIActivityViewController too, so I believe it can be done, I try to search the information about how to implement, but it fail, maybe I use the wrong key word
this is my code
UIImage *Img = [UIImage imageNamed:#"myImg.png"];
NSString *myString = #"hi, I am strign";
NSURL *myUrl = [NSURL URLWithString:#"www.google.com"];
NSArray *items = #[myString, Img, myUrl];
UIActivityViewController *avc = [[UIUIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
self presentViewController:avc animated:YES completion:nil];
and this is what I get
just Image appear
myString does not appear, I guess this is because,it will appear in"user message field", and this is illegal(the first image), so iOS delete it
but where is my URL? if I post this to Facebook, it just a Image, I can't direct to other website
Is anyone know how to customize image card space?
=====================edit==================
ok, i think i got it
the app not customize the area
it just put the url
and iOS get the data automatly, and display it
so, just put url to UIActivityViewController
if anything wrong please re correct me

How can parse all the images form Website in IOS SDK

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.

how to change default receiver image size on tv screen

I altered the sample code and set the value, and then found that the default receiver image size has no change on tv. how to change that?
GCKMediaMetadata *metadata = [[GCKMediaMetadata alloc] init];
if (thumbnailURL) {
[metadata addImage:[[GCKImage alloc] initWithURL:thumbnailURL width:200 height:100]]; //<=== alter here, try to change "width:200 height:100" to "width:720 height:960", but there's no change.
}
GCKMediaInformation *mediaInformation =
[[GCKMediaInformation alloc] initWithContentID:[url absoluteString]
streamType:GCKMediaStreamTypeNone
contentType:mimeType
metadata:metadata
streamDuration:0
customData:nil];
[self.mediaControlChannel loadMedia:mediaInformation autoplay:autoPlay playPosition:startTime];
It is not clear what you are trying to achieve; if you want the image to be differently sized on your TV, then yo have to make changes in your receiver, in the <img/> tag to adjust to the size that you want.
You cannot customise the UI with a default media receiver. Use the styled media receiver instead and specify the size of your image in the css.

Image quality of socially shared image

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.

iOS close background thread

In my ViewController, I'm downloading a number of png files off the internet and adding them to UIImageViews, which I add to a UIScrollView.
However, if the user presses the back button in the navigation bar, I noticed that the background thread is still continuing to download those files. Also, I noticed huge memory spikes as a result, and I don't think my objects are properly getting released.
How can I close all threads when the user presses back in the navigation bar?
xcode 4.2.1, ARC
Thanks!
EDIT -- the following is in a for loop
NSURL* url = [[NSURL alloc] initWithString:[#"someurl"]];
NSData* imageData = [[NSData alloc]initWithContentsOfURL:url];
UIImage* image = [[UIImage alloc] initWithData:imageData];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = aFrame;
[self.screenshots addSubview:imageView]
You shouldn't be doing any downloading in your view controller. That's the source of the problem. Move your data into model classes. Do all of your downloading and data management there. The view controllers are just responsible for pulling data from the model and giving it to the views. View controllers are not responsible for fetching data from the network. As you've discovered, they can vanish at any time.
You don't want to abort downloads and then restart them every time someone moves between screens. You want to let the model classes know that some data is needed (because the user came to a screen), and then you want the model classes to post a notification (or provide a KVO change notification) that lets the view controllers know that new data is read.
You may want to consider NSOperationQueue and add new download operations via. NSURLConnection and add a supply your NSOperationQueue. You can have more then one source downloading at once and cancel all operations at once once you need to. Also you can set things like how many to download at a time.
Try this:
in your for loop, make a condition that would stop the downloads when you don't want them anymore:
declare class variable or properly
BOOL stopDownloading;
set it to false on when you start the downloads:
stopDownloading = NO;
modify your for loop to stop when you set it to NO:
if (!stopDownloading) {
NSURL* url = [[NSURL alloc] initWithString:[#"someurl"]];
NSData* imageData = [[NSData alloc]initWithContentsOfURL:url];
UIImage* image = [[UIImage alloc] initWithData:imageData];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = aFrame;
[self.screenshots addSubview:imageView];
}
so now, when back button is pressed, set
stopDownloading = YES;
it will stop all further downloads, however due to your setup, i don't immediately see a way to stop the one that is currently downloading (only subsequent ones).
To solve this problem, i would create a NSOperationQueue and add NSOperations for each download.
Or even simpler, use some existing open source solutions like AFNetworking. specifically these two:
AFImageRequestOperation A subclass of AFHTTPRequestOperation for downloading and processing images.
UIImageView+AFNetworking Adds methods to UIImageView for loading remote images asynchronously from a URL.

Resources