1、增加了阅读协议并给协议截屏,然后上传到服务端,一下为滚动协议的截屏功能代码:
- (void)screenShotWithScrollView:(UIScrollView *)scrollView
{
UIImage* image;
UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, NO, 1);
{
CGPoint savedContentOffset = scrollView.contentOffset;
CGRect savedFrame = scrollView.frame;
scrollView.contentOffset = CGPointZero;
scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
scrollView.contentOffset = savedContentOffset;
scrollView.frame = savedFrame;
}
UIGraphicsEndImageContext();
NSData *data = UIImageJPEGRepresentation(image, 1);
[data writeToFile:[self getPathWithDocument:@"protocol" fileName:@"protocol.jpg"] atomically:NO];
}
在webView加载数据完成后:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
// js获取高度
CGFloat scrollHeight = [[webView stringByEvaluatingJavaScriptFromString: @"document.body.scrollHeight"] floatValue];
if (!webView.isLoading) {
NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];
BOOL complete = [readyState isEqualToString:@"complete"];
if (complete) {
//此处是判断webView数据加载完成后的一些操作,有时候它已经加载完但是数据并没有显示出来,这个方法可以判断加载完并且数据全部显示完毕。
}
}
}
2、图片签名:
用到了别人写的一个类:PJRSignatureView。它有一个变量incrImage,需要声明为公有属性,用来在外部判断改签名是否为空。
然后是获得某个范围内的屏幕图像
- (UIImage *)imageFromView:(UIView *)theView atFrame:(CGRect)r
{
UIGraphicsBeginImageContext(CGSizeMake(theView.width, _signatureView.bottom));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
UIRectClip(r);
[theView.layer renderInContext:context];
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
最后是图片的合成,把协议截取的图片与签名合成一张图片:
- (void)combine:(UIImage *)topImage bottomImage:(UIImage *)bottomImg imageSacle:(CGFloat)scale
{
CGFloat height = topImage.size.height + bottomImg.size.height;
CGSize offScreenSize = CGSizeMake(kScreenWidth, height);
UIGraphicsBeginImageContextWithOptions(offScreenSize, YES, scale);
CGRect rect = CGRectMake(0, 0, kScreenWidth, topImage.size.height);
[topImage drawInRect:rect];
rect.origin.y+=topImage.size.height;
CGRect rect1 = CGRectMake(0, rect.origin.y, kScreenWidth, bottomImg.size.height);
[bottomImg drawInRect:rect1];
UIImage *imagez = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data = UIImageJPEGRepresentation(imagez, 1);
[data writeToFile:[self getPathWithDocument:@"protocol" fileName:@"protocolSignature.jpg"] atomically:YES];
self.imagePath = [self getPathWithDocument:@"protocol" fileName:@"protocolSignature.jpg"];
}
3、在图片上传的时候需要用到AFN的含有AFMultipartFormData类的post请求。
如果崩溃的话在这个地方加个判断:
//把image 转为data , POST上传只能传data
if (data != nil) {
//上传的参数(上传图片,以文件流的格式)
[formData appendPartWithFileData:data name:@"file" fileName:imgPath mimeType:@"image/jpg"];
}
保存本地的图片最好用jpg,因为png有些大。清晰度可以根据参数scale来调整。在上传图片时有一点需要注意:
if ([imgPath containOfString:@"http"]) {
imgPath = [imgPath stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
NSURL *newStr2Url = [NSURL URLWithString:imgPath];
//转成data,让data读取这个地址上的内容并将其转成data数据
data = [NSData dataWithContentsOfURL:newStr2Url];
}else{
data = [NSData dataWithContentsOfFile:imgPath];
}
这里是需要区分本地路径和网络图片路径的。当时就因为这个晕了一会儿。
(最后才发现,这个没必要)
此次更新新的功能就这么多。记录一下。
参考:http://blog.csdn.net/kiwirr/article/details/50433897