diff --git a/app/build.gradle b/app/build.gradle index a884bc2..1023689 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,6 @@ android { noCompress 'tflite' } } - dependencies { implementation 'androidx.appcompat:appcompat:1.3.1' diff --git a/app/src/main/java/com/echo/colorizeit/ui/f_gallery_view/GalleryFragment.java b/app/src/main/java/com/echo/colorizeit/ui/f_gallery_view/GalleryFragment.java index 5019734..5dda2ca 100644 --- a/app/src/main/java/com/echo/colorizeit/ui/f_gallery_view/GalleryFragment.java +++ b/app/src/main/java/com/echo/colorizeit/ui/f_gallery_view/GalleryFragment.java @@ -62,19 +62,19 @@ public class GalleryFragment extends BaseFragment { } }); RecyclerView image_gallery = binding.rcGallery; - StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); +// StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); adapter = new ImageAdapter(getRcImageList()); - image_gallery.setLayoutManager(layoutManager); +// image_gallery.setLayoutManager(layoutManager); image_gallery.setAdapter(adapter); - layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE); +// layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE); //防止item 交换位置 - image_gallery.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { - super.onScrollStateChanged(recyclerView, newState); - layoutManager.invalidateSpanAssignments(); //防止第一行到顶部有空白区域 - } - }); +// image_gallery.addOnScrollListener(new RecyclerView.OnScrollListener() { +// @Override +// public void onScrollStateChanged(RecyclerView recyclerView, int newState) { +// super.onScrollStateChanged(recyclerView, newState); +// layoutManager.invalidateSpanAssignments(); //防止第一行到顶部有空白区域 +// } +// }); return root; diff --git a/app/src/main/java/com/echo/colorizeit/ui/f_gallery_view/ImageAdapter.java b/app/src/main/java/com/echo/colorizeit/ui/f_gallery_view/ImageAdapter.java index 933e8a5..89509b7 100644 --- a/app/src/main/java/com/echo/colorizeit/ui/f_gallery_view/ImageAdapter.java +++ b/app/src/main/java/com/echo/colorizeit/ui/f_gallery_view/ImageAdapter.java @@ -1,6 +1,12 @@ package com.echo.colorizeit.ui.f_gallery_view; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.net.Uri; +import android.provider.MediaStore; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -13,7 +19,10 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import com.echo.colorizeit.ImageUtil.rcImage; +import com.echo.colorizeit.ui.a_image_upload_activity.ImageUploadViewActivity; +import com.echo.photo_editor.photo_editor_view.PhotoEditorView; import com.example.myapplication.R; +import com.google.android.material.snackbar.Snackbar; import java.util.List; @@ -59,13 +68,80 @@ public class ImageAdapter extends RecyclerView.Adapter } }); holder.Image.startAnimation(animation_fade_in); + holder.Image.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(holder.Image.getContext(), PhotoEditorView.class); + intent.putExtra("sourceFilePath", image.getImgPath()); + holder.Image.getContext().startActivity(intent); + } + }); + holder.Edit_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(holder.Image.getContext(), PhotoEditorView.class); + intent.putExtra("sourceFilePath", image.getImgPath()); + holder.Image.getContext().startActivity(intent); + } + }); + holder.Share_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Bitmap tmp = BitmapFactory.decodeFile(image.getImgPath()); + String data = MediaStore.Images.Media.insertImage(holder.Image.getContext().getContentResolver(), tmp, String.valueOf(System.currentTimeMillis()), ":)"); + while (data == null) { + try { + Thread.sleep(1); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + Uri ColorizedImageUri = Uri.parse(data); + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_SEND); + intent.setType("image/*"); + intent.putExtra(Intent.EXTRA_STREAM, ColorizedImageUri); + intent.putExtra(Intent.EXTRA_SUBJECT, "Share");//添加分享内容标题 + intent = Intent.createChooser(intent, "Share"); + holder.Image.getContext().startActivity(intent); + } + }); + holder.Save_button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Bitmap tmp = BitmapFactory.decodeFile(image.getImgPath()); + String data = MediaStore.Images.Media.insertImage(holder.Image.getContext().getContentResolver(), tmp, String.valueOf(System.currentTimeMillis()), ":)"); + final AlertDialog.Builder alterDialog = new AlertDialog.Builder(holder.Image.getContext()); + + alterDialog.setTitle("Image saved successfully.");//文字 + alterDialog.setMessage("You can view it in your gallery.");//提示消息 + alterDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Intent intent = new Intent(); + intent.setAction(android.content.Intent.ACTION_VIEW); + intent.setType("image/*"); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + holder.Image.getContext().startActivity(intent); + } + }); + + alterDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }); + alterDialog.show(); + } + }); + // new Handler().postDelayed(new Runnable() { // @Override // public void run() { // holder.Image.startAnimation(animation_fade_in); // } // }, position); - holder.Name.setText(image.getImgName()); } @Override @@ -75,13 +151,17 @@ public class ImageAdapter extends RecyclerView.Adapter static class ViewHolder extends RecyclerView.ViewHolder{ ImageView Image; - TextView Name; + ImageView Share_button; + ImageView Edit_button; + ImageView Save_button; public ViewHolder (View view) { super(view); Image = (ImageView) view.findViewById(R.id.rc_image_view); - Name = (TextView) view.findViewById(R.id.rc_image_name); + Share_button = view.findViewById(R.id.gallery_share_button); + Edit_button = view.findViewById(R.id.gallery_edit_button); + Save_button = view.findViewById(R.id.gallery_save_button); } } diff --git a/app/src/main/res/drawable/gallery_background.xml b/app/src/main/res/drawable/gallery_background.xml new file mode 100644 index 0000000..5a6f564 --- /dev/null +++ b/app/src/main/res/drawable/gallery_background.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_baseline_edit_24.xml b/app/src/main/res/drawable/ic_baseline_edit_24.xml new file mode 100644 index 0000000..073cea7 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_edit_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_save_alt_24.xml b/app/src/main/res/drawable/ic_baseline_save_alt_24.xml new file mode 100644 index 0000000..a16ed18 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_save_alt_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_baseline_share_24.xml b/app/src/main/res/drawable/ic_baseline_share_24.xml new file mode 100644 index 0000000..311fc23 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_share_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/fragment_clarity_enhancement.xml b/app/src/main/res/layout/fragment_clarity_enhancement.xml index f1c95b4..1f13c46 100644 --- a/app/src/main/res/layout/fragment_clarity_enhancement.xml +++ b/app/src/main/res/layout/fragment_clarity_enhancement.xml @@ -4,6 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + android:padding="0dp" tools:context="com.echo.colorizeit.ui.f_gallery_view.GalleryFragment"> \ No newline at end of file diff --git a/app/src/main/res/layout/rcimage_item.xml b/app/src/main/res/layout/rcimage_item.xml index 9aa6242..cd5ba6f 100644 --- a/app/src/main/res/layout/rcimage_item.xml +++ b/app/src/main/res/layout/rcimage_item.xml @@ -5,6 +5,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" + android:layout_margin="8dp" + android:background="@drawable/gallery_background" android:hapticFeedbackEnabled="false" android:orientation="vertical" android:paddingStart="8dp" @@ -13,27 +15,50 @@ + app:srcCompat="@drawable/black_demo_image" /> + + - + app:layout_constraintTop_toTopOf="@+id/gallery_share_button" + app:srcCompat="@drawable/ic_baseline_edit_24" /> + + \ No newline at end of file diff --git a/photoEditor_test/src/main/java/com/echo/appliaction_test/MainActivity.java b/photoEditor_test/src/main/java/com/echo/appliaction_test/MainActivity.java index 9167ec2..ac71122 100644 --- a/photoEditor_test/src/main/java/com/echo/appliaction_test/MainActivity.java +++ b/photoEditor_test/src/main/java/com/echo/appliaction_test/MainActivity.java @@ -36,10 +36,10 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); binding = ActivityMainBinding.inflate(getLayoutInflater()); //-----------------------------TEST Image------------------------------- -// sourceFilePath = "/storage/emulated/0/Pictures/Colorized Image (26).jpg"; -// Intent intent = new Intent(_this, PhotoEditorView.class); -// intent.putExtra("sourceFilePath", sourceFilePath); -// startActivity(intent); + sourceFilePath = "/storage/emulated/0/Pictures/Colorized Image (26).jpg"; + Intent intent = new Intent(_this, PhotoEditorView.class); + intent.putExtra("sourceFilePath", sourceFilePath); + startActivity(intent); setContentView(binding.getRoot()); TextView textView = binding.textView2; TextView textView1 = binding.textView3; diff --git a/photo_editor/build.gradle b/photo_editor/build.gradle index 874a6d1..d44e4e9 100644 --- a/photo_editor/build.gradle +++ b/photo_editor/build.gradle @@ -59,6 +59,8 @@ dependencies { implementation 'io.github.lucksiege:pictureselector:v2.7.3-rc07' implementation 'com.github.bumptech.glide:glide:4.9.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' + implementation group: 'com.baidu.aip', name: 'java-sdk', version: '4.15.0' implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly' implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly' + implementation 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' } \ No newline at end of file diff --git a/photo_editor/src/main/java/com/echo/photo_editor/ML/BaiduImageAPI.java b/photo_editor/src/main/java/com/echo/photo_editor/ML/BaiduImageAPI.java new file mode 100644 index 0000000..cd3ff80 --- /dev/null +++ b/photo_editor/src/main/java/com/echo/photo_editor/ML/BaiduImageAPI.java @@ -0,0 +1,219 @@ +package com.echo.photo_editor.ML; + +import android.content.Context; +import android.graphics.Bitmap; +import android.util.Log; + +import com.baidu.aip.imageprocess.AipImageProcess; +import com.echo.photo_editor.util.PhotoLib; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.HashMap; + +public class BaiduImageAPI { + //设置APPID/AK/SK + public static final String APP_ID = "24778510"; + public static final String API_KEY = "z2Uw0ij41KQLxlfNmbs9X4YZ"; + public static final String SECRET_KEY = "wIiKlRQjQA9XG40ivhPwcl89E40FP8TU"; + public Context context; + + public BaiduImageAPI(Context context) { + this.context = context; + } + + + public void styleTrans(RequestsListener listener, String imagePath, styleTransTypes style) { + new Thread(() -> { + AipImageProcess client = NewClient(); + // 传入可选参数调用接口 + HashMap options = new HashMap(); + options.put("option", style.toString()); + JSONObject res = client.styleTrans(imagePath, options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + public void styleTrans(RequestsListener listener, Bitmap image, styleTransTypes style) { + new Thread(() -> { + AipImageProcess client = NewClient(); + // 传入可选参数调用接口 + HashMap options = new HashMap(); + options.put("option", style.toString()); + + JSONObject res = client.styleTrans(PhotoLib.saveImageTmp(context, image), options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + + public void dehaze(RequestsListener listener, String imagePath) { + new Thread(() -> { + AipImageProcess client = NewClient(); + HashMap options = new HashMap(); + + JSONObject res = client.dehaze(imagePath, options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + public void dehaze(RequestsListener listener, Bitmap image) { + new Thread(() -> { + AipImageProcess client = NewClient(); + HashMap options = new HashMap(); + + JSONObject res = client.dehaze(PhotoLib.saveImageTmp(context, image), options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + + public void contrastEnhance(RequestsListener listener, String imagePath) { + new Thread(() -> { + AipImageProcess client = NewClient(); + HashMap options = new HashMap(); + + JSONObject res = client.contrastEnhance(imagePath, options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + public void contrastEnhance(RequestsListener listener, Bitmap image) { + new Thread(() -> { + AipImageProcess client = NewClient(); + HashMap options = new HashMap(); + + JSONObject res = client.contrastEnhance(PhotoLib.saveImageTmp(context, image), options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + + public void colourize(RequestsListener listener, String imagePath) { + new Thread(() -> { + AipImageProcess client = NewClient(); + HashMap options = new HashMap(); + JSONObject res = client.colourize(imagePath, options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + + public void selfieAnime(RequestsListener listener, String imagePath) { + new Thread(() -> { + AipImageProcess client = NewClient(); + HashMap options = new HashMap(); + + JSONObject res = client.selfieAnime(imagePath, options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + public void selfieAnime(RequestsListener listener, Bitmap image) { + new Thread(() -> { + AipImageProcess client = NewClient(); + HashMap options = new HashMap(); + + JSONObject res = client.selfieAnime(PhotoLib.saveImageTmp(context, image), options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + + public void imageDefinitionEnhance(RequestsListener listener, String imagePath) { + new Thread(() -> { + AipImageProcess client = NewClient(); + HashMap options = new HashMap(); + + JSONObject res = client.imageDefinitionEnhance(imagePath, options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + public void imageDefinitionEnhance(RequestsListener listener, byte[] image) { + new Thread(() -> { + AipImageProcess client = NewClient(); + HashMap options = new HashMap(); + + JSONObject res = client.imageDefinitionEnhance(image, options); + try { + Log.d("INFO", String.valueOf(res)); + String ImgData = res.getString("image"); + listener.success(ImgData); + } catch (JSONException e) { + listener.failure(e.toString()); + e.printStackTrace(); + } + }).start(); + } + + private AipImageProcess NewClient(){ + AipImageProcess client; + client = new AipImageProcess(APP_ID, API_KEY, SECRET_KEY); + client.setConnectionTimeoutInMillis(2000); + client.setSocketTimeoutInMillis(60000); + return client; + } + +} diff --git a/photo_editor/src/main/java/com/echo/photo_editor/ML/RequestsListener.java b/photo_editor/src/main/java/com/echo/photo_editor/ML/RequestsListener.java new file mode 100644 index 0000000..53ca48d --- /dev/null +++ b/photo_editor/src/main/java/com/echo/photo_editor/ML/RequestsListener.java @@ -0,0 +1,6 @@ +package com.echo.photo_editor.ML; + +public interface RequestsListener { + void success(String data); + void failure(String info); +} diff --git a/photo_editor/src/main/java/com/echo/photo_editor/ML/styleTransTypes.java b/photo_editor/src/main/java/com/echo/photo_editor/ML/styleTransTypes.java new file mode 100644 index 0000000..df2f59e --- /dev/null +++ b/photo_editor/src/main/java/com/echo/photo_editor/ML/styleTransTypes.java @@ -0,0 +1,13 @@ +package com.echo.photo_editor.ML; + +public enum styleTransTypes { + cartoon, + pencil, + color_pencil, + warm, + wave, + lavender, + mononoke, + scream, + gothic +} diff --git a/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/PhotoEditorView.java b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/PhotoEditorView.java index 929d94d..8e34d92 100644 --- a/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/PhotoEditorView.java +++ b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/PhotoEditorView.java @@ -14,14 +14,19 @@ import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; +import com.echo.photo_editor.ML.BaiduImageAPI; import com.echo.photo_editor.ML.LowLightModel; import com.echo.photo_editor.ML.StyleTransModel; +import com.echo.photo_editor.ML.styleTransTypes; import com.echo.photo_editor.R; import com.echo.photo_editor.databinding.ActivityPhotoEditorBinding; import com.echo.photo_editor.photo_editor_view.adapter.ImagePreviewAdapter; +import com.echo.photo_editor.photo_editor_view.model.ContrastEnhanceTool; +import com.echo.photo_editor.photo_editor_view.model.DehazeTool; import com.echo.photo_editor.photo_editor_view.model.EditableImage; -import com.echo.photo_editor.photo_editor_view.model.LowLightTool; +import com.echo.photo_editor.photo_editor_view.model.SelfieAnimeTool; import com.echo.photo_editor.photo_editor_view.model.StyleTool; +import com.echo.photo_editor.photo_editor_view.model.StyleTool2; import com.echo.photo_editor.photo_editor_view.model.Tool; import com.echo.photo_editor.photo_editor_view.model.Toolbox; import com.echo.photo_editor.util.PhotoLib; @@ -41,6 +46,7 @@ public class PhotoEditorView extends AppCompatActivity { public StyleTransModel styleTransModel = new StyleTransModel(this); public LowLightModel lowLightModel = new LowLightModel(this); private PhotoEditorView _this = this; + public BaiduImageAPI baiduImageAPI; @Override @@ -48,6 +54,7 @@ public class PhotoEditorView extends AppCompatActivity { super.onCreate(savedInstanceState); binding = ActivityPhotoEditorBinding.inflate(getLayoutInflater()); model = new ViewModelProvider(this).get(PhotoEditorViewModel.class); + baiduImageAPI = new BaiduImageAPI(this); Intent intent = getIntent(); String sourceFilePath = intent.getStringExtra("sourceFilePath"); model.set_sourceFilePath(sourceFilePath); @@ -136,7 +143,7 @@ public class PhotoEditorView extends AppCompatActivity { this ); - Toolbox style_trans = new Toolbox("Style Trans", BitmapFactory.decodeResource(getResources(), R.mipmap.tool_tmp_image)); + Toolbox style_trans = new Toolbox("Style Trans", BitmapFactory.decodeResource(getResources(), R.mipmap.candy)); style_trans.getTools().add(candy); style_trans.getTools().add(feathers); style_trans.getTools().add(la_muse); @@ -144,19 +151,123 @@ public class PhotoEditorView extends AppCompatActivity { style_trans.getTools().add(the_scream); style_trans.getTools().add(udnie); - LowLightTool lowLightTool = new LowLightTool( - "LowLight", - BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher), +// LowLightTool lowLightTool = new LowLightTool( +// "LowLight", +// BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher), +// this +// ); +// Toolbox lowLightToolBox = new Toolbox( +// "Lowlight", +// BitmapFactory.decodeResource(getResources(), R.mipmap.tool_tmp_image) +// ); +// lowLightToolBox.getTools().add(lowLightTool); + + StyleTool2 cartoon = new StyleTool2( + "cartoon", + BitmapFactory.decodeResource(getResources(), R.mipmap.cartoon), + styleTransTypes.cartoon, + this + ); + StyleTool2 pencil = new StyleTool2( + "pencil", + BitmapFactory.decodeResource(getResources(), R.mipmap.pencil), + styleTransTypes.pencil, + this + + ); + StyleTool2 color_pencil = new StyleTool2( + "color_pencil", + BitmapFactory.decodeResource(getResources(), R.mipmap.colorpencil), + styleTransTypes.color_pencil, + this + + ); + StyleTool2 warm = new StyleTool2( + "warm", + BitmapFactory.decodeResource(getResources(), R.mipmap.warm), + styleTransTypes.warm, + this + + ); + StyleTool2 wave = new StyleTool2( + "wave", + BitmapFactory.decodeResource(getResources(), R.mipmap.wave), + styleTransTypes.wave, + this + + ); + StyleTool2 lavender = new StyleTool2( + "lavender", + BitmapFactory.decodeResource(getResources(), R.mipmap.lavender), + styleTransTypes.lavender, + this + + ); + StyleTool2 mononoke = new StyleTool2( + "mononoke", + BitmapFactory.decodeResource(getResources(), R.mipmap.mononoke), + styleTransTypes.mononoke, + this + + ); + StyleTool2 scream = new StyleTool2( + "scream", + BitmapFactory.decodeResource(getResources(), R.mipmap.scream), + styleTransTypes.scream, + this + + ); + StyleTool2 gothic = new StyleTool2( + "gothic", + BitmapFactory.decodeResource(getResources(), R.mipmap.gothic), + styleTransTypes.gothic, + this + + ); + + Toolbox style_trans_baidu = new Toolbox("Style Trans2", BitmapFactory.decodeResource(getResources(), R.mipmap.scream)); + style_trans_baidu.getTools().add(cartoon); + style_trans_baidu.getTools().add(pencil); + style_trans_baidu.getTools().add(color_pencil); + style_trans_baidu.getTools().add(warm); + style_trans_baidu.getTools().add(wave); + style_trans_baidu.getTools().add(lavender); + style_trans_baidu.getTools().add(mononoke); + style_trans_baidu.getTools().add(scream); + style_trans_baidu.getTools().add(gothic); + + + Toolbox dehaze = new Toolbox("Dehaze", BitmapFactory.decodeResource(getResources(), R.mipmap.dehaze_demo)); + Tool dehaze_tool = new DehazeTool( + "Dehaze", + BitmapFactory.decodeResource(getResources(), R.mipmap.dehaze_demo), this ); - Toolbox lowLightToolBox = new Toolbox( - "Lowlight", - BitmapFactory.decodeResource(getResources(), R.mipmap.tool_tmp_image) + dehaze.getTools().add(dehaze_tool); + + Toolbox selfieAnimeToolbox = new Toolbox("selfieAnime", BitmapFactory.decodeResource(getResources(), R.mipmap.selfieanime_demo)); + Tool selfieAnimeTool = new SelfieAnimeTool( + "selfieAnime", + BitmapFactory.decodeResource(getResources(), R.mipmap.selfieanime_demo), + this ); - lowLightToolBox.getTools().add(lowLightTool); + selfieAnimeToolbox.getTools().add(selfieAnimeTool); + + Toolbox ContrastEnhanceToolBox = new Toolbox("Contrast", BitmapFactory.decodeResource(getResources(), R.mipmap.contrastenhance_demo)); + ContrastEnhanceTool contrastEnhanceTool = new ContrastEnhanceTool( + "Enhance", + BitmapFactory.decodeResource(getResources(), R.mipmap.contrastenhance_demo), + this + ); + ContrastEnhanceToolBox.getTools().add(contrastEnhanceTool); toolboxes.add(style_trans); - toolboxes.add(lowLightToolBox); +// toolboxes.add(lowLightToolBox); + toolboxes.add(style_trans_baidu); + toolboxes.add(dehaze); + toolboxes.add(ContrastEnhanceToolBox); + toolboxes.add(selfieAnimeToolbox); + imagePreviewAdapter = new ImagePreviewAdapter(toolboxes); binding.imagePreviewRcView.setAdapter(imagePreviewAdapter); diff --git a/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/ContrastEnhanceTool.java b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/ContrastEnhanceTool.java new file mode 100644 index 0000000..b815f87 --- /dev/null +++ b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/ContrastEnhanceTool.java @@ -0,0 +1,45 @@ +package com.echo.photo_editor.photo_editor_view.model; + + +import android.graphics.Bitmap; +import android.view.View; + +import com.echo.photo_editor.ML.RequestsListener; +import com.echo.photo_editor.ML.styleTransTypes; +import com.echo.photo_editor.photo_editor_view.PhotoEditorView; +import com.echo.photo_editor.util.PhotoLib; + +/** + * @author WangYuyang + * @date 2021-10-29 22:51:42 + */ +public class ContrastEnhanceTool extends Tool { + public styleTransTypes style_type; + + public ContrastEnhanceTool(String name, Bitmap image, PhotoEditorView view) { + super(name, image); + this.style_type = style_type; + super.listener = new View.OnClickListener() { + @Override + public void onClick(View v) { + view.showLoading("Processing...."); + view.baiduImageAPI.contrastEnhance(new RequestsListener() { + @Override + public void success(String data) { + Bitmap res_image = PhotoLib.Base64ToBitmap(data); + view.model.getEditableImage().getValue().update_current_bitmap(res_image); + view.hideLoading(); + } + + @Override + public void failure(String info) { + System.out.println(info); + view.hideLoading(); + + } + }, view.model.getEditableImage().getValue().getCurrent_bitmap()); + } + }; + } + +} diff --git a/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/DehazeTool.java b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/DehazeTool.java new file mode 100644 index 0000000..ca69389 --- /dev/null +++ b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/DehazeTool.java @@ -0,0 +1,45 @@ +package com.echo.photo_editor.photo_editor_view.model; + + +import android.graphics.Bitmap; +import android.view.View; + +import com.echo.photo_editor.ML.RequestsListener; +import com.echo.photo_editor.ML.styleTransTypes; +import com.echo.photo_editor.photo_editor_view.PhotoEditorView; +import com.echo.photo_editor.util.PhotoLib; + +/** + * @author WangYuyang + * @date 2021-10-29 22:51:42 + */ +public class DehazeTool extends Tool { + public styleTransTypes style_type; + + public DehazeTool(String name, Bitmap image, PhotoEditorView view) { + super(name, image); + this.style_type = style_type; + super.listener = new View.OnClickListener() { + @Override + public void onClick(View v) { + view.showLoading("Processing...."); + view.baiduImageAPI.dehaze(new RequestsListener() { + @Override + public void success(String data) { + Bitmap res_image = PhotoLib.Base64ToBitmap(data); + view.model.getEditableImage().getValue().update_current_bitmap(res_image); + view.hideLoading(); + } + + @Override + public void failure(String info) { + System.out.println(info); + view.hideLoading(); + + } + }, view.model.getEditableImage().getValue().getCurrent_bitmap()); + } + }; + } + +} diff --git a/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/SelfieAnimeTool.java b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/SelfieAnimeTool.java new file mode 100644 index 0000000..e9a51b4 --- /dev/null +++ b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/SelfieAnimeTool.java @@ -0,0 +1,45 @@ +package com.echo.photo_editor.photo_editor_view.model; + + +import android.graphics.Bitmap; +import android.view.View; + +import com.echo.photo_editor.ML.RequestsListener; +import com.echo.photo_editor.ML.styleTransTypes; +import com.echo.photo_editor.photo_editor_view.PhotoEditorView; +import com.echo.photo_editor.util.PhotoLib; + +/** + * @author WangYuyang + * @date 2021-10-29 22:51:42 + */ +public class SelfieAnimeTool extends Tool { + public styleTransTypes style_type; + + public SelfieAnimeTool(String name, Bitmap image, PhotoEditorView view) { + super(name, image); + this.style_type = style_type; + super.listener = new View.OnClickListener() { + @Override + public void onClick(View v) { + view.showLoading("Processing...."); + view.baiduImageAPI.selfieAnime(new RequestsListener() { + @Override + public void success(String data) { + Bitmap res_image = PhotoLib.Base64ToBitmap(data); + view.model.getEditableImage().getValue().update_current_bitmap(res_image); + view.hideLoading(); + } + + @Override + public void failure(String info) { + System.out.println(info); + view.hideLoading(); + + } + }, view.model.getEditableImage().getValue().getCurrent_bitmap()); + } + }; + } + +} diff --git a/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/StyleTool2.java b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/StyleTool2.java new file mode 100644 index 0000000..f0289b8 --- /dev/null +++ b/photo_editor/src/main/java/com/echo/photo_editor/photo_editor_view/model/StyleTool2.java @@ -0,0 +1,45 @@ +package com.echo.photo_editor.photo_editor_view.model; + + +import android.graphics.Bitmap; +import android.view.View; + +import com.echo.photo_editor.ML.RequestsListener; +import com.echo.photo_editor.ML.styleTransTypes; +import com.echo.photo_editor.photo_editor_view.PhotoEditorView; +import com.echo.photo_editor.util.PhotoLib; + +/** + * @author WangYuyang + * @date 2021-10-29 22:51:42 + */ +public class StyleTool2 extends Tool { + public styleTransTypes style_type; + + public StyleTool2(String name, Bitmap image, styleTransTypes style_type, PhotoEditorView view) { + super(name, image); + this.style_type = style_type; + super.listener = new View.OnClickListener() { + @Override + public void onClick(View v) { + view.showLoading("Processing...."); + view.baiduImageAPI.styleTrans(new RequestsListener() { + @Override + public void success(String data) { + Bitmap res_image = PhotoLib.Base64ToBitmap(data); + view.model.getEditableImage().getValue().update_current_bitmap(res_image); + view.hideLoading(); + } + + @Override + public void failure(String info) { + System.out.println(info); + view.hideLoading(); + + } + }, view.model.getEditableImage().getValue().getCurrent_bitmap(), style_type); + } + }; + } + +} diff --git a/photo_editor/src/main/java/com/echo/photo_editor/util/PhotoLib.java b/photo_editor/src/main/java/com/echo/photo_editor/util/PhotoLib.java index cd41295..1a48175 100644 --- a/photo_editor/src/main/java/com/echo/photo_editor/util/PhotoLib.java +++ b/photo_editor/src/main/java/com/echo/photo_editor/util/PhotoLib.java @@ -36,6 +36,26 @@ public class PhotoLib { Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); return decodedByte; } + public static String saveImageTmp(Context context, Bitmap bmp) { + // 首先保存图片 + File appDir = context.getFilesDir(); + if (!appDir.exists()) { + appDir.mkdir(); + } + String fileName = System.currentTimeMillis() + ".jpg"; + File file = new File(appDir, fileName); + try { + FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); + bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos); + fos.flush(); + fos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return file.getAbsolutePath(); + } public static String saveImageToGallery(Context context, Bitmap bmp) { // 首先保存图片 diff --git a/photo_editor/src/main/res/mipmap-hdpi/cartoon.jpeg b/photo_editor/src/main/res/mipmap-hdpi/cartoon.jpeg new file mode 100644 index 0000000..c3f2b5d Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/cartoon.jpeg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/colorpencil.jpeg b/photo_editor/src/main/res/mipmap-hdpi/colorpencil.jpeg new file mode 100644 index 0000000..367b2a1 Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/colorpencil.jpeg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/contrastenhance_demo.jpg b/photo_editor/src/main/res/mipmap-hdpi/contrastenhance_demo.jpg new file mode 100644 index 0000000..24bc695 Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/contrastenhance_demo.jpg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/dehaze_demo.jpg b/photo_editor/src/main/res/mipmap-hdpi/dehaze_demo.jpg new file mode 100644 index 0000000..8d51bd3 Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/dehaze_demo.jpg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/gothic.jpeg b/photo_editor/src/main/res/mipmap-hdpi/gothic.jpeg new file mode 100644 index 0000000..7562561 Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/gothic.jpeg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/lavender.jpeg b/photo_editor/src/main/res/mipmap-hdpi/lavender.jpeg new file mode 100644 index 0000000..7dfd993 Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/lavender.jpeg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/mononoke.jpeg b/photo_editor/src/main/res/mipmap-hdpi/mononoke.jpeg new file mode 100644 index 0000000..f21ff67 Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/mononoke.jpeg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/pencil.jpeg b/photo_editor/src/main/res/mipmap-hdpi/pencil.jpeg new file mode 100644 index 0000000..6ac6f91 Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/pencil.jpeg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/scream.jpeg b/photo_editor/src/main/res/mipmap-hdpi/scream.jpeg new file mode 100644 index 0000000..9ec4120 Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/scream.jpeg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/selfieanime_demo.jpg b/photo_editor/src/main/res/mipmap-hdpi/selfieanime_demo.jpg new file mode 100644 index 0000000..2d9c368 Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/selfieanime_demo.jpg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/warm.jpeg b/photo_editor/src/main/res/mipmap-hdpi/warm.jpeg new file mode 100644 index 0000000..eb299ce Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/warm.jpeg differ diff --git a/photo_editor/src/main/res/mipmap-hdpi/wave.jpeg b/photo_editor/src/main/res/mipmap-hdpi/wave.jpeg new file mode 100644 index 0000000..6983eba Binary files /dev/null and b/photo_editor/src/main/res/mipmap-hdpi/wave.jpeg differ