2016-09-24 7 views
0

У меня есть намерение обрезать изображения с определенным размером вывода. Но изменения, сделанные в размерах кода, никак не влияют на изображение, а вывод для каждого изменения остается неизменным.Картинка для Android: выход x и вывод y

private void performCrop(String picUri) { 
    try { 
     //Start Crop Activity 

     Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
     // indicate image type and Uri 
     File f = new File(picUri); 
     Uri contentUri = Uri.fromFile(f); 

     cropIntent.setDataAndType(contentUri, "image/*"); 
     // set crop properties 
     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", 400); 
     cropIntent.putExtra("outputY", 400); 

     // retrieve data on return 
     cropIntent.putExtra("return-data", true); 
     // start the activity - we handle returning in onActivityResult 
     startActivityForResult(cropIntent, RESULT_CROP); 
    } 
    // respond to users whose devices do not support the crop action 
    catch (ActivityNotFoundException anfe) { 
     // display an error message 
     String errorMessage = "your device doesn't support the crop action!"; 
     Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT); 
     toast.show(); 
    } 
} 

Изменения в выходных значениях x и y не влияют на обрезанный размер изображения. Размер изображения всегда равен 160 * 160. Jut, когда я меняю пропорции, размер изображения немного меняется. Но мне нужно, чтобы обеспечить определенный размер для х и у

И если есть какие-либо библиотеки относительно урожая изображения, а также поддерживается на всех устройств, то это было бы удивительным

+1

Почему вы просто не установили свое изображение в требуемые размеры и не задали тип сканирований = centercrop? –

ответ

1

Установите ASPectX и aspectY в соотношении outputX и outputY ,

Предположим, что вы хотите получить изображение в виде 200 * 300 пикселей. Затем просто установите aspectX как 2 и aspectY как 3. Вы получите желаемое измерение изображения. Вот обновленный код.

private void performCrop(String picUri) { 
    try { 
     //Start Crop Activity 

     Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
     // indicate image type and Uri 
     File f = new File(picUri); 
     Uri contentUri = Uri.fromFile(f); 

     cropIntent.setDataAndType(contentUri, "image/*"); 
     // set crop properties 
     cropIntent.putExtra("crop", "true"); 
     // indicate aspect of desired crop 
     cropIntent.putExtra("aspectX", 2); 
     cropIntent.putExtra("aspectY", 3); 
     // indicate output X and Y 
     cropIntent.putExtra("outputX", 200); 
     cropIntent.putExtra("outputY", 300); 

     // retrieve data on return 
     cropIntent.putExtra("return-data", true); 
     // start the activity - we handle returning in onActivityResult 
     startActivityForResult(cropIntent, RESULT_CROP); 
    } 
    // respond to users whose devices do not support the crop action 
    catch (ActivityNotFoundException anfe) { 
     // display an error message 
     String errorMessage = "your device doesn't support the crop action!"; 
     Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT); 
     toast.show(); 
    } 
    }