Android uygulamalarında imageview ile ilgili bir sorunum var, kameradan resim çektikten veya galeriden resim aldıktan sonra resmi yuvarlaklaştırmak istiyorum. Ben kameradan fotoğraf çekmeye gidiyorum, bu normalde işlev, ama ben galeriden görüntü almak ile gidersem logcat içinde gösterilmiyor bazı hata var. BuradaImageView galeriye fotoğraf çekerken bir görüntüyü göstermiyor Android Uygulamaları
kodum:
public Bitmap getCroppedBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
canvas.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
Bitmap _bmp = Bitmap.createScaledBitmap(output, 300, 300, false);
return _bmp;
}
ve bu kodu: Görüntüyü yuvarlamak
private void selectImage() {
final CharSequence[] options = { "Take Photo", "Choose from Gallery","Cancel" };
AlertDialog.Builder builder = new AlertDialog.Builder(ActivityRegister.this);
builder.setTitle("Add Photo!");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Take Photo")) {
//define the file-name to save photo taken by Camera activity
String fileName = "new-photo-name.jpg";
//create parameters for Intent with filename
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION, "Image capture by camera");
//imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)
imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
//create new Intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra("crop", "true");
intent.putExtra("aspectX", -1);
intent.putExtra("aspectY", -1);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
startActivityForResult(intent, PICK_Camera_IMAGE);
}else if (options[item].equals("Choose from Gallery")){
try{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", -1);
intent.putExtra("aspectY", -1);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("return-data", true);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
}catch (Exception e){
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
}else if (options[item].equals("Cancel")){
dialog.dismiss();
}
}
});
builder.show();
}
kırpma:
bu kod resim çekmek veya galeriden almak için Seçenek menüsünü çağırmak için görüntüyü çözmek için kameradan veya galeriden görüntüleri çözme
public void decodeFile(String filePath) {
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 1024;
// Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
bitmap = BitmapFactory.decodeFile(filePath, o2);
ivImages.setImageBitmap(getCroppedBitmap(bitmap));
}
bu benim onActivityResult() Kod: benim kötü İngilizce
ONActivityResult() öğesini geçersiz kıldınız mı? – Jois
OnActivityResult() kodunuzu paylaşın. – AKSiddique
OnActivityResult() 'da geçersiz kılmadım. @Jois –