开发者知识库
首页
最新
最火
关于
搜索答案
中文简体
相关内容
將UIView轉成UIImage,將UIImage轉成PNG/JPG
本文转载自
u013375242
查看原文
2014-03-12
3928
image
/
image
/
objective-c
/
objective-c
/
frameworks
/
frameworks
/
xcode
xcode
//把UIView 轉換成圖片
-(UIImage *)getImageFromView:(UIView *)view{
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return
image;
}
//UIImage -> PNG / JPG
// Create paths to output images
NSString
*
pngPath
=
[
NSHomeDirectory
(
)
stringByAppendingPathComponent
:
@
"Documents/Test.png"
]
;
NSString
*
jpgPath
=
[
NSHomeDirectory
(
)
stringByAppendingPathComponent
:
@
"Documents/Test.jpg"
]
;
// Write a UIImage to JPEG with minimum compression (best quality)
// The value 'image' must be a UIImage object
// The value '1.0' represents image compression quality as value from 0.0 to 1.0
[
UIImageJPEGRepresentation
(
image,
1.0
)
writeToFile
:
jpgPath atomically
:
YES
]
;
// Write image to PNG
[
UIImagePNGRepresentation
(
image
)
writeToFile
:
pngPath atomically
:
YES
]
;
// Let's check to see if files were successfully written...
// Create file manager
NSError
*
error;
NSFileManager
*
fileMgr
=
[
NSFileManager
defaultManager
]
;
// Point to Document directory
NSString
*
documentsDirectory
=
[
NSHomeDirectory
(
)
stringByAppendingPathComponent
:
@
"Documents"
]
;
// Write out the contents of home directory to console
NSLog
(
@
"Documents directory: %@"
,
[
fileMgr contentsOfDirectoryAtPath
:
documentsDirectory error
:&
error
]
)
;
×
注意!
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。
jpg or png for UIImage — which is more efficient?
把UIView轉成UIImage,解決模糊失真問題
如何把UIView轉成UIImage,解決模糊失真問題
如何把UIView轉成UIImage,解決模糊失真問題
把UIView轉成UIImage,解決模糊失真問題
怎么樣把PNG轉成BMP或JPG格式
android 把bitmap格式轉成jpg 或png格式
將UIImage保存成JPG或PNG格式存儲在本地
怎樣將UIImage對象保存到JPG或者PNG文件中?
C# Bitmap/png轉成jpg格式,壓縮圖片
© 2014-2022 ITdaan.com 联系我们:
×
收藏本文
添加到收藏夹 *