[英]How to convert jpeg image to PICT image on MAC using Cocoa
如何使用可可將JPEG圖像轉換為PICT圖像。下面給出一些腳本。
NSData *imgData = [NSData datawithContentsOfFile:@"/var/root/Desktop/1.jpeg"];
NSPICTImageRep *imagerep = [NSPICTImageRep imageRepWithData:imgData];
NSData *data = [imageRep PICTRepresentation];
[data writeTofile:@"/var/root/Desktop/save.pict" atomically:No];
該腳本不起作用。 以及其他任何無需Applescript即可將jpeg圖像轉換為pict圖像的替代方法。
。
您的代碼有幾個問題。
#1)您確定該“ 1.jpeg
”文件的位置嗎?
#2)您不是在查看“ writeToFile
”的錯誤結果。 在我的機器上,我無法寫入“ /var/root
”目錄中的任何內容。
修復源路徑和目標路徑后,應將代碼更改為以下內容:
NSData *imgData = [NSData datawithContentsOfFile:@"/Users/anuj/Desktop/1.jpeg"];
NSPICTImageRep *imagerep = [NSPICTImageRep imageRepWithData:imgData];
NSData *data = [imageRep PICTRepresentation];
NSLog(@"my image data size is %ld", [data length]);
if([data length] > 0)
{
BOOL success = [data writeTofile:@"/Users/anuj/Desktop/save.pict" atomically:NO];
if(success)
NSLog(@"successfully wrote the file");
else
NSLog(@"did not write the file");
}
else
{
NSLog(@"didn't convert the image to a Pict");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.