- //把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]);
將UIView轉成UIImage,將UIImage轉成PNG/JPG
轉載於:https://www.cnblogs.com/jgl-blog/p/5110808.html
相關文章
- 【LaTeX入門】08、將png、bmp、jpg轉換成eps
- 在matlab中如何將圖片(png和jpg)轉成mat格式Matlab
- 如何將heic格式轉換成jpg圖片?
- 如何將HEIC轉換為JPG / JPEG或PNG?
- 怎麼將pdf轉換成jpg圖片格式
- UIImage與Iplimage相互轉換UI
- win10 png怎麼修改成jpg_win10如何把png轉換成jpgWin10
- png圖片怎麼轉換成jpg 電腦上怎麼把png格式改成jpg
- win10怎麼png轉jpg格式 win10系統png怎麼轉換成jpg圖片Win10
- Python 將Word轉換為JPG、PNG、SVG圖片PythonSVG
- 如何從將xcode工程中圖片pdf轉成png?XCode
- NSData與UIImage之間的轉換UI
- 線上將網頁轉成PDF檔案\JPG圖片的工具網頁
- 將字串轉換成Bitmap型別 或者 將Bitmap轉換成字串字串型別
- ccrendertexture to uiimageUI
- 原始碼閱讀:SDWebImage(十九)——UIImage+ForceDecode/UIImage+GIF/UIImage+MultiFormat原始碼WebUIORM
- 將 man page 轉成 HTML 格式(轉)HTML
- Win10系怎麼將HEIC轉換成JPG格式_win10怎樣把heic照片格式變成jpgWin10
- 如何使用Super Vectorizer在 Mac 上將 PNG、JPG等轉換為 SVGMacSVG
- 在 Linux 下將 PNG 和 JPG 批次互轉的四種方法Linux
- java將map轉成bean工具JavaBean
- 將整數轉換成字串字串
- 如何使用Mac預覽程式將png轉換為jpg格式的技巧分享Mac
- UIImage 影象處理UI
- OC UIImage基礎UI
- [iOS] UIImage和CGImageRefiOSUI
- png轉jpg,常用格式怎麼互相轉換
- JPG轉CAD,JPG圖片如何轉換成CAD圖紙?
- 如何將圖片轉換成影片?
- python中將xmind轉成excelPythonExcel
- Fable:將F#轉譯成JavaScriptJavaScript
- Word將文字轉換成表格技巧
- 如何免費將PDF轉成PPT?
- 如何將Word文件轉成Excel表格?Excel
- Photoshop將png轉為ico圖示
- Java實現emf轉jpg png 圖片轉換Java
- .NET使用DinkToPdf將HTML轉成PDFHTML
- php將arm轉換成mp3PHP