1
有人知道如何使用MacRuby(或普通的ruby)转换图像吗?我会想象'ScriptingBridge'框架将能够处理它。使用MacRuby转换图像
另外,我不想使用ImageMagick或类似的东西(然而,更轻的东西会很好)。
谢谢!
有人知道如何使用MacRuby(或普通的ruby)转换图像吗?我会想象'ScriptingBridge'框架将能够处理它。使用MacRuby转换图像
另外,我不想使用ImageMagick或类似的东西(然而,更轻的东西会很好)。
谢谢!
你可以用MacRuby的做到这一点:
framework 'AppKit'
input_file_path = "/Users/username/Desktop/input_file.png"
img_data = NSData.dataWithContentsOfFile(input_file_path)
bitmap = NSBitmapImageRep.imageRepWithData(img_data)
new_data = bitmap.representationUsingType(NSJPEGFileType, properties: nil) # NSBMPFileType, NSGIFFileType, NSJPEGFileType, NSPNGFileType, or NSTIFFFileType.
output_file_path = "/Users/username/Desktop/output_file.jpeg"
new_data.writeToFile(output_file_path, atomically: true)
就大功告成了,NSBitmapImageRep#representationUsingType:特性:可采取NSBMPFileType,NSGIFFileType,NSJPEGFileType,NSPNGFileType或NSTIFFFileType为BMP,GIF,JPEG,PNG或tiff
谢谢!这正是我期待的! – dejay