在android中裁剪图像 [英] Crop image in android
问题描述
我想裁剪图像我发现了一些非常有用的图像,但不知何故就像是缺少了未选区域的黑暗所以我想知道有谁知道怎么样?还是引导我走向正确的方向?我发现的在线教程显示会使所选区域变暗,但是当我使用它时,它不会。请帮助我多多感谢,抱歉我的英语不好。
我使用的教程的链接。
我希望它是这样的。
editButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v){
// TODO自动生成的方法stub
Intent goEdit;
goEdit = new Intent(PreviewActivity.this,CropImage.class);
goEdit.putExtra(image-path,path) ;
goEdit.putExt ra(scale,true);
goEdit.putExtra(fileName,nameFromPath);
// finish();
checkEdit = true;
startActivityForResult(goEdit,0);
}
});
编辑
我使用此按钮监听器调用cropImage文件通过调用CropImage类活动。这是一个自定义的意图不是Android内部的裁剪功能,但我认为是它的副本,以便它支持所有版本,但当我调用它时,选定区域不亮,我不知道问题可以在哪里引导我?谢谢
这是我正在使用的库你能使用默认的android裁剪功能吗?
这是我的代码
private void performCrop(Uri picUri){
try {
Intent cropIntent = new Intent(com.android.camera.action.CROP);
//表示图像类型,Uri
cropIntent.setDataAndType(picUri,image / *);
//在此处设置裁剪属性
cropIntent.putExtra(crop,true);
//表示所需作物的方面
cropIntent.putExtra(aspectX,1);
cropIntent.putExtra(aspectY,1);
//表示输出X和Y
cropIntent.putExtra(outputX,128);
cropIntent.putExtra(outputY,128);
//在返回时检索数据
cropIntent.putExtra(return-data,true);
//启动活动 - 我们处理onActivityResult返回
startActivityForResult(cropIntent,PIC_CROP);
}
//回应其设备不支持裁剪操作的用户
catch(ActivityNotFoundException anfe){
//显示错误消息
String errorMessage =哎呀 - 你的设备不支持裁剪动作!;
Toast toast = Toast.makeText(this,errorMessage,Toast.LENGTH_SHORT);
toast.show();
}
}
声明:
final int PIC_CROP = 1;
在顶部。
在onActivity结果中编写以下代码:
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
if(requestCode == PIC_CROP){
if(data!= null){
//获取返回的数据
Bundle extras = data.getExtras() ;
//获取裁剪位图
Bitmap selectedBitmap = extras.getParcelable(data);
imgView.setImageBitmap(selectedBitmap);
}
}
}
对我来说这很容易实施并显示变暗的区域。
I want to do cropping of image i found some pretty useful ones but somehow is like lacking of the darken the unselected areas so I wondering do anyone know how? or lead me to the right direction? The online tutorial i found shows that is will darken the selected area but when I use it, it won't. Please help me thanks alot and sorry for my bad command of english.
Links to the tutorial I use.
I want it to be something like this.
editButton.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent goEdit;
goEdit = new Intent(PreviewActivity.this, CropImage.class);
goEdit.putExtra("image-path", path);
goEdit.putExtra("scale", true);
goEdit.putExtra("fileName", nameFromPath);
//finish();
checkEdit = true;
startActivityForResult(goEdit,0);
}
});
EDIT I use this button listener to call into the cropImage file by calling to the class CropImage activity. This is a custom intent not the crop feature inside android but I think is the copy of it so that make it support for all versions but when I call into it the selected area isnt brighten and I donno where is the problem can anyone guide me? Thanks This is the library I'm using drioid4you crop image
Can you use default android Crop functionality?
Here is my code
private void performCrop(Uri picUri) {
try {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
// set crop properties here
cropIntent.putExtra("crop", true);
// indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
// indicate output X and Y
cropIntent.putExtra("outputX", 128);
cropIntent.putExtra("outputY", 128);
// retrieve data on return
cropIntent.putExtra("return-data", true);
// start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, PIC_CROP);
}
// respond to users whose devices do not support the crop action
catch (ActivityNotFoundException anfe) {
// display an error message
String errorMessage = "Whoops - your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
declare:
final int PIC_CROP = 1;
at top.
In onActivity result method, writ following code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PIC_CROP) {
if (data != null) {
// get the returned data
Bundle extras = data.getExtras();
// get the cropped bitmap
Bitmap selectedBitmap = extras.getParcelable("data");
imgView.setImageBitmap(selectedBitmap);
}
}
}
It is pretty easy for me to implement and also shows darken areas.
这篇关于在android中裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!