Reputation: 51
I have this bitmap on my imageview and when i save the bitmap, it includes the black border around the bitmap. The border is there because the size of the bitmap is different from the screensize. Anyone can tell me why and how to solve it? Thank you so much in advance!
Here's the screenshot of my image's Before and After :
Here's my layout XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="gone" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
</LinearLayout>
<Button
android:id="@+id/selectPhotoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Select Photo" />
<Button
android:id="@+id/editPhotoButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Edit Now" />
</RelativeLayout>
The imageview with problem is imageView2.
Here's how i save the image:
private void savePhoto() {
if (editPhotoImg.getDrawable() == null) {
// Toast.makeText(getApplicationContext(), "No Photo Edited",
// Toast.LENGTH_SHORT).show();
} else {
try {
String filePath = getOutputMediaFile(RESULT).getPath();
editPhotoImg.setDrawingCacheEnabled(true);
Bitmap b = editPhotoImg.getDrawingCache(true);
b.compress(CompressFormat.JPEG, 100, new FileOutputStream(
filePath));
// Toast.makeText(getApplicationContext(),
// "Image saved to: "+filePath, Toast.LENGTH_SHORT).show();
// detectFaces(true);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Invalid File Path",
Toast.LENGTH_SHORT).show();
}
}
}
Once again thanks for the help in advance!!!
Upvotes: 0
Views: 1622
Reputation: 2173
You have set
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
... />
which stretches the image view to the bounds of its parent view (which doesn't guarantee that the image will have the same size as your parent view). If you don't want the black border, the view should have "wrap_content"
, so it will be automatically sized for the loaded image.
Upvotes: 1