2
在UIImagePickerController中使用ALBUM時,獲取縮略圖非常容易。使用CAMERA(非專輯)時從UIImagePickerController獲得縮略圖
從VIDEO獲得縮略圖甚至很容易。
但是當你使用相機,
self.cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
,你回來
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
如何快速獲得縮略圖?
注意,我不是特別想保存圖像。我想使用的圖像從相機(想象一下,然後在繪圖畫面使用它,或者進行圖像處理等)
以下,這是一個天真的類別,將圖像轉換爲128.128圖像。但它太慢了。
許多應用程序很快從相機移動到下一個屏幕(例如,編輯圖像或繪圖)。什麼技術?乾杯
-(UIImage *)squareAndSmall
{
// this category works fine to make a 128.128 thumbnail,
// but it is very slow
CGSize finalsize = CGSizeMake(128,128);
CGFloat scale = MAX(
finalsize.width/self.size.width,
finalsize.height/self.size.height);
CGFloat width = self.size.width * scale;
CGFloat height = self.size.height * scale;
//uses the central area, say....
CGRect imageRect = CGRectMake(
(finalsize.width - width)/2.0f,
(finalsize.height - height)/2.0f,
width, height);
UIGraphicsBeginImageContextWithOptions(finalsize, NO, 0);
[self drawInRect:imageRect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
順便說一句,Ayan,我沒有保存圖像,也不想保存圖像 - 我只是想在飛行中獲取縮略圖。但是,謝謝你提供的信息豐富的答案!乾杯 – Fattie
@Joe不幸的是資產庫只會在寫作過程中生成縮略圖和任何其他相關圖像('fullResolutionImage' /'fullScreenImage'):( –
優秀信息,謝謝 – Fattie