问题
I would like to implement live wallpaper where user will be able to setup own photo on the phone desktop.
Right now I have successfully implemented logic where user can crop any photo from android gallery or camera itself.
On the live wallpaper settings page I'd like to implement cropped photo preview. For this purpose, I have implemented SelectImagePreference
public class SelectImagePreference extends Preference {
public SelectImagePreference(Context context, AttributeSet attributeSet) {
this(context, attributeSet, 0);
}
public SelectImagePreference(Context context, AttributeSet attributeSet, int paramInt) {
super(context, attributeSet, paramInt);
setLayoutResource(R.layout.select_image_preference);
}
}
with layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:attr/theme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:listPreferredItemHeight"
android:paddingRight="?android:scrollbarSize" >
<ImageView
android:id="@+id/picture"
android:layout_width="200px"
android:layout_height="250px"
android:layout_margin="5dp"
android:background="@drawable/pic_border"
android:contentDescription="@string/picture" />
</LinearLayout>
In my WallpaperSettings activity in onActivityResult method I'm trying to set the returned Bitmap to my ImageView
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
} else if (requestCode == PICK_CROP) {
try {
Bundle extras = data.getExtras();
Bitmap croppedPicture = extras.getParcelable("data");
File saveFilePath = FileUtils.createNewFile(this, FOLDER, FileUtils.getUniqueFileName(CROPPED_IMAGE_PREFIX, CROPPED_IMAGE_EXTENSION));
FileOutputStream out = new FileOutputStream(saveFilePath);
croppedPicture.compress(Bitmap.CompressFormat.JPEG, 100, out);
saveCroppedImageUrl(saveFilePath.getAbsolutePath());
ImageView pictureView = (ImageView) findViewById(R.id.picture);
pictureView.setImageBitmap(croppedPicture);
} catch (Exception e) {
e.printStackTrace();
}
}
On my Samsung Note 2 preview picture shows maybe 1 time from ~10.
I'm sure that picture exists on the disk and Bitmap is not null. How to solve this issue ? Thanks
回答1:
Take a look to this wallpaper slideshow source code:
android-wallpaper-slideshow
来源:https://stackoverflow.com/questions/14487371/android-image-crop-and-wallpaper-settings-page