如何把NSString和UIImage合成一张图片保存 如题请大家帮助,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 UIImage转成NSData,再利用base64编码转成字符串加上一个定义结构体或是类typedef struct{ NSString *yourStr; NSString *imgBase64;} yourStructName;不知是不是你想要的答案? 先把image画到屏幕,再把字符串画到屏幕上,然后再保存[self setNeedsDisplay];//用这个方法,系统会执行下面的方法- (void) drawRect: (CGRect) rect{ if (!self.points) return; if (self.points.count < 2) return; CGContextRef context = UIGraphicsGetCurrentContext(); [current set]; CGContextSelectFont (context, // 3 "Arial", 40, kCGEncodingMacRoman); UIFont* tfont = [UIFont fontWithName:@"Arial" size:40.0]; CGContextSetCharacterSpacing (context, 10); // 4 CGContextSetTextDrawingMode (context, kCGTextFillStroke); // 5 // CGContextSetRGBFillColor (context, 0, 1, 0, 1.0); // 6// CGContextSetRGBStrokeColor (context, 0, 0, 1, 1); // 7 // NSString *tstr = @"test";// // // [tstr drawAtPoint:CGPointMake(0.0,0.0) withFont:tfont]; NSString *path = [self pathForItemNamed:@"aa.png" inFolder:[self imageFolderPath:@"Documents"]]; UIImage * img = [UIImage imageWithContentsOfFile:path]; [img drawInRect:CGRectMake(0.0, 0.0, 320, 480)]; NSString*tstr1 = @"1111111111111111111111"; [tstr1 drawInRect:CGRectMake(0.0, 0.0, 320, 480) withFont:tfont];}然后⋯⋯保存http://www.cocoachina.com/macdev/cocoa/2009/0611/69.html 不明白楼主出于什么目的而做这个的,拼是可以拼,但UIImage二进制拼上NSString,那么这个就不是图片了,而是你自定义的一种数据格式,用图片预览是看不出来图片的。无非就是为了保存数据。何必搞得那么麻烦呢。写入不方便,读取出来也不方便。 明显楼主的思路开始就是错误的了,手机拍照的时间,相机类型等的数据已以在拍照时自动写入图片了,只要在服务器那边读取这张照片的属性(EXIF、TIFF信息)就可以了。至于服务器是用什么语言实现的,就要根据具体的语言去读取。这是object c 实现的例子代码:NSData *imageData = [NSData dataWithContentsOfFile:imagePath];CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); NSDictionary *metaData = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source,0,NULL);NSDictionary *exifData = [metaData objectForKey:@"{Exif}"];NSDictionary *tiffData = [metaData objectForKey:@"{TIFF}"];这是我读取图片显示出来的JSON信息分别是EXIF TIFF信息,"photoFlow" : [ { "ExposureTime" : 0.01666667, "MaxApertureValue" : 2.96875, "Flash" : 89, "ColorSpace" : 1, "ExifVersion" : [ 2, 2 ], "FocalPlaneYResolution" : 7245.283, "FocalPlaneResolutionUnit" : 2, "ShutterSpeedValue" : 5.90625, "FocalLength" : 7.3, "CompressedBitsPerPixel" : 2, "FNumber" : 2.8, "SceneCaptureType" : 0, "PixelYDimension" : 1, "ApertureValue" : 2.96875, "PixelXDimension" : 1, "CustomRendered" : 0, "WhiteBalance" : 0, "DateTimeDigitized" : "2008:08:23 22:15:01", "SensingMethod" : 2, "DateTimeOriginal" : "2008:08:23 22:15:01", "MeteringMode" : 5, "FlashPixVersion" : [ 1, 0 ], "ComponentsConfiguration" : [ 1, 2, 3, 0 ], "ExposureMode" : 0, "DigitalZoomRatio" : 1, "ExposureBiasValue" : 0, "FocalPlaneXResolution" : 7236.749 }, { "Model" : "Canon PowerShot A610", "_YCbCrPositioning" : 1, "ResolutionUnit" : 2, "YResolution" : 180, "XResolution" : 180, "Orientation" : 1, "DateTime" : "2008:08:23 22:15:01", "Make" : "Canon" } ], 先把image画到屏幕,再把字符串画到屏幕上,然后再保存正解 佳能一直在搞这个似乎,有失真,楼主要有思想准备。基本做法是jpeg转成中间存储格式,在Windows上可以是bitmap,然后在bitmap上用画图函数写时间,之后再转换成jpeg。jpeg库是现成的,到网上找找官方的,是用c语言写的。 求救 彭佳乐他应该有思路Iphone的GDI跟Win的类似,你拿来改改 怎样发送16进制的数字? 有没有在另外一个类之中继续定义一个宏的方法 如何在本地mac机子上搭建webserver? 横竖屏切换时界面整体会往home键方向平移 请问如何搭建phonegap开发iphone的环境 IOS怎么入门? 新手求助:为什么layoutSubview方法不调用? AutoLayout中UIlabel高度问题 iOS 中怎么修改 UIImageView的frame? 文本自适应控件frame Ipad开发 如何在设置里配置应用程序(主要是弹出对话框形式配置) 教个问题!关于多个label的显示问题(也可以说是动画效果?)
加上一个定义结构体或是类
typedef struct
{
NSString *yourStr;
NSString *imgBase64;
} yourStructName;不知是不是你想要的答案?
[self setNeedsDisplay];//用这个方法,系统会执行下面的方法
- (void) drawRect: (CGRect) rect
{
if (!self.points) return;
if (self.points.count < 2) return;
CGContextRef context = UIGraphicsGetCurrentContext();
[current set];
CGContextSelectFont (context, // 3
"Arial",
40,
kCGEncodingMacRoman);
UIFont* tfont = [UIFont fontWithName:@"Arial" size:40.0];
CGContextSetCharacterSpacing (context, 10); // 4
CGContextSetTextDrawingMode (context, kCGTextFillStroke); // 5
// CGContextSetRGBFillColor (context, 0, 1, 0, 1.0); // 6
// CGContextSetRGBStrokeColor (context, 0, 0, 1, 1); // 7
// NSString *tstr = @"test";
//
//
// [tstr drawAtPoint:CGPointMake(0.0,0.0) withFont:tfont];
NSString *path = [self pathForItemNamed:@"aa.png" inFolder:[self imageFolderPath:@"Documents"]];
UIImage * img = [UIImage imageWithContentsOfFile:path];
[img drawInRect:CGRectMake(0.0, 0.0, 320, 480)];
NSString*tstr1 = @"1111111111111111111111";
[tstr1 drawInRect:CGRectMake(0.0, 0.0, 320, 480) withFont:tfont];
}
然后⋯⋯
保存
http://www.cocoachina.com/macdev/cocoa/2009/0611/69.html
无非就是为了保存数据。何必搞得那么麻烦呢。写入不方便,读取出来也不方便。
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); NSDictionary *metaData = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(source,0,NULL);NSDictionary *exifData = [metaData objectForKey:@"{Exif}"];NSDictionary *tiffData = [metaData objectForKey:@"{TIFF}"];
这是我读取图片显示出来的JSON信息分别是EXIF TIFF信息,"photoFlow" : [
{
"ExposureTime" : 0.01666667,
"MaxApertureValue" : 2.96875,
"Flash" : 89,
"ColorSpace" : 1,
"ExifVersion" : [
2,
2
],
"FocalPlaneYResolution" : 7245.283,
"FocalPlaneResolutionUnit" : 2,
"ShutterSpeedValue" : 5.90625,
"FocalLength" : 7.3,
"CompressedBitsPerPixel" : 2,
"FNumber" : 2.8,
"SceneCaptureType" : 0,
"PixelYDimension" : 1,
"ApertureValue" : 2.96875,
"PixelXDimension" : 1,
"CustomRendered" : 0,
"WhiteBalance" : 0,
"DateTimeDigitized" : "2008:08:23 22:15:01",
"SensingMethod" : 2,
"DateTimeOriginal" : "2008:08:23 22:15:01",
"MeteringMode" : 5,
"FlashPixVersion" : [
1,
0
],
"ComponentsConfiguration" : [
1,
2,
3,
0
],
"ExposureMode" : 0,
"DigitalZoomRatio" : 1,
"ExposureBiasValue" : 0,
"FocalPlaneXResolution" : 7236.749
},
{
"Model" : "Canon PowerShot A610",
"_YCbCrPositioning" : 1,
"ResolutionUnit" : 2,
"YResolution" : 180,
"XResolution" : 180,
"Orientation" : 1,
"DateTime" : "2008:08:23 22:15:01",
"Make" : "Canon"
}
],
基本做法是jpeg转成中间存储格式,在Windows上可以是bitmap,然后在bitmap上用画图函数写时间,之后再转换成jpeg。jpeg库是现成的,到网上找找官方的,是用c语言写的。
他应该有思路
Iphone的GDI跟Win的类似,你拿来改改