Commit 592bc5ed authored by 林生雨's avatar 林生雨

commit

parent 3636de24
This diff is collapsed.
...@@ -227,6 +227,7 @@ class GengmeiFlutterPlugin : MethodCallHandler { ...@@ -227,6 +227,7 @@ class GengmeiFlutterPlugin : MethodCallHandler {
}).addTo(disposable) }).addTo(disposable)
} }
QUIT_PAGE -> { QUIT_PAGE -> {
disposable.clear()
disposable.dispose() disposable.dispose()
disposable = CompositeDisposable() disposable = CompositeDisposable()
quit_page = true; quit_page = true;
...@@ -297,10 +298,22 @@ class GengmeiFlutterPlugin : MethodCallHandler { ...@@ -297,10 +298,22 @@ class GengmeiFlutterPlugin : MethodCallHandler {
} }
resign.addRequestPermissionsResultListener { id, permissions, grantResults -> resign.addRequestPermissionsResultListener { id, permissions, grantResults ->
if (grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED if (grantResults.size > 0) {
&& grantResults[2] == PackageManager.PERMISSION_GRANTED) { var givePremission = true;
listener.OK(); grantResults.forEach {
if (it != PackageManager.PERMISSION_GRANTED) {
givePremission = false;
}
}
if (givePremission) {
listener.OK()
} else {
Toast.makeText(activity.applicationContext, "请同意权限", Toast.LENGTH_SHORT).show()
result?.run {
this.error("没有权限!!", "no premission", "没有权限!!");
}
}
} else { } else {
Toast.makeText(activity.applicationContext, "请同意权限", Toast.LENGTH_SHORT).show() Toast.makeText(activity.applicationContext, "请同意权限", Toast.LENGTH_SHORT).show()
result?.run { result?.run {
......
...@@ -6,6 +6,7 @@ package com.example.myimagepicker.bean ...@@ -6,6 +6,7 @@ package com.example.myimagepicker.bean
*/ */
data class MediaFile( data class MediaFile(
var id: Int? = 0,
var path: String? = null, var path: String? = null,
var mime: String? = null, var mime: String? = null,
var folderId: Int? = null, var folderId: Int? = null,
...@@ -16,5 +17,7 @@ data class MediaFile( ...@@ -16,5 +17,7 @@ data class MediaFile(
var isBigIm: Boolean = false, var isBigIm: Boolean = false,
var bigScare: Float = 0f, var bigScare: Float = 0f,
var realPath: String? = null, var realPath: String? = null,
var isVideo: Boolean? = null var isVideo: Boolean? = null,
var width: Int? = 0,
var height: Int? = 0
) )
...@@ -24,7 +24,13 @@ class ImageScanner(var context: Context) : AbsMediaScanner<MediaFile>(context) { ...@@ -24,7 +24,13 @@ class ImageScanner(var context: Context) : AbsMediaScanner<MediaFile>(context) {
override val projection: Array<String> override val projection: Array<String>
get() = get() =
arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media.MIME_TYPE, MediaStore.Images.Media.BUCKET_ID, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE) arrayOf(MediaStore.Images.Media.DATA,
// MediaStore.Images.Media.MIME_TYPE,
// MediaStore.Images.Media.BUCKET_ID,
MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DATE_TAKEN,
MediaStore.Images.Media.SIZE,
MediaStore.Audio.Media._ID)
override val selection: String override val selection: String
get() = get() =
...@@ -46,41 +52,47 @@ class ImageScanner(var context: Context) : AbsMediaScanner<MediaFile>(context) { ...@@ -46,41 +52,47 @@ class ImageScanner(var context: Context) : AbsMediaScanner<MediaFile>(context) {
* @return * @return
*/ */
override fun parse(cursor: Cursor): MediaFile { override fun parse(cursor: Cursor): MediaFile {
val path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)) // val path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA))
val mime = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE)) // val mime = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE))
val folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID)) // val folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID))
val folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME)) // val folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME))
val dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN)) // val dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN))
val size = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.SIZE)) // val size = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.SIZE))
val mediaFile = MediaFile()
mediaFile.mime = mime val path = cursor.getString(0)
mediaFile.folderId = folderId val folderName = cursor.getString(1)
val dateToken = cursor.getLong(2)
val size = cursor.getLong(3)
val id = cursor.getInt(4);
val mediaFile = MediaFile()
mediaFile.id = id
// mediaFile.mime = mime
// mediaFile.folderId = folderId
mediaFile.folderName = folderName mediaFile.folderName = folderName
mediaFile.dateToken = dateToken mediaFile.dateToken = dateToken
mediaFile.size = size mediaFile.size = size
mediaFile.realPath = path mediaFile.realPath = path
mediaFile.isVideo = false mediaFile.isVideo = false
val dir = Environment.getExternalStorageDirectory().absolutePath + "/GMAlbum/.album"; // val dir = Environment.getExternalStorageDirectory().absolutePath + "/GMAlbum/.album";
// val dir = getImageCacheDir(context, Luban.DEFAULT_DISK_CACHE_DIR)!!.absolutePath; //// val dir = getImageCacheDir(context, Luban.DEFAULT_DISK_CACHE_DIR)!!.absolutePath;
val tempFilePngString = dir + "/" + getFileName(path)!! + ".png"; // val tempFilePngString = dir + "/" + getFileName(path)!! + ".png";
val tempFilePngExists = File(tempFilePngString).exists() // val tempFilePngExists = File(tempFilePngString).exists()
if (tempFilePngExists) { // if (tempFilePngExists) {
mediaFile.path = tempFilePngString; // mediaFile.path = tempFilePngString;
} // }
val tempFileJpgString = dir + "/" + getFileName(path)!! + ".jpg"; // val tempFileJpgString = dir + "/" + getFileName(path)!! + ".jpg";
val tempFileJpgExists = File(tempFileJpgString).exists() // val tempFileJpgExists = File(tempFileJpgString).exists()
if (tempFileJpgExists) { // if (tempFileJpgExists) {
mediaFile.path = tempFileJpgString; // mediaFile.path = tempFileJpgString;
} // }
val tempFileJpegString = dir + "/" + getFileName(path)!! + ".jpeg" // val tempFileJpegString = dir + "/" + getFileName(path)!! + ".jpeg"
val tempFileJpegExists = File(tempFileJpegString).exists() // val tempFileJpegExists = File(tempFileJpegString).exists()
if (tempFileJpegExists) { // if (tempFileJpegExists) {
mediaFile.path = tempFileJpegString; // mediaFile.path = tempFileJpegString;
} // }
if (size < 1024 * 160) { // if (size < 1024 * 160) {
mediaFile.path = path // mediaFile.path = path
} // }
// //
// if (it.size > 1024 * 1024 && !tempFilePngExists // if (it.size > 1024 * 1024 && !tempFilePngExists
// && !tempFileJpgExists && !tempFileJpegExists) { // && !tempFileJpgExists && !tempFileJpegExists) {
......
package com.example.gengmei_flutter_plugin.ImagePlugin.repository.local
/**
* @author lsy
* @date 2019-10-27
*/
class Thumb {
companion object{
}
}
\ No newline at end of file
package com.example.gengmei_flutter_plugin.ImagePlugin.repository.local;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.provider.MediaStore;
import android.util.Log;
import com.example.myimagepicker.bean.MediaFile;
import java.util.ArrayList;
import java.util.HashMap;
/**
* @author lsy
* @date 2019-10-27
*/
public class ThumbUtil {
public static ArrayList<MediaFile> getAllPictures(Context context) {
long st = System.currentTimeMillis();
ArrayList<MediaFile> scanList = new ArrayList<>();
ContentResolver cr = context.getContentResolver();
Cursor cursor = cr.query(
MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
new String[]{
MediaStore.Images.Thumbnails.IMAGE_ID,
MediaStore.Images.Thumbnails.DATA,
MediaStore.Images.Thumbnails.WIDTH,
MediaStore.Images.Thumbnails.HEIGHT,
},
null,
null,
null);
if (cursor != null && cursor.moveToFirst()) {
do {
MediaFile mediaFile = new MediaFile();
mediaFile.setId(cursor.getInt(0));
mediaFile.setPath(cursor.getString(1));
mediaFile.setWidth(cursor.getInt(2));
mediaFile.setHeight(cursor.getInt(3));
mediaFile.setVideo(false);
scanList.add(mediaFile);
} while (cursor.moveToNext());
cursor.close();
}
Log.e("lsy", " T1122 !! " + (System.currentTimeMillis() - st));
return scanList;
}
// public static ArrayList<MediaFile> getAllRealImages(Context context){
// ArrayList<MediaFile> scanList = new ArrayList<>();
// ContentResolver cr = context.getContentResolver();
// Cursor cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
// new String[]{
// MediaStore.Images.Media.DATA,
// MediaStore.Images.Media.MIME_TYPE,
// MediaStore.Images.Media.BUCKET_ID,
// MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
// MediaStore.Images.Media.DATE_TAKEN,
// MediaStore.Images.Media.SIZE,
// MediaStore.Audio.Media._ID
//
// },
// MediaStore.Audio.Media._ID + "=" + file.getId(),
// null,
// MediaStore.Images.Media.DATE_TAKEN +
// " DESC"
// );
//
//
// for (int i = 0; i < scanList.size(); i++) {
// MediaFile file = scanList.get(i);
//
// if (cursor.moveToFirst()) {
// do {
// String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
// String mime = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.MIME_TYPE));
// int folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_ID));
// String folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME));
// long dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN));
// long size = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Media.SIZE));
// long aLong = cursor.getLong(6);
// Log.e("lsy", " LONGGG " + aLong);
// file.setRealPath(path);
// file.setMime(mime);
// file.setFolderId(folderId);
// file.setFolderName(folderName);
// file.setDateToken(dateToken);
// file.setSize(size);
// scanList.set(i, file);
// } while (cursor.moveToNext());
// cursor.close();
// }
// }
// return scanList;
// }
public static ArrayList<MediaFile> getAllVideos(Context context) {
ArrayList<MediaFile> scanList = new ArrayList<>();
ContentResolver cr = context.getContentResolver();
Cursor cursor = cr.query(
MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
new String[]{
MediaStore.Video.Thumbnails.VIDEO_ID,
MediaStore.Video.Thumbnails.DATA,
MediaStore.Video.Thumbnails.WIDTH,
MediaStore.Video.Thumbnails.HEIGHT,
},
null,
null,
null);
if (cursor != null && cursor.moveToFirst()) {
do {
MediaFile mediaFile = new MediaFile();
mediaFile.setId(cursor.getInt(0));
mediaFile.setPath(cursor.getString(1));
mediaFile.setWidth(cursor.getInt(2));
mediaFile.setHeight(cursor.getInt(3));
scanList.add(mediaFile);
} while (cursor.moveToNext());
cursor.close();
}
// for (int i = 0; i < scanList.size(); i++) {
// MediaFile file = scanList.get(i);
// cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
// new String[]{
// MediaStore.Video.Media.DATA,
// MediaStore.Video.Media.MIME_TYPE,
// MediaStore.Video.Media.BUCKET_ID,
// MediaStore.Video.Media.BUCKET_DISPLAY_NAME,
// MediaStore.Video.Media.DURATION,
// MediaStore.Video.Media.DATE_TAKEN,
// MediaStore.Images.Media.SIZE
// },
// MediaStore.Audio.Media._ID + "=" + file.getId(),
// null,
// MediaStore.Images.Media.DATE_TAKEN +
// " DESC"
// );
// if (cursor.moveToFirst()) {
// do {
// String path = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA));
// String mime = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE));
// int folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_ID));
// String folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME));
// long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DURATION));
// long dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN));
// file.setRealPath(path);
// file.setMime(mime);
// file.setFolderId(folderId);
// file.setFolderName(folderName);
// file.setDateToken(dateToken);
// file.setDuration(duration);
// scanList.set(i, file);
// } while (cursor.moveToNext());
// cursor.close();
// }
// }
return scanList;
}
}
...@@ -5,6 +5,7 @@ import android.database.Cursor ...@@ -5,6 +5,7 @@ import android.database.Cursor
import android.net.Uri import android.net.Uri
import android.os.Environment import android.os.Environment
import android.provider.MediaStore import android.provider.MediaStore
import android.util.Log
import com.example.gengmei_flutter_plugin.utils.MyUtil import com.example.gengmei_flutter_plugin.utils.MyUtil
import com.example.myimagepicker.bean.MediaFile import com.example.myimagepicker.bean.MediaFile
import java.io.File import java.io.File
...@@ -22,14 +23,21 @@ class VideoScanner(private val mContext: Context) : AbsMediaScanner<MediaFile>(m ...@@ -22,14 +23,21 @@ class VideoScanner(private val mContext: Context) : AbsMediaScanner<MediaFile>(m
override val projection: Array<String> override val projection: Array<String>
get() = get() =
arrayOf(MediaStore.Video.Media.DATA, MediaStore.Video.Media.MIME_TYPE, MediaStore.Video.Media.BUCKET_ID, MediaStore.Video.Media.BUCKET_DISPLAY_NAME, MediaStore.Video.Media.DURATION, MediaStore.Video.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE arrayOf(MediaStore.Video.Media.DATA,
// MediaStore.Video.Media.MIME_TYPE,
// MediaStore.Video.Media.BUCKET_ID,
MediaStore.Video.Media.BUCKET_DISPLAY_NAME,
MediaStore.Video.Media.DURATION,
MediaStore.Video.Media.DATE_TAKEN,
MediaStore.Images.Media.SIZE,
MediaStore.Audio.Media._ID
) )
override val order: String override val order: String
get() = MediaStore.Video.Media.DATE_TAKEN + " desc" get() = MediaStore.Video.Media.DATE_TAKEN + " desc"
override val selectionArgs: Array<String>? override val selectionArgs: Array<String>?
// get() = null // get() = null
get() = arrayOf("video/mp4", "video/avi") get() = arrayOf("video/mp4", "video/avi")
override val selection: String override val selection: String
...@@ -45,38 +53,47 @@ class VideoScanner(private val mContext: Context) : AbsMediaScanner<MediaFile>(m ...@@ -45,38 +53,47 @@ class VideoScanner(private val mContext: Context) : AbsMediaScanner<MediaFile>(m
*/ */
protected override fun parse(cursor: Cursor): MediaFile { protected override fun parse(cursor: Cursor): MediaFile {
val path = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA)) // val path = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA))
val mime = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE)) // val mime = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE))
val folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_ID)) // val folderId = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_ID))
val folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME)) // val folderName = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME))
val duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DURATION)) // val duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DURATION))
val dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN)) // val dateToken = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DATE_TAKEN))
val path = cursor.getString(0)
val folderName = cursor.getString(1)
val duration = cursor.getLong(2)
val dateToken = cursor.getLong(3)
val size = cursor.getLong(4)
val id = cursor.getInt(5);
val mediaFile = MediaFile() val mediaFile = MediaFile()
mediaFile.realPath = path mediaFile.realPath = path
mediaFile.mime = mime // mediaFile.mime = mime
mediaFile.folderId = folderId // mediaFile.folderId = folderId
mediaFile.folderName = folderName mediaFile.folderName = folderName
mediaFile.duration = duration mediaFile.duration = duration
mediaFile.dateToken = dateToken mediaFile.dateToken = dateToken
mediaFile.isVideo=true mediaFile.isVideo = true
val dir = Environment.getExternalStorageDirectory().absolutePath + "/GMAlbum/.album" mediaFile.size=size
// val dir = getImageCacheDir(context, Luban.DEFAULT_DISK_CACHE_DIR)!!.absolutePath; mediaFile.id=id
val tempFilePngString = dir + "/" + MyUtil.getFileName(path)!! + ".png"; // val dir = Environment.getExternalStorageDirectory().absolutePath + "/GMAlbum/.album"
val tempFilePngExists = File(tempFilePngString).exists() //// val dir = getImageCacheDir(context, Luban.DEFAULT_DISK_CACHE_DIR)!!.absolutePath;
if (tempFilePngExists) { // val tempFilePngString = dir + "/" + MyUtil.getFileName(path)!! + ".png";
mediaFile.path = tempFilePngString; // val tempFilePngExists = File(tempFilePngString).exists()
} // if (tempFilePngExists) {
val tempFileJpgString = dir + "/" + MyUtil.getFileName(path)!! + ".jpg"; // mediaFile.path = tempFilePngString;
val tempFileJpgExists = File(tempFileJpgString).exists() // }
if (tempFileJpgExists) { // val tempFileJpgString = dir + "/" + MyUtil.getFileName(path)!! + ".jpg";
mediaFile.path = tempFileJpgString; // val tempFileJpgExists = File(tempFileJpgString).exists()
} // if (tempFileJpgExists) {
val tempFileJpegString = dir + "/" + MyUtil.getFileName(path)!! + ".jpeg" // mediaFile.path = tempFileJpgString;
val tempFileJpegExists = File(tempFileJpegString).exists() // }
if (tempFileJpegExists) { // val tempFileJpegString = dir + "/" + MyUtil.getFileName(path)!! + ".jpeg"
mediaFile.path = tempFileJpegString; // val tempFileJpegExists = File(tempFileJpegString).exists()
} // if (tempFileJpegExists) {
// mediaFile.path = tempFileJpegString;
// }
return mediaFile return mediaFile
} }
......
package com.example.gengmei_flutter_plugin.utils; package com.example.gengmei_flutter_plugin.utils;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log; import android.util.Log;
import java.io.File; import java.io.File;
...@@ -18,9 +20,8 @@ public class FileUtil { ...@@ -18,9 +20,8 @@ public class FileUtil {
if (fileNames.length > 0) { if (fileNames.length > 0) {
// directory // directory
File file = new File(newPath); File file = new File(newPath);
if (!file.mkdirs()) if (!file.mkdirs()) {
{ Log.d("mkdir", "can't make folder");
Log.d("mkdir","can't make folder");
} }
...@@ -47,7 +48,9 @@ public class FileUtil { ...@@ -47,7 +48,9 @@ public class FileUtil {
} }
} }
public static void copyAssetsFileToSD(Context context,String name, String predictorPath) {
public static void copyAssetsFileToSD(Context context, String name, String predictorPath) {
// File file = new File(predictorPath); // File file = new File(predictorPath);
// if (file.exists()) { // if (file.exists()) {
// return; // return;
......
...@@ -6,8 +6,11 @@ import com.example.myimagepicker.luban.Luban ...@@ -6,8 +6,11 @@ import com.example.myimagepicker.luban.Luban
import java.io.File import java.io.File
import android.media.ThumbnailUtils import android.media.ThumbnailUtils
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.DebugUtils import android.util.DebugUtils
import java.io.FileNotFoundException
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.IOException
import java.lang.Exception import java.lang.Exception
...@@ -77,6 +80,53 @@ class MyUtil { ...@@ -77,6 +80,53 @@ class MyUtil {
return filePath return filePath
} }
fun scareImg(imgPath: String, scareSize: Float, filePath: String, quality: Int): String {
val newOpts = BitmapFactory.Options()
// 开始读入图片,此时把options.inJustDecodeBounds 设回true,即只读边不读内容
newOpts.inJustDecodeBounds = true
newOpts.inPreferredConfig = Bitmap.Config.RGB_565
// 获取位图信息,但请注意位图现在为空
var bitmap = BitmapFactory.decodeFile(imgPath, newOpts)
newOpts.inJustDecodeBounds = false
val w = newOpts.outWidth
val h = newOpts.outHeight
val max = Math.max(w, h)
var scare = 1f
if (max > scareSize) {
scare = max / scareSize
}
// 想要缩放的目标尺寸,现在大部分手机都是1080*1920,参考值可以让宽高都缩小一倍
// float hh = w * scare;// 设置高度为960f时,可以明显看到图片缩小了
// float ww = h * scare;// 设置宽度为540f,可以明显看到图片缩小了
// // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
// int be = 1;// be=1表示不缩放
// if (w > h && w > ww) {// 如果宽度大的话根据宽度固定大小缩放
// be = (int) (newOpts.outWidth / ww);
// } else if (w < h && h > hh) {// 如果高度高的话根据宽度固定大小缩放
// be = (int) (newOpts.outHeight / hh);
// }
// if (be <= 0)
// be = 1;
newOpts.inSampleSize = scare.toInt()// 设置缩放比例
// 开始压缩图片,注意此时已经把options.inJustDecodeBounds 设回false了
bitmap = BitmapFactory.decodeFile(imgPath, newOpts)
val file = File(filePath)
try {
val out = FileOutputStream(file)
bitmap.compress(Bitmap.CompressFormat.PNG, quality, out)
out.flush()
out.close()
bitmap.recycle()
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
return filePath
}
} }
} }
...@@ -64,12 +64,8 @@ class AlbumModel { ...@@ -64,12 +64,8 @@ class AlbumModel {
if (key[i] == null) { if (key[i] == null) {
continue; continue;
} }
if (itemList[i].path == null) { itemList[i].path = key[i]["path"];
itemList[i].path = key[i]["path"]; itemList[i].realPath = key[i]["realPath"];
}
if (itemList[i].realPath == null) {
itemList[i].realPath = key[i]["realPath"];
}
} }
} }
}); });
......
...@@ -127,9 +127,9 @@ class AlbumState extends State<AlbumPage> { ...@@ -127,9 +127,9 @@ class AlbumState extends State<AlbumPage> {
} }
return GridView.builder( return GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3, crossAxisCount: 4,
crossAxisSpacing: 5, crossAxisSpacing: 1,
mainAxisSpacing: 5, mainAxisSpacing: 1,
childAspectRatio: 1), childAspectRatio: 1),
itemCount: imgList.data.length + 2, itemCount: imgList.data.length + 2,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
...@@ -204,6 +204,7 @@ class AlbumState extends State<AlbumPage> { ...@@ -204,6 +204,7 @@ class AlbumState extends State<AlbumPage> {
color: Colors.grey, color: Colors.grey,
size: 25, size: 25,
), ),
imgList.data[newIndex].isVideo?Icon(Icons.cancel,color: Colors.yellow,):Container(),
_model.isFullSelect() && !_model.isSelect(newIndex) _model.isFullSelect() && !_model.isSelect(newIndex)
? Container( ? Container(
width: double.maxFinite, width: double.maxFinite,
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/.dart_tool" /> <excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/.pub" /> <excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/build" /> <excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/gengmei_flutter_plugin/example/ios/Flutter/App.framework/flutter_assets/packages" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages" /> <excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages" />
</content> </content>
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
......
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