From 5cf19469968c39b1e667e1f8bc99816646d9e6cd Mon Sep 17 00:00:00 2001 From: YangYuhao Date: Tue, 4 Jul 2023 16:01:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=20=E9=B2=81=E7=8F=AD=E5=8E=8B=E7=BC=A9=E4=B8=8D?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=9A=84=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- circle_app/lib/app/friendslist/view.dart | 3 +- circle_app/lib/app/minefragment/view.dart | 4 ++ circle_app/lib/util/qiniu.dart | 52 ++++++++++++++++++----- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/circle_app/lib/app/friendslist/view.dart b/circle_app/lib/app/friendslist/view.dart index 566f5a0..d81fd15 100644 --- a/circle_app/lib/app/friendslist/view.dart +++ b/circle_app/lib/app/friendslist/view.dart @@ -36,7 +36,7 @@ class FriendslistPage extends StatelessWidget { onRefresh: _onRefresh, onLoading: _onLoading, child: ListView.builder( - // padding: EdgeInsets.all(16.sp), + padding: EdgeInsets.all(10.sp), itemCount: logic.lists.length, itemBuilder: (context, index) { return ListItem(logic.lists[index]); @@ -70,6 +70,7 @@ class FriendslistPage extends StatelessWidget { }); }, child: CachedNetworkImage( + fit: BoxFit.cover, imageUrl: item.avatar, width: 53.sp, height: 53.sp, diff --git a/circle_app/lib/app/minefragment/view.dart b/circle_app/lib/app/minefragment/view.dart index 776195a..1b049cc 100644 --- a/circle_app/lib/app/minefragment/view.dart +++ b/circle_app/lib/app/minefragment/view.dart @@ -243,7 +243,10 @@ class MinefragmentPage extends StatelessWidget { GestureDetector( behavior: HitTestBehavior.opaque, onTap: ()async { + logic.like_me_count_new = 0; + logic.update(); if(null!=logic.like_me_count){ + SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setInt("likeMeCount", logic.like_me_count); } @@ -301,6 +304,7 @@ class MinefragmentPage extends StatelessWidget { GestureDetector( behavior: HitTestBehavior.opaque, onTap: () async{ + logic.recent_visit_count_new = 0; if(null!=logic.recent_visit_count){ SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setInt("recentVisitCount", logic.recent_visit_count); diff --git a/circle_app/lib/util/qiniu.dart b/circle_app/lib/util/qiniu.dart index 2e9861f..d2a55e9 100644 --- a/circle_app/lib/util/qiniu.dart +++ b/circle_app/lib/util/qiniu.dart @@ -12,6 +12,7 @@ import 'package:intl/intl.dart'; import '../common/config.dart'; import '../network/api.dart'; import '../network/dio_manager.dart'; +import 'package:image/image.dart' as img; typedef void MyCallback(String result); @@ -41,7 +42,13 @@ void updataQiniu(String filePath,String name,String path ,String quToken,MyCallb options: PutOptions(controller: putController, key: imgPath)); } +const List jpgSuffix = ["jpg", "jpeg", "JPG", "JPEG","png", "PNG"]; + +bool isImageJpgOrPng(String imagePath) { + String extension = imagePath.split('.').last.toLowerCase(); + return jpgSuffix.contains(extension) ; +} //封装上传图片 void upDataImage(String quToken ,XFile pickedFile,String updataRoute,MyCallback myCallback) async{ // print(quToken); @@ -60,20 +67,43 @@ void upDataImage(String quToken ,XFile pickedFile,String updataRoute,MyCallback } } var path = await getApplicationSupportDirectoryPath(); - - CompressObject compressObject = CompressObject( - imageFile:File(pickedFile.path), //image - path:path, //compress to path - quality: 80,//first compress quality, default 80 - step: 9,//compress quality step, The bigger the fast, Smaller is more accurate, default 6 - mode: CompressMode.LARGE2SMALL,//default AUTO - ); - Luban.compressImage(compressObject).then((_path) { - updataQiniu(_path.toString(),pickedFile.name,updataRoute,quToken,(result){ + if(isImageJpgOrPng(pickedFile.path)){ + CompressObject compressObject = CompressObject( + imageFile:File(pickedFile.path), //image + path:path, //compress to path + quality: 80,//first compress quality, default 80 + step: 9,//compress quality step, The bigger the fast, Smaller is more accurate, default 6 + mode: CompressMode.LARGE2SMALL,//default AUTO + ); + Luban.compressImage(compressObject).then((_path) { + updataQiniu(_path.toString(),pickedFile.name,updataRoute,quToken,(result){ + myCallback(result); + }); + }); + }else{ + updataQiniu(pickedFile.path,pickedFile.name,updataRoute,quToken,(result){ myCallback(result); }); - }); + } + +} + +void convertImageFormat(String imagePath, String outputPath, String outputFormat) { + // 读取原始图像文件 + final File inputFile = File(imagePath); + final List inputBytes = inputFile.readAsBytesSync(); + + // 解码图像 + final img.Image image = img.decodeImage(inputBytes)!; + + // 转换图像格式 + final img.Image convertedImage = img.copyResize(image, width: image.width, height: image.height); + final List? outputBytes = img.encodeNamedImage(convertedImage, outputFormat); + + // 写入转换后的图像文件 + final File outputFile = File(outputPath); + outputFile.writeAsBytesSync(outputBytes!); }