如何在ios中更改截图插件中的图像路径

时间:2014-12-27 11:05:46

标签: android ios objective-c cordova

我正在使用" cordova插件添加https://github.com/gitawego/cordova-screenshot.git"

在我的项目中使用ScreenShort插件

在android中它将图像保存在Pictures.But中,它保存在临时文件夹中。如何在ios中将图像从临时文件夹更改为摄像机角色。 这是我的Screenshot.m

`#import <Cordova/CDV.h>
#import "Screenshot.h"

@implementation Screenshot

@synthesize webView;

 - (void)saveScreenshot:(CDVInvokedUrlCommand*)command
{
    NSString *filename = [command.arguments objectAtIndex:2];
    NSNumber *quality = [command.arguments objectAtIndex:1];
    NSString *path = [NSString stringWithFormat:@"%@.jpg",filename];

    NSString *jpgPath = [NSTemporaryDirectory() stringByAppendingPathComponent:path ];
    CGRect imageRect;
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    // statusBarOrientation is more reliable than UIDevice.orientation
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        // landscape check
        imageRect = CGRectMake(0, 0, CGRectGetHeight(screenRect), CGRectGetWidth(screenRect));
    } else {
        // portrait check
        imageRect = CGRectMake(0, 0, CGRectGetWidth(screenRect), CGRectGetHeight(screenRect));
    }

    // Adds support for Retina Display. Code reverts back to original if iOs 4 not detected.
    if (NULL != UIGraphicsBeginImageContextWithOptions)
        UIGraphicsBeginImageContextWithOptions(imageRect.size, NO, 0);
    else
        UIGraphicsBeginImageContext(imageRect.size);

    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor blackColor] set];
    CGContextTranslateCTM(ctx, 0, 0);
    CGContextFillRect(ctx, imageRect);

    [webView.layer renderInContext:ctx];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    NSData *imageData = UIImageJPEGRepresentation(image,[quality floatValue]);
    [imageData writeToFile:jpgPath atomically:NO];
    UIGraphicsEndImageContext();
    CDVPluginResult* pluginResult = nil;
    NSDictionary *jsonObj = [ [NSDictionary alloc]
        initWithObjectsAndKeys :
        jpgPath, @"filePath",
        @"true", @"success",
        nil
        ];

    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:jsonObj];
    [self writeJavascript:[pluginResult toSuccessCallbackString:command.callbackId]];
}

@end

` 如何改变路径

0 个答案:

没有答案