如何在facebook集成的文本中发布带有Iphone sdk的图像 [英] How to post images with text in facebook integration in Iphone sdk

查看:73
本文介绍了如何在facebook集成的文本中发布带有Iphone sdk的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我有一个问题。实际上,我在我的应用程序中实现了facebook集成,我需要用文本发布图像,但我不知道如何处理这个。任何人都可以使用示例代码来建议对我来说非常有帮助。



任何人的帮助将不胜感激。

解决方案

我假设您想在图片中绘制一些文字,然后将图像上传到Facebook。



首先,我们需要将原始图像和所需文本绘制到新图像中。

  UIGraphicsBeginImageContext(CGSizeMake(320.0,320.0)); 
CGContextRef context = UIGraphicsGetCurrentContext();
//绘制原始图像
[image drawInRect:CGRectMake(0,0,320.0,320.0)];
//绘制文本
[@textdrawInRect:CGRectMake(...)withFont:[UIFont systemFontOfSize:20.0];

UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

然后,将图像转换为NSData,并调用Facebook的photos.uploadAPI上传它。

  NSMutableDictionary * args = [[[NSMutableDictionary alloc] init] autorelease]; 
[args setObject:@captionforKey:@caption];
FBRequest * uploadPhotoRequest = [FBRequest requestWithDelegate:self];
NSData * data = UIImagePNGRepresentation(newImage);
[uploadPhotoRequest call:@photos.uploadparams:args dataParam:data];


Here Iam having a problem.Actually I implemented the facebook integration in my application and I need to post the images with text but I dont have any idea how to work on this.can anyone suggest this with a sample code so that it is very helpful for me.

Anyone's help will be much appreciated.

解决方案

I assume that you want to draw some text in an image, and then upload the image to Facebook.

At first, we need to draw the original image and the desired text into a new image.

UIGraphicsBeginImageContext(CGSizeMake(320.0, 320.0));
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw the original image
[image drawInRect:CGRectMake(0, 0, 320.0, 320.0)];
// Draw the text
[@"text" drawInRect:CGRectMake(...) withFont:[UIFont systemFontOfSize:20.0];

UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

And then, convert the image into NSData and call Facebook's "photos.upload" API to upload it.

NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:@"caption" forKey:@"caption"];      
FBRequest *uploadPhotoRequest = [FBRequest requestWithDelegate:self];
NSData *data = UIImagePNGRepresentation(newImage);
[uploadPhotoRequest call:@"photos.upload" params:args dataParam:data];

这篇关于如何在facebook集成的文本中发布带有Iphone sdk的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