小编bpo*_*lat的帖子

如何通过填写NSDictionary以JSON格式发送UIImage

我正在尝试使用JSON将数据发送到服务器.我可以用我的对象和关键参数创建我的NSDictionary.但我想发送我的照片,照片是UIImage.

 NSDictionary* mainJSON = [NSDictionary dictionaryWithObjectsAndKeys:
                          @"John",
                          @"First_Name",
                          @"McCintosh",
                          @"Last_name",
                          <HERE I WANT PICTURE>,
                          @"Profile_picture",
                          nil];

 // Here I convert to NSDATA 
 NSData * jsonData = [NSJSONSerialization dataWithJSONObject:mainJSON options:NSJSONWritingPrettyPrinted error:&error];

 // Sending operation :
 dispatch_async(kBgQueue, ^
                   {
                       NSData * data = [NSData dataWithContentsOfURL:@"addresSERVER"];
                       [self performSelectorOnMainThread:@selector(receivedResponseFromServer:)
                                              withObject:data
                                           waitUntilDone:YES];
                   }
                   );
Run Code Online (Sandbox Code Playgroud)

所以我想知道如何在NSDictionary中添加我的图片?因为我想发送我的照片的内容.如果我添加我的对象UIImage ...我会发送整个对象吗?

谢谢

iphone json objective-c ios xcode4

5
推荐指数
1
解决办法
1万
查看次数

如何在预览视图图层上设置相机大小

我使用下面的代码在iPhone设备上显示相机.相机可以显示UI,我可以拍照.但是,相机仅显示在previewLayer的中间.如何让相机填满AVCaptureVideoPreviewLayer上的所有空间?我试图使用AVLayerVideoGravityResizeAspectFill引力,但它会使图像变形.

self.session = AVCaptureSession()
        do {
            let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
            try self.videoInput = AVCaptureDeviceInput(device: device)
        } catch {

        }
        if ((self.session?.canSetSessionPreset(AVCaptureSessionPresetHigh)) != nil){
            self.session?.sessionPreset = AVCaptureSessionPresetHigh
        }
        self.stillImageOutput = AVCaptureStillImageOutput()

        self.stillImageOutput?.outputSettings = [AVVideoCodecKey:AVVideoCodecJPEG]
        if self.session!.canAddInput(self.videoInput){
            self.session?.addInput(self.videoInput)
        }
        if self.session!.canAddOutput(self.stillImageOutput){
            self.session?.addOutput(self.stillImageOutput)
        }

self.previewLayer = AVCaptureVideoPreviewLayer(session: self.session)
        //self.backView.frame = CGRectMake(0, 0, self.view.bounds.width,self.view.bounds.width)
        let viewLayer:CALayer = self.backView.layer
        viewLayer.masksToBounds = true
        let bounds:CGRect = viewLayer.bounds
        self.previewLayer?.frame = bounds
        self.previewLayer?.backgroundColor = UIColor.blackColor().CGColor
        self.previewLayer?.videoGravity = AVLayerVideoGravityResizeAspect//AVLayerVideoGravityResizeAspect
        self.backView.layer.addSublayer(self.previewLayer!)
Run Code Online (Sandbox Code Playgroud)

以下是相机的屏幕截图.

在此输入图像描述

ios swift

0
推荐指数
1
解决办法
1885
查看次数

标签 统计

ios ×2

iphone ×1

json ×1

objective-c ×1

swift ×1

xcode4 ×1