我正在尝试使用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设备上显示相机.相机可以显示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)
以下是相机的屏幕截图.