gpt4 book ai didi

iphone - iPhone 相机 View 上的实时水印图像

转载 作者:行者123 更新时间:2023-12-03 19:15:13 24 4
gpt4 key购买 nike

提前特别感谢......我是iphone软件开发的初学者。

只是寻找如何使用 cocoa 以编程方式将实时水印图像添​​加到相机 View 中。不是一步一步地寻找(虽然那会很棒),而是或多或少地寻找我应该从哪里开始学习如何。是否有为此开发的框架?想要一些使用 XCode 框架的 Objective-C 原生的东西,因为我想最终在 iPhone 上尝试一下。任何帮助都会很棒。

最佳答案

更新:这是我关于如何将此叠加 View 放在相机动画下的另一个答案:camera overlay view - just for preview?

Helo Rajendra!

我创建了一个简单的基于 Windows 的 iPhone 操作系统应用程序,为您提供一个非常简单的示例,说明如何以及如何使用相机拍摄照片、在相机模式下覆盖 View 、调整图像大小和合并图像。该项目实际上只有 AppDelegate 头文件和实现文件,可以在 XCode 中轻松复制。

这是头文件:

//
// CameraWatermarkAppDelegate.h
// CameraWatermark
//
// Created by Ivan Karpan on 1/16/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface CameraWatermarkAppDelegate : NSObject < UIApplicationDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate > {
UIImageView *imageView;
UIViewController *viewController;
UIWindow *window;
}

@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIViewController *viewController;
@property (nonatomic, retain) IBOutlet UIWindow *window;


@end

这是实现文件:

//
// CameraWatermarkAppDelegate.m
// CameraWatermark
//
// Created by Ivan Karpan on 1/16/10.
// Copyright __MyCompanyName__ 2010. All rights reserved.
//

#import "CameraWatermarkAppDelegate.h"


const float WATERMARK_ALPHA = 0.5;


@implementation CameraWatermarkAppDelegate

@synthesize imageView, viewController, window;


- (void)applicationDidFinishLaunching:(UIApplication *)application {
self.viewController = [[UIViewController new] autorelease];
viewController.view.backgroundColor = [UIColor blackColor];

// An image view to save to (and therefore display) the captured image
self.imageView = [[UIImageView new] autorelease];
imageView.frame = viewController.view.frame;
[viewController.view addSubview:imageView];

[window addSubview:viewController.view];

UIImagePickerController *anImagePickerController = [UIImagePickerController new];
anImagePickerController.delegate = self;
anImagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

{// This block of code is only needed in case you want your watermark to be displayed also during the shooting process
UIImageView *anImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Watermark.png"]];
anImageView.alpha = WATERMARK_ALPHA;
anImageView.contentMode = UIViewContentModeTopLeft;
anImageView.frame = viewController.view.frame;
anImagePickerController.cameraOverlayView = anImageView;
[anImageView release];
}

// From the very beginning we simply present the image picker controller
[viewController presentModalViewController:anImagePickerController animated:NO];
[anImagePickerController release];
}


- (void)dealloc {
[imageView release];
[viewController release];
[window release];
[super dealloc];
}

#pragma mark UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIGraphicsBeginImageContext(CGSizeMake(320, 480));
// This is where we resize captured image
[(UIImage *)[info objectForKey:UIImagePickerControllerOriginalImage] drawInRect:CGRectMake(0, 0, 320, 480)];
// And add the watermark on top of it
[[UIImage imageNamed:@"Watermark.png"] drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeNormal alpha:WATERMARK_ALPHA];
// Save the results directly to the image view property
imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Dismiss the image picker controller and look at the results
[picker dismissModalViewControllerAnimated:YES];
}


@end

我希望这可以作为您的起点。

关于iphone - iPhone 相机 View 上的实时水印图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2076456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com