gpt4 book ai didi

android - 在 android Nougat 中裁剪图像

转载 作者:行者123 更新时间:2023-12-05 07:47:43 32 4
gpt4 key购买 nike

我已将手机更新为 android nougat,裁剪功能突然无法使用。在 Marshmallow 中工作得很好。这是我的build.gradle

    apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "multas.com.usj.multaszgz"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':tess-two-release')
compile files('libs/androidjhlabs.jar')
//Pestañas
compile files('libs/commons-codec-1.7.jar')
compile project(path: ':openCVLibrary310')
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
compile 'com.android.support:design:24.2.0'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.itextpdf:itextg:5.5.9'
compile 'org.codepond:wizardroid:1.3.1'
compile 'com.google.android.gms:play-services:9.4.0'
testCompile 'junit:junit:4.12'
}

这是裁剪的代码:

  private void crop(){
try {

Log.v("OCRActivity", "HA LLEGADO AL CROP: "+takeStoragePermissionGranted());
File file = new File(path);
Uri outputFileUri = Uri.fromFile(file);

Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(outputFileUri, "image/*");
intent.putExtra("crop", true);
//intent.putExtra("outputX",bm.getWidth());
//intent.putExtra("outputY", bm.getHeight());
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
Log.v("OCRActivity", "HA LLEGADO ");

startActivityForResult(intent, PIC_CROP);

}
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();
}catch(Exception e){
Log.e("OCRActivity", "crop():"+e.getMessage());
}

}

我没有在控制台中检测到任何错误,但在 onActivityOnResult 中返回 resultcode = 0,而它应该是 1...我不知道牛轧糖会发生什么,而棉花糖的代码与它的工作原理相同...

有什么解决办法吗?

最佳答案

我在我的 android 项目中使用这个函数。希望对您有所帮助。

//图像裁剪函数

 private void croppingIMG() {
imageSelect = true;
final ArrayList cropOptions = new ArrayList();
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");

List list = getActivity().getPackageManager().queryIntentActivities(intent, 0);
int size = list.size();
if (size == 0) {
Toast.makeText(getActivity(), "Cann't find image croping app", Toast.LENGTH_SHORT).show();
return;
} else {
intent.setData(mImageCaptureUri);
intent.putExtra("outputX", 512);
intent.putExtra("outputY", 512);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
//TODO: don't use return-data tag because it's not return large image data and crash not given any message
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(outPutFile));

if (size == 1) {
Intent i = new Intent(intent);
ResolveInfo res = (ResolveInfo) list.get(0);
i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
startActivityForResult(i, CROPING_CODE);
} else {

Intent i = new Intent(intent);
ResolveInfo res = (ResolveInfo) list.get(0);
i.setComponent( new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
startActivityForResult(i, CROPING_CODE);
}
}
}

关于android - 在 android Nougat 中裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39400546/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com