UIImage與字符串互轉(zhuǎn)
//圖片轉(zhuǎn)字符串
-(NSString *)UIImageToBase64Str:(UIImage *) image{
NSData *data = UIImageJPEGRepresentation(image, 1.0f);
NSString *encodedImageStr = [data
base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
return encodedImageStr;
}
//字符串轉(zhuǎn)圖片
-(UIImage *)Base64StrToUIImage:(NSString *)_encodedImageStr{
NSData *_decodedImageData = [[NSData alloc]
initWithBase64Encoding:_encodedImageStr];
UIImage *_decodedImage = [UIImage imageWithData:_decodedImageData];
return _decodedImage;
}
截圖
// 1. 開啟一個與圖片相關(guān)的圖形上下文
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,NO,0.0);
// 2. 獲取當(dāng)前圖形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 3. 獲取需要截取的view的layer
[self.view.layer renderInContext:ctx];
// 4. 從當(dāng)前上下文中獲取圖片
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
// 5. 關(guān)閉圖形上下文
UIGraphicsEndImageContext();
// 6. 把圖片保存到相冊
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
這樣可以通過把圖片轉(zhuǎn)換為字符串傳輸。。。。