需要帮助将进程从Java(android)转换为IOS Swift吗
背景:我在android应用程序中有一个进程,它调整图像大小,使用位图中30%的JPEG压缩,并返回一个byteArray,在其中我转换为Base64编码字符串。如果可能的话,我需要将这种类型的功能移植到IOS Swift。我正在经历信息过载,因为在网络上有大量的图像处理方法,我需要更多的指导。 以下是我的android代码:需要帮助将进程从Java(android)转换为IOS Swift吗,android,ios,swift,uiimage,Android,Ios,Swift,Uiimage,背景:我在android应用程序中有一个进程,它调整图像大小,使用位图中30%的JPEG压缩,并返回一个byteArray,在其中我转换为Base64编码字符串。如果可能的话,我需要将这种类型的功能移植到IOS Swift。我正在经历信息过载,因为在网络上有大量的图像处理方法,我需要更多的指导。 以下是我的android代码: Bitmap bmp = null; Bitmap scaledBitmap = null; ByteArrayOutputStream
Bitmap bmp = null;
Bitmap scaledBitmap = null;
ByteArrayOutputStream baos = null;
try
{
bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
//if the bitmap is smaller than 1600 wide, scale it up while preserving aspect ratio
if(bmp.getWidth() < 1600) {
int originalHeight = bmp.getHeight();
int originalWidth = bmp.getWidth();
scaledBitmap = Bitmap.createScaledBitmap(bmp, 1600,
originalHeight*1600/originalWidth, true);
bmp = scaledBitmap;
scaledBitmap = null;
}
baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 30, baos); // 30% compression
image = baos.toByteArray();
}
//catch stuff after this
我认为这与我的Android程序有很大不同。我在IOS代码中创建的Base64字符串的大小太大了。抱歉,这是一个愚蠢的错误。 这: 需要这样做:
let imageData = UIImageJPEGRepresentation(info[UIImagePickerControllerOriginalImage] as? UIImage, 0.3)
let imageData = UIImageJPEGRepresentation(info[UIImagePickerControllerOriginalImage] as? UIImage, 30.0)
let imageData = UIImageJPEGRepresentation(info[UIImagePickerControllerOriginalImage] as? UIImage, 0.3)