- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有两个 UIImageView。我想通过脚本将两个图像发布到服务器。在此之前,我必须将这些图像转换为数据并将数据转换为字符串,但我不知道如何将图像从 UIImageView
转换为 NSData
和 NSData
到 NSString
。我已经引用了所有代码,但它不起作用。我还想知道在我的代码中应该在哪里声明转换编码(图像到数据和数据到图像)?
这是我实现的
.h部分
#import <UIKit/UIKit.h>
#import "GlobalAccessClass.h"
#import <QuartzCore/QuartzCore.h>
@interface AskQuestionHome : UIViewController<UITextViewDelegate,UITextFieldDelegate,UIImagePickerControllerDelegate,UIActionSheetDelegate>
{
}
@property (strong, nonatomic) IBOutlet UIImageView *imgSecondImg;
@property (strong, nonatomic) IBOutlet UIImageView *imgFirstImg;
@property (strong, nonatomic) IBOutlet UITextView *txtviewAsk;
-(IBAction)postbutton:(id)sender;
@property (nonatomic,retain) NSString *datestr;
@property(nonatomic,retain) NSData *imageData;
@property(nonatomic,retain) NSString *postLength;
@end
.m部分
-(void)post
{
NSMutableURLRequest *mutableurlrequest = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://www.alvinchuastudios.com/aNSWERED/insert_question.php"]];
// create the Method "POST" For POSTING the QUESTIION with IMAGES
[mutableurlrequest setHTTPMethod:@"POST"];
NSLog(@"the email is:%@",manage.transformEmail);
NSLog(@"the cat is:%@",manage.transformCategories);
NSLog(@"the text is:%@",textviewText.text);
// NSLog(@"the firstimage is:%ld",(long)imgFirstImg.tag);
// NSLog(@"the secondimage is:%ld",(long)imgSecondImg.tag);
// NSlog(@"the status is:%d",1);
NSLog(@"the user is:%@",manage.transformName);
NSLog(@"the user registered is:%@",datestr);
//passing the string to the server
NSString *qususerUpdate =[NSString stringWithFormat:@"email_id=%@&cat=%@&q_text=%@&q_image1=%ld&q_image2=%ld&q_status=1&last_upd_by=%@&last_upd_timestamp=%@",manage.transformEmail,manage.transformCategories,textviewText.text,(long)imgFirstImg.tag,(long)imgSecondImg.tag,manage.transformName,datestr,Nil];
//check the value that what we passed
NSLog(@"the data Details is =%@", qususerUpdate);
//Convert the String to Data
NSData *data1 =[qususerUpdate dataUsingEncoding:NSUTF8StringEncoding];
//Apply the data to the body
[mutableurlrequest setHTTPBody:data1];
//Create the response and Error
NSError *err;
NSURLResponse *response;
NSData *responseData =[NSURLConnection sendSynchronousRequest:mutableurlrequest returningResponse:&response error:&err];
NSString *resStr =[[NSString alloc]initWithData:responseData encoding:NSASCIIStringEncoding];
//This is for Response
NSLog(@"got response==%@", resStr); }
最佳答案
我认为 Ashu 的回答将返回 null。试试这个
NSData *dataImage = [[NSData alloc] init];
dataImage = UIImagePNGRepresentation(image);
NSString *stringImage = [dataImage base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
关于ios - 将 UIImage 转换为 NSData 并将 NSData 转换为 NSString 以将图像发布到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21301142/
我有一个相当大的 NSData (或 NSMutableData 如果需要)对象,我想从中取出一小块并保留其余部分。由于我正在处理大量 NSData 字节,因此我不想制作大副本,而只是截断现有字节。基
我有一个 NSMutableData 保存随机 ASCII 字节。 我想将这些字节的值移动一个值(X)。 所以让我们说我有这样的事情: 02 00 02 4e 00 我现在想将每个字节增加 0x01
我有一个NSData对象,其中包含图像的 RGB 值。我想把它变成 UIImage (给定宽度和高度)。然后我想转换 UIImage回到NSData对象与我开始时的对象相同。 请帮助我,我已经尝试了几
在做了类似的事情之后 NSData *originalImageData = [NSData dataWithContentsOfFile:@"somefolder\somepicture.jpg"]
我有两个 NSData 对象 NSData *toScan = /* initialized somehow with "Hello, this world." */; NSData *toMatch
我有一个 NSData 对象,其中包含我需要的一些数据。我想做的是找出数据“FF D8”的位置(JPEG数据的开始) 我怎样才能完成这样的工作? 最佳答案 先获取范围,然后获取数据: // The m
在基础框架中对内置的 NSData 类调用散列时——使用什么实现来返回散列值? (CRC32,还有什么?) 最佳答案 别的。其实就是一个实现细节,不需要在不同的版本中使用固定的算法。 你可以在Core
在基础框架中对内置的 NSData 类调用散列时——使用什么实现来返回散列值? (CRC32,还有什么?) 最佳答案 别的。其实就是一个实现细节,不需要在不同的版本中使用固定的算法。 你可以在Core
我收到错误: NSData 不是我下面代码中 NSData 的子类型,我做错了什么? let urlPath = "myurl" var url = NSURL(string: urlPath) le
我有一个大小约为 1000kB 的 NSData 对象。现在我想通过蓝牙传输这个。如果我有 10 个 100kB 的对象,那就更好了。我想到我应该使用 NSData 的 -subdataWithRan
我的 NSData 格式为“Hello$World$Image”($ 用作分隔符来区分不同的部分数据)我使用以下代码制作的 NSData *data=[@"$" dataUsingEncoding:N
我有两个 NSData 对象,我想将它们存储在第三个 NSData 对象中。我的想法是,当我稍后解码较大的对象时,我希望能够轻松地获得彼此独立的两个较小的对象,而不用担心它们的相对大小或数据类型。 看
我想将图像添加到字节数组。下面的代码给我一个错误。我想我没有做对。 错误 Field has incomplete type 'NSData *__strong[]' 在.m文件中 @interfac
我遇到了问题,你能帮帮我吗?太感谢了!NSString *我的字符串;UIImage *图像;NSData *data = ... 包括字符串和图像的数据,可以像以前一样反编译它们 最佳答案 您可以按
我觉得上面的错误一定是 Swift 的一个错误,否则 1 != 1 是一个正确的陈述... 我正在尝试创建一个 JSONObject,我可以将其包含在 HTTP Post 请求的正文中,以便使用 Co
我正在尝试将两个 NSData 对象连接成一个 NSMutableData,然后将它们取回。现在我正在尝试以这种方式进行: 获取第一个对象的长度。 按以下顺序写入 NSMutableData:第一个对
我想将 [String] 转换为 NSData 以进行 BLE 连接。 我知道如何将 String 转换为 NSData/NSData 为 String。 // String -> NSData va
这是我正在尝试的代码 NSData *imageData = [[NSData alloc]initWithData:UIImagePNGRepresentation(myImage.image)];
例如: NSData *data = [NSData dataWithContentsOfFile:filePath]; int len = [data length]; 如果 len = 10000
NSData 和 NSMutableData 有什么区别? 最佳答案 来自 Stack Overflow 标签维基: nsdata The NSData class is an apple class
我是一名优秀的程序员,十分优秀!