修改上传图片 鲁班压缩不支持的图片
This commit is contained in:
parent
a0e4428f15
commit
5cf1946996
@ -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,
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<String> 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<int> 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<int>? outputBytes = img.encodeNamedImage(convertedImage, outputFormat);
|
||||
|
||||
// 写入转换后的图像文件
|
||||
final File outputFile = File(outputPath);
|
||||
outputFile.writeAsBytesSync(outputBytes!);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user