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

commit

parent 21f5511c
This diff is collapsed.
/*
* @author lsy
* @date 2019-10-14
**/
import 'package:flutter/material.dart';
enum RouteWay {
SCARE,
TRAN_RIGHT_TO_LEFT,
ALP,
}
class CustomRoute extends PageRouteBuilder {
final Widget widget;
RouteWay routeWay;
CustomRoute(this.widget, {RouteWay routeWay = RouteWay.TRAN_RIGHT_TO_LEFT})
: super(
// 设置过度时间
transitionDuration: Duration(milliseconds: 230),
// 构造器
pageBuilder: (
// 上下文和动画
BuildContext context,
Animation<double> animaton1,
Animation<double> animaton2,
) {
return widget;
},
transitionsBuilder: (
BuildContext context,
Animation<double> animaton1,
Animation<double> animaton2,
Widget child,
) {
// 渐变效果
if (routeWay.index == 2) {
return FadeTransition(
// 从0开始到1
opacity: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
// 传入设置的动画
parent: animaton1,
// 设置效果,快进漫出 这里有很多内置的效果
curve: Curves.fastOutSlowIn,
)),
child: child,
);
} else if (routeWay.index == 1) {
return SlideTransition(
position: Tween<Offset>(
begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0))
.animate(CurvedAnimation(
parent: animaton1, curve: Curves.fastOutSlowIn)),
child: child,
);
} else {
return ScaleTransition(
scale: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
parent: animaton1, curve: Curves.fastOutSlowIn)),
child: child,
);
}
// 旋转加缩放动画效果
// return RotationTransition(
// turns: Tween(begin: 0.0,end: 1.0)
// .animate(CurvedAnimation(
// parent: animaton1,
// curve: Curves.fastOutSlowIn,
// )),
// child: ScaleTransition(
// scale: Tween(begin: 0.0,end: 1.0)
// .animate(CurvedAnimation(
// parent: animaton1,
// curve: Curves.fastOutSlowIn
// )),
// child: child,
// ),
// );
});
}
......@@ -12,8 +12,11 @@ import 'package:gengmei_flutter_plugin/ScanImagePlugn.dart';
import 'package:gengmei_flutter_plugin/gengmei_flutter_plugin.dart';
import 'package:gengmei_flutter_plugin_example/AlbumModel/LiveData.dart';
import 'package:gengmei_flutter_plugin_example/AlbumModel/bean/DirBean.dart';
import 'package:gengmei_flutter_plugin_example/AlbumModel/page/preview/AlbumPreviewPage.dart';
import 'package:gengmei_flutter_plugin_example/AlbumModel/repository/AlbumRepository.dart';
import '../../Anim.dart';
const String MainDir = "IsGengmeiAlbumAllImages";
const String MainDirExplain = "全部相片";
......@@ -344,4 +347,38 @@ class AlbumModel {
showPop = false;
albumLive.notifyView(_mainValue[dirName]);
}
bool previewItemClick = false;
void previewItem(BuildContext context, int index, String pageName) {
String path;
if (Platform.isAndroid) {
path = albumLive.data[index].realPath;
Navigator.push(context, CustomRoute(AlbumPreviewPage(path, pageName)));
} else {
// Navigator.push(
// context, CustomRoute(AlbumPreviewPage(albumLive.data[index].path, pageName)));
if (previewItemClick) {
return;
}
previewItemClick = true;
path = albumLive.data[index].path;
iosItem(path, context, (value) {
var realPath = value["realImagePath"];
Navigator.push(
context, CustomRoute(AlbumPreviewPage(realPath, pageName)));
});
}
}
void iosItem(String path, BuildContext context, Function fun) {
GengmeiFlutterPlugin.ios_album_item(path).then((value) {
if (value != null) {
fun(Map<String, String>.from(value));
}
previewItemClick=false;
}).catchError((error) {
previewItemClick=false;
print(error);
});
}
}
......@@ -182,7 +182,10 @@ class AlbumState extends State<AlbumPage> {
return Container();
}
return GestureDetector(
onTap: () => _model.clickItem(context, newIndex),
onTap: (){
_model.previewItem(context, newIndex, "pageName");
// _model.clickItem(context, newIndex);
},
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
......
/*
* @author lsy
* @date 2019-11-01
**/
class AlbumPreviewModel {
final String imgPath;
AlbumPreviewModel(this.imgPath);
}
\ No newline at end of file
/*
* @author lsy
* @date 2019-11-01
**/
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:gengmei_flutter_plugin_example/AlbumModel/page/preview/AlbumPreviewModel.dart';
class AlbumPreviewPage extends StatefulWidget {
AlbumPreviewModel _model;
String fromPage;
AlbumPreviewPage(String imgPath, this.fromPage) {
_model = AlbumPreviewModel(imgPath);
}
@override
State<StatefulWidget> createState() => AlbumPreviewState(_model, fromPage);
}
class AlbumPreviewState extends State<AlbumPreviewPage> {
AlbumPreviewModel _model;
final String fromPage;
AlbumPreviewState(this._model, this.fromPage);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("test"),
),
body: ConstrainedBox(
constraints: BoxConstraints.expand(),
child: new Image.file(
File(
_model.imgPath,
),
fit: BoxFit.fitWidth,
)),
);
}
@override
String pageName() {
return "album_preview";
}
@override
String referrer() {
return fromPage;
}
}
......@@ -44,6 +44,7 @@ NSString *cacheDirectory;
assetCollectionList = [NSMutableArray array];
viewController =[UIApplication sharedApplication].delegate.window.rootViewController;
concurrentQueue = dispatch_queue_create("com.gengmei_flutter_plugin", DISPATCH_QUEUE_CONCURRENT);
// concurrentQueue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
queue = dispatch_queue_create("com.gengmei_flutter_plugin", DISPATCH_QUEUE_SERIAL);
FlutterEventChannel* chargingChannel = [FlutterEventChannel
eventChannelWithName:@"gengmei_flutter_plugin_event"
......@@ -295,31 +296,33 @@ NSString *cacheDirectory;
// }
//
// CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
[[PHImageManager defaultManager] requestImageDataForAsset:assets options:imageRequestOption resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
// [[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable res, NSDictionary * _Nullable info) {
dispatch_async(concurrentQueue, ^{
@autoreleasepool{
UIImage * res=[UIImage imageWithData:imageData];
NSData *data = UIImageJPEGRepresentation(res, 0.8) ;
[data writeToFile:tempTake atomically:YES];
res=nil;
data=nil;
}
NSMutableDictionary *dict=[[NSMutableDictionary alloc] init];
[dict setObject:path[i] forKey:@"path"];
[dict setObject:tempTake forKey:@"realImagePath"];
@synchronized (self) {
self.channelSize++;
[self.channelList addObject:dict];
}
if(self.channelSize==self.channelAllSize){
dispatch_async(dispatch_get_main_queue(), ^{
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :self.channelList];
});
}
});
}];
dispatch_async(concurrentQueue, ^{
[[PHImageManager defaultManager] requestImageDataForAsset:assets options:imageRequestOption resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
// [[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable res, NSDictionary * _Nullable info) {
dispatch_async(concurrentQueue, ^{
@autoreleasepool{
UIImage * res=[UIImage imageWithData:imageData];
NSData *data = UIImageJPEGRepresentation(res, 0.8) ;
[data writeToFile:tempTake atomically:YES];
res=nil;
data=nil;
}
NSMutableDictionary *dict=[[NSMutableDictionary alloc] init];
[dict setObject:path[i] forKey:@"path"];
[dict setObject:tempTake forKey:@"realImagePath"];
@synchronized (self) {
self.channelSize++;
[self.channelList addObject:dict];
}
if(self.channelSize==self.channelAllSize){
dispatch_async(dispatch_get_main_queue(), ^{
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :self.channelList];
});
}
});
}];
});
}
}
}else if ([[self.takePhotoMap allKeys] containsObject:path[i]]){
......@@ -350,7 +353,7 @@ NSString *cacheDirectory;
PHImageRequestOptions *imageRequestOption = [[PHImageRequestOptions alloc] init];
imageRequestOption.synchronous =NO;
imageRequestOption.networkAccessAllowed = YES;
imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeHighQualityFormat;
// imageRequestOption.deliveryMode=PHImageRequestOptionsDeliveryModeFastFormat;
imageRequestOption.resizeMode=PHImageRequestOptionsResizeModeFast;
imageRequestOption.version=PHImageRequestOptionsVersionUnadjusted;
NSString *tempPath = NSTemporaryDirectory();
......@@ -364,27 +367,38 @@ NSString *cacheDirectory;
[dict setObject:tempTake forKey:@"realImagePath"];
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :dict];
}else{
int picWidth=[assets pixelWidth];
int picHeight=[assets pixelHeight];
float tempScareSize=1;
float limit=1024.0;
float max=MAX(picWidth, picHeight);
if(max>limit){
tempScareSize=limit/max;
}
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
[[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
@autoreleasepool{
NSData *data = UIImageJPEGRepresentation(result, 1) ;
[data writeToFile:tempTake atomically:YES];
result=nil;
data=nil;
dispatch_async(queue, ^{
CFAbsoluteTime start=CFAbsoluteTimeGetCurrent();
int picWidth=[assets pixelWidth];
int picHeight=[assets pixelHeight];
float tempScareSize=1;
float limit=1024.0;
float max=MAX(picWidth, picHeight);
if(max>limit){
tempScareSize=limit/max;
}
NSMutableDictionary *dict=[[NSMutableDictionary alloc] init];
[dict setObject:path forKey:@"path"];
[dict setObject:tempTake forKey:@"realImagePath"];
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :dict];
}];
CGSize temp=CGSizeMake(picWidth*tempScareSize, picHeight*tempScareSize);
__block bool isResult=false;
[[PHImageManager defaultManager] requestImageForAsset:assets targetSize:temp contentMode:PHImageContentModeDefault options:imageRequestOption resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
if(isResult){
return ;
}
isResult=true;
@autoreleasepool{
NSData *data = UIImageJPEGRepresentation(result, 0.7) ;
[data writeToFile:tempTake atomically:YES];
// result=nil;
// data=nil;
}
NSMutableDictionary *dict=[[NSMutableDictionary alloc] init];
[dict setObject:path forKey:@"path"];
[dict setObject:tempTake forKey:@"realImagePath"];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"压缩预览图片耗时:%f ms",(CFAbsoluteTimeGetCurrent()-start)*1000);
[[ResultManager sharedSingleton] resultSuccess:[NSNumber numberWithLong:resultTemp] :dict];
});
}];
});
}
}else if ([[self.takePhotoMap allKeys] containsObject:path]){
NSMutableDictionary *dict=[[NSMutableDictionary alloc] init];
......
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