Facebook Photo Size in iOS sdk - iphone

Right now with the Facebook iOS sdk, I am pulling images off the wall. but I need to analyze the photo and determine the height and width of the photo.
How would I go about doing this?

I know that this is an old question which has been answered, but since the accepted answer is very unclear and because this might help others that have the same problem as you had:
Given that the images that you pull off the wall are turned into UIImage objects before you display them, then you can just do the following to easily get the height and width of each object:
Full code example:
NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:yourimageurlhere]];
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
[imageData release];
NSLog(#"Height : %0.1f", image.size.height);
NSLog(#"Width : %0.1f", image.size.width);

when you issue a call to GraphAPI photo object, you get dimensions in the response: https://graph.facebook.com/98423808305
is it what are you looking for?

Related

Loading server image using initWithData not working

I am using following code to display image from server in UIImageView.
NSURL *url = [NSURL URLWithString:#"http://www.gettyicons.com/free-icons/125/miscellaneous/png/256/apple_256.png"];
NSData *imageData =[[NSData alloc] initWithContentsOfURL:url];
imgLargePicture.image = [[UIImage alloc] initWithData:imageData];
I can see the picture in Saffari but the image is not rendered in the iPhone application. I searched a lot on net and even in stackoverflow, everywhere this same code is given to display image from server. But in my case somehow its not working.
Can anyone please help me with this?
I use the same code of you and i get the image, so please check the NSData and make sure that imageView IBOutlet should be properly connected. Same code is running fine at my side i have check in xcode.
Just tried that code in my app and it worked. You are not adding that "imgLargePicture" (I assume it's a UIImageView) as your UIViewController's view subview or not giving it a proper frame.
Try this in your -viewDidLoad: and see if it works
UIImageView *imgLargePicture = [[UIImageView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:imgLargePicture];
NSURL *url = [NSURL URLWithString:#"http://www.gettyicons.com/free-icons/125/miscellaneous/png/256/apple_256.png"];
NSData *imageData =[[NSData alloc] initWithContentsOfURL:url];
imgLargePicture.image = [[UIImage alloc] initWithData:imageData];
This was happening because of proxy server setup in the organization. It required me to provide user name & password to go through proxy. So this is fixed by implementing AuthenticationChallenge method where I passed the credentials.

UIImageView not displaying image in ipad

I am loading image from url coming from xml image not showing image
CGRect mywebframe=CGRectMake(0,60,700,300);
UIImageView*imageView=[[UIImageView alloc] initWithFrame:mywebframe];
NSString*imageurl=aBook.image;
imageurl=[imageurl stringByReplacingOccurenceOfString:#"\n" withString:#""];
imageurl=[imageurl stringByTrimmingCharacterInSet:[NSCharacterSet whitespaceCharacterSet]];
NSURL*url=[NSURL URLWithString:imageurl];
NSData*data=[[NSData alloc] initWithContentsOfURL:url];
UIImage*imagetemp=[[UIImage alloc] initWithData:data];
imageView.image=imagetemp;
[subView addSubView:imageView];
I bet your image (imagetemp) is nil.
Too many possibilities why it is nil. Try to log every variable before you use it and you'll find the bug quickly.
Firstly, you can use NSLog() to make sure your URL is correct.
Secondly, you really can not get the image that simple. I recommend a ImageView named EGOImageView You only need to give a place holding image and a URL, you can have the an asynchronized imageView.It also cache images for you automatically.

Image Swiping In Objective-C

I'm just a beginner to iphone development.
Recently i'm doing a project in which images need to be swiped. Could any one help me with it?
The images are stored in a server whose link is given.
I'm need it badly. So please help me
thank you
There are two ways.
You could either look at using a Paging Scroll View
Or, You could look at getting a series of UIImageViews with the correct images in each and then setting up a UISwipeGestureRecogniser for both directions. On the swipe's event handler you can adjust the x and y positions of the imageViews.
This is basic stuff. You should read some of the How-to's on Apple's developer website to help you with the base knowledge.
Edit:
Regarding the Internet images, the code can be adapted into the paging scroll view example:
NSString *path = #"http://merrimusings.mu.nu/archives/images/groundhog2.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data cache:NO];
Load the strings from an NSMutableArray instead and you're good to go!
Use Three20 photo Album. Your problem will be solved.

iphone image loading problem

I have make a one small image and in which one detail page is there.
and I in detail page I have one image tag which is in webview with html page.
It's work completely but image take a much time for loading and show in the screen.
So how can I reduce the time of loading for image. and this image is come form url.
imgBiteSpot.clipsToBounds=YES;
NSData *imageData = [[[NSData alloc]init]autorelease];
imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ObjBitSpot.StrImagePath]];
if(imageData==0)
{
imgBiteSpot.image=[UIImage imageNamed:#"img-not-found.gif"];
}
else {
UIImage *imgs = [[UIImage alloc] initWithData:imageData];
UIGraphicsBeginImageContext(CGSizeMake(88,88));
[imgs drawInRect:CGRectMake(0.0, 0.0, 88.0, 88.0)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
imgBiteSpot.image=newImage;
[imgs release];
}
You could consider not downloading the image but downloading a one characters variable/flag from a web service. Depending on the answer from the web service you could load an image locally from the bundle? This could be faster.
Chris.
This is best example for loading image.
http://www.dimzzy.com/blog/2009/11/remote-image-for-iphone/
Its take time base on image size and internet speed.
But one thing you can do in your application.
You can download asynchronously that image and store it in temporary variable before you go in detail image view. When you go on that detail image you can load that downloaded image as per your requirement.

Uploading pictures to Facebook

I am writing an app that publishes pictures on Facebook using facebook-ios-sdk, but everytime I upload a picture, it's displayed with the wrong orientation on my album. Here's the code I am using, note that I account for the orientation on the second line:
ALAssetRepresentation *rep = [currentAsset defaultRepresentation];
UIImage *img = [UIImage imageWithCGImage:[rep fullResolutionImage] scale:[rep scale] orientation:[rep orientation]];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
img, #"picture",
[pictureCaptionTextView text], #"caption",
nil];
[facebook requestWithMethodName: #"photos.upload"
andParams: params
andHttpMethod: #"POST"
andDelegate: self];
[img release];
Does anyone know what's going on? Should I pass the orientation when uploading it?
Have you tried using different photos, or are you testing on the same images each time? Sometimes an image will have EXIF data that will tell image programs to rotate it; it could be either that facebook is honoring EXIF data that your local app isn't and thus rotating or it could be that locally your program is displaying it rotated and facebook isn't.
Try viewing your photo in a few different browsers, and even better try downloading a photo from facebook and then re-uploading it =]
I finally figure this out thanks to this link.
The trick is that UIImageView automatically rotates the image correctly but the raw data is always on the default camera orientation (landscape, top to the right), so you need to adjust accordingly.
Bonus: this method resizes the image if you need to.