Kaynağa Gözat

添加一些常用滤镜

zengjiebin 7 yıl önce
ebeveyn
işleme
f0f95720a4

+ 1 - 0
app/proguard-rules.pro

@@ -152,6 +152,7 @@
 -keep class com.kfzs.duanduan.bean.** { *; }
 -keep class com.kfzs.duanduan.proto.** { *; }
 -keep class com.sheep.gamegroup.model.** { *; }
+-keep class com.sheep.gamegroup.module.*.model.** { *; }
 -keep class com.sheep.jiuyan.samllsheep.bean.** { *; }
 -keep class com.sheep.gamegroup.greendao.** { *; }
 -keep class com.jcodecraeer.** { *; }

+ 35 - 5
app/src/main/java/cn/finalteam/rxgalleryfinal/utils/MediaUtils.java

@@ -6,6 +6,8 @@ import android.content.ContentValues;
 import android.content.Context;
 import android.content.Intent;
 import android.database.Cursor;
+import android.graphics.BitmapFactory;
+import android.media.MediaMetadataRetriever;
 import android.net.Uri;
 import android.os.Build;
 import android.provider.MediaStore;
@@ -15,8 +17,10 @@ import android.text.TextUtils;
 import android.util.Log;
 import android.widget.Toast;
 
+import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
+import com.sheep.jiuyan.samllsheep.utils.FileUtil;
 import com.yalantis.ucrop.UCrop;
 
 import java.io.File;
@@ -80,8 +84,16 @@ public class MediaUtils {
             if (count > 0) {
                 cursor.moveToFirst();
                 do {
-                    MediaBean mediaBean = parseImageCursorAndCreateThumImage(context, cursor);
-                    mediaBeanList.add(mediaBean);
+                    MediaBean item = parseImageCursorAndCreateThumImage(context, cursor);
+                    mediaBeanList.add(item);
+                    //检查并重新设置宽高
+                    if (item != null && item.getOriginalPath() != null) {
+                        if (item.getHeight() <= 0 || item.getWidth() <= 0) {
+                            BitmapFactory.Options options = FileUtil.getImageOptions(item.getOriginalPath());
+                            item.setWidth(options.outWidth);
+                            item.setHeight(options.outHeight);
+                        }
+                    }
                 } while (cursor.moveToNext());
             }
         }
@@ -135,8 +147,26 @@ public class MediaUtils {
             if (count > 0) {
                 cursor.moveToFirst();
                 do {
-                    MediaBean mediaBean = parseVideoCursorAndCreateThumImage(context, cursor);
-                    mediaBeanList.add(mediaBean);
+                    MediaBean item = parseVideoCursorAndCreateThumImage(context, cursor);
+                    mediaBeanList.add(item);
+                    //检查并重新设置宽高
+                    if (item != null && item.getOriginalPath() != null) {
+                        if (item.getHeight() <= 0 || item.getWidth() <= 0) {
+                            try {
+
+                            MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
+                            metadataRetriever.setDataSource(SheepApp.getInstance(), Uri.parse(item.getOriginalPath()));
+                            String width = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH); // 视频宽度
+                            String height = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT); // 视频高度
+//                            String rotation = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION); // 视频旋转方向
+
+                            item.setWidth(Float.valueOf(width).intValue());
+                            item.setHeight(Float.valueOf(height).intValue());
+                            } catch (Exception e){
+                                LogUtil.println("getMediaWithVideoList", e.getMessage());
+                            }
+                        }
+                    }
                 } while (cursor.moveToNext());
             }
         }
@@ -467,7 +497,7 @@ public class MediaUtils {
             Uri uri = SheepApp.getInstance().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
             captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
         }
-        if(!isImage){
+        if (!isImage) {
             captureIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 15000L);
         }
         // video : 1: 高质量  0 低质量

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/module/find/activity/ActEditVideo.java

@@ -19,8 +19,8 @@ import android.widget.SeekBar;
 import com.kfzs.duanduan.utils.StatusBarUtils;
 import com.sheep.gamegroup.absBase.AbsObserver;
 import com.sheep.gamegroup.absBase.BaseContainerActivity;
