add-more-image-editing-funcality
@ -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>
|
@ -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
|
||||
}
|
@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
After Width: | Height: | Size: 114 KiB |
After Width: | Height: | Size: 156 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 132 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 112 KiB |
After Width: | Height: | Size: 154 KiB |
After Width: | Height: | Size: 107 KiB |
After Width: | Height: | Size: 31 KiB |
After Width: | Height: | Size: 126 KiB |
After Width: | Height: | Size: 102 KiB |