我正在制作一个图像过滤器应用程序,在应用过滤器之前,我将图像裁剪为正方形,我可以使用Soundcloud库像这样裁剪图像:-
private void beginCrop(String sources) {
img_name = "cropped"+System.currentTimeMillis();
Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"+System.currentTimeMillis()));
Uri source = Uri.parse("file://"+sources);
Crop.of(source, destination).withAspect(200,200).start(this);
}
private void handleCrop(int resultCode, Intent result) {
if (resultCode == RESULT_OK) {
Toast.makeText(this,Crop.getOutput(result).toString(), Toast.LENGTH_SHORT).show();
Intent intent = new Intent(AlbumActivity.this,FilterImageActivity
.class);
intent.putExtra("output_image",Crop.getOutput(result).toString());
startActivity(intent);
} else if (resultCode == Crop.RESULT_ERROR) {
Toast.makeText(this, Crop.getError(result).getMessage(), Toast.LENGTH_SHORT).show();
}
}}
Run Code Online (Sandbox Code Playgroud)
以及下一个活动是FilterImageActivity.java:-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_filter_image);
String uri = getIntent().getStringExtra("output_image");
setImageDir(uri);
}
Run Code Online (Sandbox Code Playgroud)
和功能setImageDir():-
private void setImageDir(String uri)
{
Bitmap bitmap = …Run Code Online (Sandbox Code Playgroud)