Commit a67a1ed3 authored by 林生雨's avatar 林生雨

commit

parent 3f010139
This diff is collapsed.
...@@ -123,6 +123,8 @@ class HOME extends StatefulWidget { ...@@ -123,6 +123,8 @@ class HOME extends StatefulWidget {
} }
class HOMESTATE extends State<HOME> { class HOMESTATE extends State<HOME> {
String imagePath;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// TODO: implement build // TODO: implement build
...@@ -130,12 +132,23 @@ class HOMESTATE extends State<HOME> { ...@@ -130,12 +132,23 @@ class HOMESTATE extends State<HOME> {
body: GestureDetector( body: GestureDetector(
onTap: () { onTap: () {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => AlbumPage(false, 10, null))); builder: (context) => AlbumPage(false, 10, null)))
.then((value) {
setState(() {
imagePath = value;
});
}).catchError((error) {
print(error);
});
}, },
child: Center( child: Container(
child: Text("wwwwwwww"), width: 200,
height: 200,
color: Colors.yellow,
child:
imagePath == null ? Text("www") : Image.file(File(imagePath)),
))); )));
} }
} }
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
#import <Photos/Photos.h> #import <Photos/Photos.h>
#import "Image/AlbumItem.h" #import "Image/AlbumItem.h"
#import "ResultManager.h" #import "ResultManager.h"
#import <ImageIO/ImageIO.h>
@interface GengmeiFlutterPlugin () <UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,FlutterStreamHandler> //一定要声明这三个协议,缺一不可 @interface GengmeiFlutterPlugin () <UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,FlutterStreamHandler> //一定要声明这三个协议,缺一不可
//@property(nonatomic)FlutterResult result; //@property(nonatomic)FlutterResult result;
@property(atomic)int needSize; @property(atomic)int needSize;
@property(nonatomic)int nowSize; @property(atomic)int nowSize;
@property(atomic)int copySize; @property(atomic)int copySize;
@property(nonatomic)int tempSize;
@property(nonatomic) long resultKey; @property(nonatomic) long resultKey;
@property(nonatomic)long nativeCameraKey; @property(nonatomic)long nativeCameraKey;
@property(strong,atomic)NSMutableDictionary<NSString*,NSMutableArray<NSMutableDictionary<NSString*,NSObject*>*>*>* finalMap; @property(strong,atomic)NSMutableDictionary<NSString*,NSMutableArray<NSMutableDictionary<NSString*,NSObject*>*>*>* finalMap;
...@@ -385,16 +385,32 @@ FlutterEventSink _eventSink; ...@@ -385,16 +385,32 @@ FlutterEventSink _eventSink;
imageRequestOption.synchronous =NO; imageRequestOption.synchronous =NO;
int picWidth=[assets pixelWidth]; int picWidth=[assets pixelWidth];
int picHeight=[assets pixelHeight]; int picHeight=[assets pixelHeight];
float tempScareSize=320.0/picWidth; float tempScareSize=1;
if(picWidth>picHeight){
if (picWidth>320.0) {
tempScareSize=320.0/picWidth;
}
}else{
if (picHeight>320.0) {
tempScareSize=320.0/picHeight;
}
}
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize); CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
imageRequestOption.networkAccessAllowed = YES; imageRequestOption.networkAccessAllowed = YES;
imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat; imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeHighQualityFormat;
//PHImageRequestOptionsDeliveryModeHighQualityFormat。//PHImageRequestOptionsDeliveryModeFastFormat
// imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat; // imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat;
imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast; imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast;
imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted; imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted;
//PHImageManagerMaximumSize //PHImageManagerMaximumSize
[[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { [[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
[UIImageJPEGRepresentation(result,1) writeToFile:tmpPath atomically:YES]; @autoreleasepool{
NSData *data = UIImageJPEGRepresentation(result, 0.7) ;
[data writeToFile:tmpPath atomically:YES];
data=nil;
result=nil;
}
// [UIImageJPEGRepresentation(result,1) writeToFile:tmpPath atomically:YES];
// [UIImageJPEGRepresentation([self image:result byScalingToSize:temp],0.8) writeToFile:realPath atomically:YES ]; // [UIImageJPEGRepresentation([self image:result byScalingToSize:temp],0.8) writeToFile:realPath atomically:YES ];
NSMutableDictionary* queryItemDict = [NSMutableDictionary dictionary]; NSMutableDictionary* queryItemDict = [NSMutableDictionary dictionary];
[queryItemDict setObject:tmpPath forKey:@"path"]; [queryItemDict setObject:tmpPath forKey:@"path"];
...@@ -408,35 +424,10 @@ FlutterEventSink _eventSink; ...@@ -408,35 +424,10 @@ FlutterEventSink _eventSink;
[self.finalMap[docName] addObject:queryItemDict]; [self.finalMap[docName] addObject:queryItemDict];
} }
NSLog(@"SCARE SIZEEE %d %d ",self.nowSize,self.needSize); NSLog(@"SCARE SIZEEE %d %d ",self.nowSize,self.needSize);
result=nil;
if (self.nowSize==self.needSize) { if (self.nowSize==self.needSize) {
[self resultImgs:resultId]; [self resultImgs:resultId];
} }
// if ([[NSFileManager defaultManager] createFileAtPath:realPath contents:data attributes:nil]) {
// if ([[NSFileManager defaultManager] createFileAtPath:tmpPath contents:scareData attributes:nil]) {
// NSLog(@"result %@",tmpPath);
// self.nowSize++;
// NSMutableDictionary* queryItemDict = [NSMutableDictionary dictionary];
// [queryItemDict setObject:tmpPath forKey:@"path"];
// [queryItemDict setObject:realPath forKey:@"realPath"];
// NSMutableArray * arr=self.finalMap[docName];
// if (arr==nil) {
// self.finalMap[docName]=[NSMutableArray array];
// [self.finalMap[docName] addObject:queryItemDict];
// }else{
// [self.finalMap[docName] addObject:queryItemDict];
// }
// NSLog(@"SIZEEE %d %d ",self.nowSize,self.needSize);
// if (self.nowSize==self.needSize) {
// [self resultImgs:resultId];
// }
// }else{
// NSLog(@"ERRORRRR ");
// self.needSize--;
// }
// } else {
// NSLog(@"ERRORRRR ");
// self.needSize--;
// }
}]; }];
} }
} }
...@@ -467,6 +458,7 @@ FlutterEventSink _eventSink; ...@@ -467,6 +458,7 @@ FlutterEventSink _eventSink;
__block NSString *tmpPath=[cacheDirectory stringByAppendingPathComponent:imgName]; __block NSString *tmpPath=[cacheDirectory stringByAppendingPathComponent:imgName];
if ([fileManager fileExistsAtPath:realPath]==YES){ if ([fileManager fileExistsAtPath:realPath]==YES){
self.nowSize++; self.nowSize++;
NSLog(@"!!!REAL IS EXIE!! %@",realPath);
NSMutableArray<NSMutableDictionary<NSString*,NSObject*>*>* array=self.finalMap[docName]; NSMutableArray<NSMutableDictionary<NSString*,NSObject*>*>* array=self.finalMap[docName];
for (int x=0; x<[array count]; x++) { for (int x=0; x<[array count]; x++) {
NSMutableDictionary<NSString*,NSObject*>* map=[array objectAtIndex:x]; NSMutableDictionary<NSString*,NSObject*>* map=[array objectAtIndex:x];
...@@ -484,23 +476,31 @@ FlutterEventSink _eventSink; ...@@ -484,23 +476,31 @@ FlutterEventSink _eventSink;
}else{ }else{
NSLog(@"file NOT EXIT !! "); NSLog(@"file NOT EXIT !! ");
PHImageRequestOptions *imageRequestOption = [[PHImageRequestOptions alloc] init]; PHImageRequestOptions *imageRequestOption = [[PHImageRequestOptions alloc] init];
imageRequestOption.synchronous =YES; imageRequestOption.synchronous =NO;
int picWidth=[assets pixelWidth]; int picWidth=[assets pixelWidth];
int picHeight=[assets pixelHeight]; int picHeight=[assets pixelHeight];
float tempScareSize; float tempScareSize=1;
if(picWidth>1080.0){ float limit=2160.0;
tempScareSize=1080.0/picWidth; if(picWidth>picHeight){
if (picWidth>limit) {
tempScareSize=limit/picWidth;
}
}else{ }else{
tempScareSize=1; if (picHeight>limit) {
tempScareSize=limit/picHeight;
}
} }
NSLog(@"SCARE SZIE %d %d %f %f %f",picWidth,picHeight,tempScareSize,picWidth*tempScareSize,picHeight*tempScareSize);
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize); CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
imageRequestOption.networkAccessAllowed = YES; imageRequestOption.networkAccessAllowed = YES;
imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeHighQualityFormat; imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeHighQualityFormat;
// imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat; // imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat;
imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast; imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast;
imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted; imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted;
[[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) { [[PHImageManager defaultManager] requestImageDataForAsset:assets options:imageRequestOption resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
[UIImageJPEGRepresentation(result,1) writeToFile:realPath atomically:YES]; // UIImage *image = [UIImage imageWithData:imageData];
[imageData writeToFile:realPath atomically:YES];
//获取照片 image
self.nowSize++; self.nowSize++;
self.copySize++; self.copySize++;
NSMutableArray<NSMutableDictionary<NSString*,NSObject*>*>* array=self.finalMap[docName]; NSMutableArray<NSMutableDictionary<NSString*,NSObject*>*>* array=self.finalMap[docName];
...@@ -513,10 +513,11 @@ FlutterEventSink _eventSink; ...@@ -513,10 +513,11 @@ FlutterEventSink _eventSink;
} }
} }
NSLog(@"SIZEEE %d %d %d",self.nowSize,self.needSize,self.copySize); NSLog(@"SIZEEE %d %d %d",self.nowSize,self.needSize,self.copySize);
// result=nil;
if (self.nowSize==self.needSize) { if (self.nowSize==self.needSize) {
[self upImgs]; [self upImgs];
self.execdTask=true; self.execdTask=true;
}else if(self.copySize%15==0){ }else if(self.copySize%30==0){
NSLog(@"UPPP!!"); NSLog(@"UPPP!!");
[self upImgs]; [self upImgs];
} }
...@@ -526,6 +527,21 @@ FlutterEventSink _eventSink; ...@@ -526,6 +527,21 @@ FlutterEventSink _eventSink;
} }
} }
-(void)writeImage:(UIImage *)image dest:(NSString*)path{
@autoreleasepool {
CFURLRef url=(__bridge CFURLRef)[NSURL fileURLWithPath:path];
CGImageDestinationRef des=CGImageDestinationCreateWithURL(url, CFSTR("public.png"), 1, NULL);
if(!des){
NSLog(@"wrong");
return;
}
CGImageDestinationAddImage(des, image.CGImage, nil);
if(!CGImageDestinationFinalize(des)){
NSLog(@"wrong222");
}
CFRelease(des);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment