Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

android - Crop a Bitmap image

How can i crop a bitmap image? this is my question i have tried some concepts using intents but still fail..

I am having a bitmap image which i want to crop!!

here is the code :

 Intent intent = new Intent("com.android.camera.action.CROP");  
                      intent.setClassName("com.android.camera", "com.android.camera.CropImage");  
                      File file = new File(filePath);  
                      Uri uri = Uri.fromFile(file);  
                      intent.setData(uri);  
                      intent.putExtra("crop", "true");  
                      intent.putExtra("aspectX", 1);  
                      intent.putExtra("aspectY", 1);  
                      intent.putExtra("outputX", 96);  
                      intent.putExtra("outputY", 96);  
                      intent.putExtra("noFaceDetection", true);  
                      intent.putExtra("return-data", true);                                  
                      startActivityForResult(intent, REQUEST_CROP_ICON);

Could anybody help me regarding this @Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I used this method to crop the image and it works perfect:

Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.xyz);

resizedbitmap1=Bitmap.createBitmap(bmp, 0,0,yourwidth, yourheight);

createBitmap() takes bitmap,start X,start Y,width & height as parameter


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...