您好我必须为我的应用设置个人资料图片。我已经完成了从画廊和相机拍摄图像,然后将其裁剪为完美的形状并在我的图像视图中显示,但它是低质量像素,图像不清晰。 如何获得相机拍摄的相同质量或图库中的图像
我的代码是:
public String getContactByPhoneNumber(String phoneNumber) throws Exception {
HttpURLConnection connection = null;
URL url = new URL(completeURL + "/contacts?select=lastname&$filter=telephone1 eq '"+phoneNumber+"'");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("OData-MaxVersion", "4.0");
connection.setRequestProperty("OData-Version", "4.0");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Prefer", "odata.include-annotations=\"*\"");
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.addRequestProperty("Authorization", "Bearer " + token);
if (connection.getResponseCode() == 200) {
String response = getResponseAsString(connection);
return response;
} else {
String error = getErrorAsString(connection);
System.err.println(error);
return null;
}
}
答案 0 :(得分:0)
将库包含为本地库项目。将此行添加到build.gradle文件
compile 'com.yalantis:ucrop:2.2.0'
将UCropActivity添加到AndroidManifest.xml
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
使用构建器模式创建uCrop配置。
UCrop.of(sourceUri, destinationUri)
.withAspectRatio(16, 9)
.withMaxResultSize(maxWidth, maxHeight)
.start(context);
覆盖onActivityResult方法并处理uCrop结果。
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
final Uri resultUri = UCrop.getOutput(data);
} else if (resultCode == UCrop.RESULT_ERROR) {
final Throwable cropError = UCrop.getError(data);
}
}