add-more-image-editing-funcality

yuying
王宇洋 3 years ago
parent e3add59c8c
commit 4fe71ac025

@ -45,7 +45,6 @@ android {
noCompress 'tflite'
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'

@ -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;

@ -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<ImageAdapter.ViewHolder>
}
});
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<ImageAdapter.ViewHolder>
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);
}
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="8dp" />
<solid android:color="@android:color/transparent"/>
<stroke android:color="#787878"
android:width="2dp"/>
</shape>
</item>
</selector>

@ -0,0 +1,5 @@
<vector android:alpha="0.8" android:height="24dp"
android:tint="?attr/colorControlNormal" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

@ -0,0 +1,5 @@
<vector android:alpha="0.8" android:height="24dp"
android:tint="?attr/colorControlNormal" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19,12v7L5,19v-7L3,12v7c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2v-7h-2zM13,12.67l2.59,-2.58L17,11.5l-5,5 -5,-5 1.41,-1.41L11,12.67L11,3h2z"/>
</vector>

@ -0,0 +1,5 @@
<vector android:alpha="0.8" android:height="24dp"
android:tint="?attr/colorControlNormal" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z"/>
</vector>

@ -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">
<TextView
@ -37,10 +38,12 @@
android:id="@+id/rcGallery"
android:layout_width="0dp"
android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.StaggeredGridLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4"
app:spanCount="2"
tools:ignore="SpeakableTextPresentCheck"
tools:listitem="@layout/rcimage_item" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -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 @@
<ImageView
android:id="@+id/rc_image_view"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:padding="10dp"
android:scaleType="fitXY"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_menu_camera" />
app:srcCompat="@drawable/black_demo_image" />
<ImageView
android:id="@+id/gallery_share_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/gallery_edit_button"
app:layout_constraintTop_toBottomOf="@+id/rc_image_view"
app:srcCompat="@drawable/ic_baseline_share_24" />
<TextView
android:id="@+id/rc_image_name"
<ImageView
android:id="@+id/gallery_edit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="6dp"
android:layout_marginTop="11dp"
android:text="123123"
android:visibility="gone"
android:layout_marginEnd="16dp"
android:padding="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="@+id/gallery_share_button"
app:srcCompat="@drawable/ic_baseline_edit_24" />
<ImageView
android:id="@+id/gallery_save_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="@+id/gallery_share_button"
app:layout_constraintEnd_toStartOf="@+id/gallery_share_button"
app:layout_constraintTop_toTopOf="@+id/gallery_share_button"
app:srcCompat="@drawable/ic_baseline_save_alt_24" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -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;

@ -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'
}

@ -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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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<String, String> options = new HashMap<String, String>();
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;
}
}

@ -0,0 +1,6 @@
package com.echo.photo_editor.ML;
public interface RequestsListener {
void success(String data);
void failure(String info);
}

@ -0,0 +1,13 @@
package com.echo.photo_editor.ML;
public enum styleTransTypes {
cartoon,
pencil,
color_pencil,
warm,
wave,
lavender,
mononoke,
scream,
gothic
}

@ -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);

@ -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());
}
};
}
}

@ -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());
}
};
}
}

@ -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());
}
};
}
}

@ -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);
}
};
}
}

@ -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) {
// 首先保存图片

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Loading…
Cancel
Save