当我按下快门按钮后在我的应用程序中拍照时,图像预览会水平镜像。我知道这样做是为了模仿镜像,但我不想在我的应用程序上出现这种行为。我希望它能像Instagram一样无需翻转就能拍摄前置摄像头照片。我知道如何翻转照片,即:
UIImage * flippedImage = [UIImage imageWithCGImage:picture.CGImage scale:picture.scale orientation:UIImageOrientationLeftMirrored];
但它是我要翻转的预览图像(显示“重拍”和“使用照片”的图像)。任何想法如何去做?我想我需要在UIImagePicker类中覆盖一些东西。
由于
答案 0 :(得分:1)
我在stackoverlfow上尝试了很多答案,但没有一个提供我想要的结果。 Eiter整个NSNotificationCenter.defaultCenter().addObserver(self, selector: "photoTaken", name: "_UIImagePickerControllerUserDidCaptureItem", object: nil)
被改造了,所以相机不直观,不像看镜子,或者只是图像在你描述之后被转换,什么工作得很好,但你有错误的图像预览 - 之间。所以我最终得到了这个黑客,它绝对不是最佳实践,但适用于iOS8和9,并为我提供了我需要的结果。
确保添加观察者以在按下捕获图像按钮时收到通知:
potoTaken
在func photoTaken() {
for subview in self.imagePicker.view.subviews {
for subsubview in subview.subviews {
for subsubsubview in subsubview.subviews {
for subsubsubsubview in subsubsubview.subviews {
for subsubsubsubsubview in subsubsubsubview.subviews {
for subsubsubsubsubsubview in subsubsubsubsubview.subviews {
for subsubsubsubsubsubsubview in subsubsubsubsubsubview.subviews {
if subsubsubsubsubsubsubview.isKindOfClass(UIImageView) {
subsubsubsubsubsubsubview.transform = CGAffineTransformScale(self.imagePicker.cameraViewTransform, -1, 1)
}
}
}
}
}
}
}
}
}
方法中,您可以执行以下操作来查找预览图像并将其转换为您期望的样式:
didFinishPickingMediaWithInfo
在您的func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
let flippedImage = UIImage(CGImage: pickedImage.CGImage!, scale: pickedImage.scale, orientation: .LeftMirrored)
myCustomPhotoAlbum.sharedInstance.saveImage(flippedImage)
self.imageView.image = flippedImage
}
self.dismissViewControllerAnimated(true, completion: nil)
}
代表中,在保存或显示之前再次翻转图像。
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import fl.video.*;
import flash.filters.*;
public class Main extends MovieClip
{
private var drukknopje1:knopje1;
private var drukknopje2:knopje2;
private var drukknopje3:knopje3;
private var drukknopje4:knopje4;
private var drukknopje5:knopje5;
private var drukknopje6:knopje6;
private var drukknopje7:knopje7;
private var drukknopje8:knopje8;
private var drukknopje9:knopje9;
private var drukknopje10:knopje10;
private const BUTTONS_NUM:int = 10;
private const BUTTONS_Y:int = 70;
private const BUTTONS_SUFFIX:String = 'inst_knop';
private const VIDEOS:Array = ['1.flv', '2.flv', '3.flv', '4.flv', '5.flv', '6.flv', '7.flv', '8.flv', '9.flv', '10.flv'];
private var videoclip:FLVPlayback = new FLVPlayback();
public function Main()
{
createButtons();
}
private function createButtons(): void
{
drukknopje1 = new knopje1();
drukknopje1.name = BUTTONS_SUFFIX + ('1');
drukknopje1.x = 0
drukknopje1.y = 0;
addChild(drukknopje1);
drukknopje1.buttonMode = true;
drukknopje1.addEventListener(MouseEvent.CLICK, playVideo);
drukknopje2 = new knopje2();
drukknopje2.name = BUTTONS_SUFFIX + ('2');
drukknopje2.x = 247 ;
drukknopje2.y = 0;
addChild(drukknopje2);
drukknopje2.buttonMode = true;
drukknopje2.addEventListener(MouseEvent.CLICK, playVideo);
drukknopje3 = new knopje3();
drukknopje3.name = BUTTONS_SUFFIX + ('3');
drukknopje3.x = 760;
drukknopje3.y = 0;
addChild(drukknopje3);
drukknopje3.buttonMode = true;
drukknopje3.addEventListener(MouseEvent.CLICK, playVideo);
drukknopje4 = new knopje4();
drukknopje4.name = BUTTONS_SUFFIX + ('4');
drukknopje4.x = 1489;
drukknopje4.y = 0;
addChild(drukknopje4);
drukknopje4.buttonMode = true;
drukknopje4.addEventListener(MouseEvent.CLICK, playVideo);
drukknopje5 = new knopje5();
drukknopje5.name = BUTTONS_SUFFIX + ('5');
drukknopje5.x = 461;
drukknopje5.y = 394;
addChild(drukknopje5);
drukknopje5.buttonMode = true;
drukknopje5.addEventListener(MouseEvent.CLICK, playVideo);
drukknopje6 = new knopje6();
drukknopje6.name = BUTTONS_SUFFIX + ('6');
drukknopje6.x = 898;
drukknopje6.y = 449 ;
addChild(drukknopje6);
drukknopje6.buttonMode = true;
drukknopje6.addEventListener(MouseEvent.CLICK, playVideo);
drukknopje7 = new knopje7();
drukknopje7.name = BUTTONS_SUFFIX + ('7');
drukknopje7.x = 0;
drukknopje7.y = 583;
addChild(drukknopje7);
drukknopje7.buttonMode = true;
drukknopje7.addEventListener(MouseEvent.CLICK, playVideo);
drukknopje8 = new knopje8();
drukknopje8.name = BUTTONS_SUFFIX + ('8');
drukknopje8.x = 444;
drukknopje8.y = 817;
addChild(drukknopje8);
drukknopje8.buttonMode = true;
drukknopje8.addEventListener(MouseEvent.CLICK, playVideo);
drukknopje9 = new knopje9();
drukknopje9.name = BUTTONS_SUFFIX + ('9');
drukknopje9.x = 450;
drukknopje9.y = 1375;
addChild(drukknopje9);
trace(drukknopje9.name);
trace(drukknopje9.x);
trace(drukknopje9.y);
drukknopje9.buttonMode = true;
drukknopje9.addEventListener(MouseEvent.CLICK, playVideo);
drukknopje10 = new knopje10();
drukknopje10.name = BUTTONS_SUFFIX + ('10');
drukknopje10.x = 418;
drukknopje10.y = 1920;
addChild(drukknopje10);
trace(drukknopje10.name);
trace(drukknopje10.x);
trace(drukknopje10.y);
drukknopje10.buttonMode = true;
drukknopje10.addEventListener(MouseEvent.CLICK, playVideo);
}
private function playVideo(event:MouseEvent):void
{
// get button's index, for example : 7 for the button called "inst_knop7"
var button_index:int = int((event.currentTarget.name).substr(BUTTONS_SUFFIX.length)) - 1;
// play the video
videoclip.x = (stage.stageWidth/2)-(videoclip.width/2);
videoclip.y = (stage.stageHeight/2)-(videoclip.height/2);
videoclip.width = 1024;
videoclip.height = 768;
videoclip.autoPlay = true;
videoclip.skin = "MinimaSilverPlayBackSeekMute.swf";
videoclip.addEventListener(Event.COMPLETE,videoComplete);
addChild(videoclip);
videoclip.play('video/' + VIDEOS[button_index]);
//trace ('video/' + VIDEOS[button_index])
}
private function videoComplete(event:Event):void
{
removeChild(videoclip);
}
}
}
答案 1 :(得分:0)
您可以优化代码来替换嵌套结构:
HEAD