在此先感謝。 我想將圖像視圖作爲覆蓋視圖添加到相機,並將(cameraview和圖像視圖)保存爲單個圖像。我搜索了它,並嘗試了在stackoverflow中給出的例子,但它沒有顯示任何東西比空白屏幕。如果任何人知道請幫助我。如何添加覆蓋視圖到cameraview並保存
0
A
回答
1
- (void)renderView:(UIView*)view inContext:(CGContextRef)context
{
// -renderInContext: renders in the coordinate space of the layer,
// so we must first apply the layer's geometry to the graphics context
CGContextSaveGState(context);
// Center the context around the window's anchor point
CGContextTranslateCTM(context, [view center].x, [view center].y);
// Apply the window's transform about the anchor point
CGContextConcatCTM(context, [view transform]);
// Offset by the portion of the bounds left of and above the anchor point
CGContextTranslateCTM(context,
-[view bounds].size.width * [[view layer] anchorPoint].x,
-[view bounds].size.height * [[view layer] anchorPoint].y);
// Render the layer hierarchy to the current context
[[view layer] renderInContext:context];
// Restore the context
CGContextRestoreGState(context);
}
// this get called when an image has been taken from the camera
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
//cameraImage = image;
CGSize imageSize = [[UIScreen mainScreen] bounds].size;
if (NULL != UIGraphicsBeginImageContextWithOptions)
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
else
UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// Draw the image returned by the camera sample buffer into the context.
// Draw it into the same sized rectangle as the view that is displayed on the screen.
float menubarUIOffset = 44.0;
UIGraphicsPushContext(context);
[image drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height-menubarUIOffset)];
UIGraphicsPopContext();
// Render the camera overlay view into the graphic context that we created above.
[self renderView:self.imagePicker.view inContext:context];
// Retrieve the screenshot image containing both the camera content and the overlay view
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);
UIGraphicsEndImageContext();
[self.imagePicker dismissModalViewControllerAnimated:YES];
}
希望這有助於
+0
@ 7kv7我沒有用相機選項高達現在的答案刻度線只要接受一些答案,我會嘗試。感謝ü爲你的迴應。 – 2011-04-11 09:10:02
+0
你可以嘗試使用UIImagePickerController。這將是一個更容易 – visakh7 2011-04-11 09:13:53
+0
雅我只使用它。 – 2011-04-11 09:29:50
相關問題
- 1. django ModelForm - 覆蓋保存()並將字段添加到self._meta.fields
- 2. 將CameraView中的圖像與覆蓋圖合併。 (Swift 3)?
- 3. 如何在android中的其他視圖添加覆蓋視圖?
- 4. 如何在Android視圖中添加半透明覆蓋圖?
- 5. 將透明覆蓋圖添加到選定的圖像視圖
- 6. 如何在Android應用程序中保存添加的Google地圖覆蓋圖?
- 7. 覆蓋保存方法或使用EF4添加保存事件
- 8. 加載欄覆蓋視圖
- 9. 將視圖控制器添加到容器視圖覆蓋視圖
- 10. 如何覆蓋生存圖
- 11. Android:添加覆蓋到MapView?
- 12. 添加視圖佈局覆蓋視圖ID
- 13. 在IPython中,如何保存並追加到文件而不是覆蓋它?
- 14. 如何將參數添加到方法並覆蓋子類
- 15. Django覆蓋保存
- 16. 添加覆蓋到Web視圖或相機中的Android
- 17. 如何將行添加到vim寄存器而不覆蓋它
- 18. Matlab:保存繪圖圖像,覆蓋plot.m
- 19. 檢查AVPlayer的播放狀態並將覆蓋視圖添加到AVPlayerViewController中
- 20. 覆蓋消息框並將圖標添加到默認按鈕
- 21. 在Python中保存並覆蓋變量
- 22. 如何覆蓋datetime.datetime,並保持它datetime.date
- 23. 添加一個覆蓋以UICollectionViewCell - 保持覆蓋
- 24. 添加更多元素到列表視圖「覆蓋」當前列表視圖
- 25. 如何將HTML添加到谷歌地圖作爲覆蓋
- 26. 覆蓋圖並保留2個X軸
- 27. 如何拍照並保存到DataBase並添加到ListView?
- 28. 如何顯示視圖覆蓋另一個視圖並更改視圖大小
- 29. 覆蓋CRUD視圖
- 30. 添加覆蓋JLabels
通過點擊對應於幫你 – visakh7 2011-04-11 09:50:58