gpt4 book ai didi

ios - 如何将 UIImage 传递给 phonegap 以在图像控件中查看?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:47:55 24 4
gpt4 key购买 nike

我正在 IOS 中做一个图像处理应用程序。我已经在 objective-c native 应用程序中完成了基本的图像转换任务。现在我需要将它嵌入到 phonegap 插件应用程序中。假设我有一种方法可以从 phonegap 端获取图像(图像 url)到我的 native 插件。我现在将图像转换为灰度并将其作为 UIImage 返回。我想知道它应该如何转换并以一种可以发送到 phonegap 端并在图像控件中查看的方式传递。

谁能告诉我如何做到这一点。

最佳答案

您可以将图像转换为 base64,并将图像作为字符串发送给插件 successCallback。

以下是您可以执行的操作的基本实现

// EDPicturePlugin.h
@interface EDPicturePlugin : CDVPlugin <EDCameraControllerDelegate>
- (void)takePicture:(CDVInvokedUrlCommand*)command;
@end

// EDPicturePlugin.m
@interface EDPicturePlugin()

@property (nonatomic, retain) NSString *callbackID;

@end

@implementation EDPicturePlugin

- (void)takePicture:(CDVInvokeUrlCommand*)command
{
self.callbackID = command.callbackID;
EDCameraController *cameraController = [[EDCameraController alloc] init]
cameraController.delegate = self;
[self.viewController presentViewController:cameraController];
[cameraController release];
}

// EDCameraControllerDelegate
- (void)cameraController:(EDCameraController*)controller
didFinishTakingImageWithInfo:(NSDictionary*)info
{
UIImage *image = info[@"image"];
NSString *base64 = [NSString stringWithFormat:@"data:image/jpeg;base64",[UIImageJPEGRepresentation(image, 0.95) base64EncodedString];
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString:base64];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackID];
[callbackID release];
}

@end

关于ios - 如何将 UIImage 传递给 phonegap 以在图像控件中查看?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17674497/

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