-import com.sheep.gamegroup.module.find.bean.Filterble;
-import com.sheep.gamegroup.module.find.bean.IFilter;
+import com.sheep.gamegroup.module.find.util.Filterble;
+import com.sheep.gamegroup.module.find.util.IFilter;
 import com.sheep.gamegroup.module.find.bean.Size;
 import com.sheep.gamegroup.module.find.fragment.FgtChooseEditList;
 import com.sheep.gamegroup.model.entity.Video;

+ 65 - 0
app/src/main/java/com/sheep/gamegroup/module/find/bean/BeautifyFilter.java

@@ -0,0 +1,65 @@
+package com.sheep.gamegroup.module.find.bean;
+
+import com.sheep.gamegroup.module.find.util.IFilter;
+
+import java.util.Locale;
+
+/**
+ * Created by realicing on 2018/12/4.
+ * realicing@sina.com
+ * 美化
+ */
+public class BeautifyFilter implements IFilter {
+
+    private String name;
+
+    public BeautifyFilter(String name) {
+        this.name = name;
+    }
+
+    private int type = 1;
+    private int width = 480;
+    private int height = 640;
+
+    public int getType() {
+        return type;
+    }
+
+    public BeautifyFilter setType(int type) {
+        this.type = type;
+        return this;
+    }
+
+    public int getWidth() {
+        return width;
+    }
+
+    public BeautifyFilter setWidth(int width) {
+        this.width = width;
+        return this;
+    }
+
+    public int getHeight() {
+        return height;
+    }
+
+    public BeautifyFilter setHeight(int height) {
+        this.height = height;
+        return this;
+    }
+
+    public BeautifyFilter setName(String name) {
+        this.name = name;
+        return this;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getConfig() {
+        return String.format(Locale.CHINA, "@beautify face %d %d %d", type, width, height);
+    }
+}

+ 3 - 2
app/src/main/java/com/sheep/gamegroup/module/find/bean/ColorBalanceFilter.java

@@ -1,5 +1,7 @@
 package com.sheep.gamegroup.module.find.bean;
 
+import com.sheep.gamegroup.module.find.util.IFilter;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -52,7 +54,7 @@ public class ColorBalanceFilter implements IFilter {
 
     @Override
     public String getConfig() {
-        return String.format(Locale.CHINA, "@adjust colorbalance %.2f %.2f %.2f ", red, green, blue);
+        return String.format(Locale.CHINA, "@adjust colorbalance %.2f %.2f %.2f", red, green, blue);
     }
 
 
@@ -69,7 +71,6 @@ public class ColorBalanceFilter implements IFilter {
     //添加默认滤镜列表
     public static List<IFilter> getDefaultFilterList() {
         List<IFilter> filterList = new ArrayList<>();
-        filterList.add(new ColorBalanceFilter("原图"));
         filterList.add(new ColorBalanceFilter("蓝色").setBlue(255));
         filterList.add(new ColorBalanceFilter("红色").setRed(255));
         filterList.add(new ColorBalanceFilter("黄色").setYellow(255));

+ 37 - 0
app/src/main/java/com/sheep/gamegroup/module/find/bean/Filter.java

@@ -0,0 +1,37 @@
+package com.sheep.gamegroup.module.find.bean;
+
+import com.sheep.gamegroup.module.find.util.IFilter;
+
+
+/**
+ * Created by realicing on 2018/12/4.
+ * realicing@sina.com
+ */
+public class Filter implements IFilter {
+    private String name;
+    private String config = "";
+
+    public Filter(String name) {
+        this.name = name;
+    }
+
+    public Filter setName(String name) {
+        this.name = name;
+        return this;
+    }
+
+    public Filter setConfig(String config) {
+        this.config = config;
+        return this;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getConfig() {
+        return config;
+    }
+}

+ 59 - 0
app/src/main/java/com/sheep/gamegroup/module/find/bean/WaveFilter.java

@@ -0,0 +1,59 @@
+package com.sheep.gamegroup.module.find.bean;
+
+import android.text.TextUtils;
+
+import com.sheep.gamegroup.module.find.util.IFilter;
+
+import java.util.Locale;
+
+/**
+ * Created by realicing on 2018/12/4.
+ * realicing@sina.com
+ * 波浪滤镜
+ */
+public class WaveFilter implements IFilter {
+
+    private String name;
+    private String type = "#unpack";
+
+    public WaveFilter(String name) {
+        this.name = name;
+    }
+    private float percent = 0.5f;
+
+    public float getPercent() {
+        return percent;
+    }
+
+    public WaveFilter setPercent(float percent) {
+        this.percent = percent;
+        return this;
+    }
+
+    public WaveFilter setName(String name) {
+        this.name = name;
+        return this;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public WaveFilter setType(String type) {
+        this.type = type;
+        return this;
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public String getConfig() {
+        if(TextUtils.isEmpty(type)){
+            return String.format(Locale.CHINA, "@dynamic wave %.1f", percent);
+        }
+        return String.format(Locale.CHINA, "%s @dynamic wave %.1f", type , percent);
+    }
+}

+ 21 - 4
app/src/main/java/com/sheep/gamegroup/module/find/fragment/FgtChooseEditList.java

@@ -1,6 +1,6 @@
 package com.sheep.gamegroup.module.find.fragment;
 
-import android.support.v7.widget.GridLayoutManager;
+import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.view.View;
 import android.widget.ImageView;
@@ -8,10 +8,15 @@ import android.widget.SeekBar;
 
 import com.chad.library.adapter.base.BaseQuickAdapter;
 import com.chad.library.adapter.base.BaseViewHolder;
+import com.sheep.gamegroup.model.entity.Lp;
+import com.sheep.gamegroup.module.find.bean.BeautifyFilter;
 import com.sheep.gamegroup.module.find.bean.ColorBalanceFilter;
-import com.sheep.gamegroup.module.find.bean.Filterble;
-import com.sheep.gamegroup.module.find.bean.IFilter;
+import com.sheep.gamegroup.module.find.bean.Filter;
+import com.sheep.gamegroup.module.find.bean.WaveFilter;
+import com.sheep.gamegroup.module.find.util.Filterble;
+import com.sheep.gamegroup.module.find.util.IFilter;
 import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.gamegroup.util.viewHelper.LayoutParamsUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.base.BaseFragment;
@@ -50,12 +55,24 @@ public class FgtChooseEditList extends BaseFragment {
 
     private List<IFilter> filterList = new ArrayList<>();
 
+    private int width;
     private void initView() {
+        filterList.add(new Filter("原图"));
         ColorBalanceFilter.addDefaultFilterList(filterList);
-        recyclerView.setLayoutManager(new GridLayoutManager(SheepApp.getInstance(), filterList.size()));
+        filterList.add(new BeautifyFilter("美化").setWidth(G.WIDTH).setHeight(G.HEIGHT));
+        filterList.add(new WaveFilter("波浪").setPercent(1).setType(null));
+        filterList.add(new Filter("浮雕").setConfig("#unpack @style emboss 1 2 2"));
+        filterList.add(new Filter("半色调").setConfig("@style halftone 1.2"));
+        filterList.add(new Filter("暴光").setConfig("@adjust exposure 0.98"));
+        filterList.add(new Filter("阴影高亮").setConfig("@adjust shadowhighlight -200 200"));
+        filterList.add(new Filter("锐化").setConfig("@adjust sharpen 10 1.5"));
+//        filterList.add(new Filter("").setConfig(""));
+        width = (G.WIDTH - recyclerView.getPaddingStart() - recyclerView.getPaddingEnd() / 2) / 5;
+        recyclerView.setLayoutManager(new LinearLayoutManager(SheepApp.getInstance(), LinearLayoutManager.HORIZONTAL, false));
         recyclerView.setAdapter(new BaseQuickAdapter<IFilter, BaseViewHolder>(R.layout.item_tv_iv, filterList) {
             @Override
             protected void convert(BaseViewHolder helper, final IFilter item) {
+                LayoutParamsUtil.resetLayoutParams(helper.itemView, new Lp().setWidth(width));
                 helper.setText(R.id.item_tv, item.getName());
                 ImageView item_iv = helper.getView(R.id.item_iv);
                 ViewUtil.setImage(item_iv, item);

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/module/find/bean/Filterble.java

@@ -1,4 +1,4 @@
-package com.sheep.gamegroup.module.find.bean;
+package com.sheep.gamegroup.module.find.util;
 
 /**
  * Created by realicing on 2018/12/4.

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/module/find/bean/IFilter.java

@@ -1,4 +1,4 @@
-package com.sheep.gamegroup.module.find.bean;
+package com.sheep.gamegroup.module.find.util;
 
 /**
  * Created by realicing on 2018/12/3.

+ 29 - 21
app/src/main/java/com/sheep/gamegroup/util/MediaMetadataRetrieverUtil.java

@@ -3,6 +3,7 @@ package com.sheep.gamegroup.util;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.media.MediaMetadataRetriever;
+import android.net.Uri;
 import android.support.v7.widget.GridLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.widget.ImageView;
@@ -154,26 +155,32 @@ public class MediaMetadataRetrieverUtil {
         if (duration < size || size < 1) {
             return null;
         }
-        long per = duration * 1000L / (size - 1);
-        List<Bitmap> resultList = new ArrayList<>();
-        long time = System.currentTimeMillis();
-        MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
-        metadataRetriever.setDataSource(fromFile);
-        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
-            MediaMetadataRetriever.BitmapParams bitmapParams = new MediaMetadataRetriever.BitmapParams();
-            Bitmap.Config config = Bitmap.Config.ARGB_8888;
-            bitmapParams.setPreferredConfig(config);
-            return metadataRetriever.getFramesAtIndex(0, size, bitmapParams);
-        }
-        for (int i = 0; i < size; i++) {
-            //这里单位为微秒
-            long atTime = i + 1 == size ? (duration * 1000L) : i * per;
-            Bitmap bitmap = metadataRetriever.getFrameAtTime(atTime, MediaMetadataRetriever.OPTION_CLOSEST);
-            resultList.add(bitmap);
+        try {
+            long per = duration * 1000L / (size - 1);
+            List<Bitmap> resultList = new ArrayList<>();
+            long time = System.currentTimeMillis();
+            MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
+            metadataRetriever.setDataSource(SheepApp.getInstance(), Uri.parse(fromFile));
+            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
+                MediaMetadataRetriever.BitmapParams bitmapParams = new MediaMetadataRetriever.BitmapParams();
+                Bitmap.Config config = Bitmap.Config.ARGB_8888;
+                bitmapParams.setPreferredConfig(config);
+                return metadataRetriever.getFramesAtIndex(0, size, bitmapParams);
+            }
+            for (int i = 0; i < size; i++) {
+                //这里单位为微秒
+                long atTime = i + 1 == size ? (duration * 1000L) : i * per;
+                Bitmap bitmap = metadataRetriever.getFrameAtTime(atTime, MediaMetadataRetriever.OPTION_CLOSEST);
+                resultList.add(bitmap);
+            }
+            long curTime = System.currentTimeMillis();
+            LogUtil.println(TAG, time, curTime, curTime - time, (curTime - time) / 1000, (curTime - time) / 10000);
+            return resultList;
+        }catch (Exception e){
+            e.printStackTrace();
+            LogUtil.println(MediaMetadataRetrieverUtil.class.getSimpleName(), "getFrameBitmapList", e.getMessage());
         }
-        long curTime = System.currentTimeMillis();
-        LogUtil.println(TAG, time, curTime, curTime - time, (curTime - time) / 1000, (curTime - time) / 10000);
-        return resultList;
+        return null;
     }
 
     /**
@@ -193,7 +200,7 @@ public class MediaMetadataRetrieverUtil {
         List<String> resultList = new ArrayList<>();
         long time = System.currentTimeMillis();
         MediaMetadataRetriever metadataRetriever = new MediaMetadataRetriever();
-        metadataRetriever.setDataSource(fromFile);
+        metadataRetriever.setDataSource(SheepApp.getInstance(), Uri.parse(fromFile));
 
         for (int i = 0; i < size; i++) {
             //这里单位为微秒
@@ -216,8 +223,9 @@ public class MediaMetadataRetrieverUtil {
                         e.printStackTrace();
                     }
                 }
+                if(bitmap != null)
+                    bitmap.recycle();
             }
-            bitmap.recycle();
         }
         long curTime = System.currentTimeMillis();
         LogUtil.println(TAG, time, curTime, curTime - time, (curTime - time) / 1000, (curTime - time) / 10000);

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/util/TestUtil.java

@@ -31,7 +31,7 @@ import com.kfzs.duanduan.utils.ApkUtils;
 import com.kfzs.duanduan.view.DialogStorageLow;
 import com.sheep.gamegroup.absBase.AbsObserver;
 import com.sheep.gamegroup.module.find.bean.ColorBalanceFilter;
-import com.sheep.gamegroup.module.find.bean.IFilter;
+import com.sheep.gamegroup.module.find.util.IFilter;
 import com.sheep.gamegroup.model.entity.BaseMessage;
 import com.sheep.gamegroup.model.entity.CreditCard;
 import com.sheep.gamegroup.model.entity.DialogConfig;

+ 3 - 3
app/src/main/java/com/sheep/gamegroup/util/TimeUtil.java

@@ -241,11 +241,11 @@ public class TimeUtil {
 
     public static String getDurationText(long duration) {
         if(duration > 3600)
-            return String.format(Locale.CHINA, "%d:%d:%d", duration / 3600, duration / 60 % 60, duration % 60);
+            return String.format(Locale.CHINA, "%d:%02d:%02d", duration / 3600, duration / 60 % 60, duration % 60);
         else if(duration > 60)
-            return String.format(Locale.CHINA, "%d:%d", duration / 60, duration % 60);
+            return String.format(Locale.CHINA, "%d:%02d", duration / 60, duration % 60);
         else if(duration > 0)
-            return String.format(Locale.CHINA, "%d:%d", 0, duration % 60);
+            return String.format(Locale.CHINA, "%d:%02d", 0, duration % 60);
         else
             return "00:01";
     }

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/util/ViewUtil.java

@@ -62,7 +62,7 @@ import com.sheep.gamegroup.absBase.IContentTypeContainer;
 import com.sheep.gamegroup.absBase.ITag;
 import com.sheep.gamegroup.dateview.DatePickerDialog;
 import com.sheep.gamegroup.dateview.DateUtil;
-import com.sheep.gamegroup.module.find.bean.IFilter;
+import com.sheep.gamegroup.module.find.util.IFilter;
 import com.sheep.gamegroup.model.entity.Advertising;
 import com.sheep.gamegroup.model.entity.Container;
 import com.sheep.gamegroup.model.entity.DialogConfig;

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/util/glide/FilterTransform.java

@@ -5,7 +5,7 @@ import android.support.annotation.NonNull;
 
 import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
 import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
-import com.sheep.gamegroup.module.find.bean.IFilter;
+import com.sheep.gamegroup.module.find.util.IFilter;
 
 import org.wysaid.nativePort.CGENativeLibrary;
 

+ 10 - 1
app/src/main/java/com/sheep/jiuyan/samllsheep/utils/FileUtil.java

@@ -112,13 +112,22 @@ public class FileUtil {
      * @return
      */
     public static BitmapFactory.Options getImageOptions(File file) {
+        return getImageOptions(file.getAbsolutePath());
+    }
+
+    /**
+     * 获取图片配置信息
+     * @param filePath
+     * @return
+     */
+    public static BitmapFactory.Options getImageOptions(String filePath) {
         BitmapFactory.Options options = new BitmapFactory.Options();
         /**
          * 最关键在此,把options.inJustDecodeBounds = true;
          * 这里再decodeFile(),返回的bitmap为空,但此时调用options.outHeight时,已经包含了图片的高了
          */
         options.inJustDecodeBounds = true;
-        BitmapFactory.decodeFile(file.getAbsolutePath(), options); // 此时返回的bitmap为null
+        BitmapFactory.decodeFile(filePath, options); // 此时返回的bitmap为null
         return options;
     }
     /**

+ 3 - 3
app/src/main/res/layout/item_my_list_but.xml

@@ -20,10 +20,10 @@
             android:id="@+id/my_item_img"
             android:layout_width="match_parent"
             android:layout_height="0dp"
-            android:minHeight="56dp"
+            android:minHeight="46dp"
             android:layout_weight="1"
-            android:paddingTop="10dp"
-            android:paddingBottom="10dp"
+            android:paddingTop="5dp"
+            android:paddingBottom="5dp"
             android:paddingStart="20dp"
             android:paddingEnd="20dp"
             android:scaleType="fitCenter"