照片增加裁剪

This commit is contained in:
976623696@qq.com 2020-12-30 19:04:53 +08:00
parent 47da7a7c29
commit 6d76d1defe
3 changed files with 25 additions and 0 deletions

View File

@ -21,6 +21,10 @@
@property(nonatomic, assign) int nDefaultFlash;
@property(nonatomic, assign) BOOL bSwitchFlash;
@property(nonatomic, assign) int targetWidth;
@property(nonatomic, assign) int targetHeight;
@property(nonatomic, assign) int nDefaultCamera;
@property(nonatomic, assign) BOOL bSwitchCamera;

View File

@ -12,6 +12,8 @@
@synthesize strCameraBGColor;
@synthesize strCameraPressedBG;
@synthesize fQuality;
@synthesize targetWidth;
@synthesize targetHeight;
@synthesize bOpacity;
@synthesize nDefaultFlash;
@synthesize bSwitchFlash;
@ -46,11 +48,17 @@
fQuality = [[command argumentAtIndex:0] intValue];
targetWidth = [[command argumentAtIndex:3] intValue];
targetHeight = [[command argumentAtIndex:4] intValue];
bOpacity = false; //[[command argumentAtIndex:7] boolValue];
nDefaultFlash = 2; //[[command argumentAtIndex:8] intValue];
bSwitchFlash = true; //[[command argumentAtIndex:9] boolValue];
nDefaultCamera = 0; //[[command argumentAtIndex:10] intValue];
bSwitchCamera = true; //[[command argumentAtIndex:11] boolValue];
}
return self;
}

View File

@ -515,6 +515,19 @@ static NSString* toBase64(NSData* data) {
@autoreleasepool {
if (image) {
if (nDestType == 0) {
CDVPictureOptions* options = [CDVPictureOptions createFromTakePictureArguments:command];
UIImage* scaledImage = nil;
if ((options.targetSize.width > 0) && (options.targetSize.height > 0)) {
// if cropToSize, resize image and crop to target size, otherwise resize to fit target without cropping
if (options.cropToSize) {
scaledImage = [image imageByScalingAndCroppingForSize:options.targetSize];
} else {
scaledImage = [image imageByScalingNotCroppingForSize:options.targetSize];
}
}
image= (scaledImage == nil ? image : scaledImage);
NSData *imageData = UIImageJPEGRepresentation(image, quality / 100);
NSString *strEncodeData = [imageData base64EncodedStringWithOptions:0];