【问题标题】:Choosing background for live wallpaper from gallery从图库中选择动态壁纸的背景
【发布时间】:2013-11-12 16:15:06
【问题描述】:

我正在开发一种动态壁纸,它允许用户从他们的图库中选择一张静态图片并将其作为主屏幕的背景。我一直在关注从这里接受的答案:Choosing background for Live Wallpaper 并且一切正常,直到我不得不实现以下代码(答案中的最后一部分):

void getBackground() { 
if (this.cvwidth == 0 || this.cvheight == 0 || this.visibleWidth == 0) {
this.cvwidth = 480;
this.cvheight = 854;
this.visibleWidth = 480;}
if(new File(imageBg).exists()) {
int SampleSize = 1;
do {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
bg = BitmapFactory.decodeFile(imageBg, options);
SampleSize = (int) (Math.ceil(options.outWidth/(this.visibleWidth * 2))*2);
options.inJustDecodeBounds = false;
try {options.inSampleSize = SampleSize;
bg = BitmapFactory.decodeFile(imageBg, options);}
catch (OutOfMemoryError e) {
SampleSize = SampleSize * 2;
}
} while (bg == null);

bg = Bitmap.createScaledBitmap(bg, this.cvwidth/2, this.cvheight, true);}
else {bg = BitmapFactory.decodeResource(getResources(), R.drawable.bg);
bg = Bitmap.createScaledBitmap(bg, this.cvwidth/2, this.cvheight, true);}
LoadText = "";
} 

在添加适当的变量后,其他一切都按原样工作。这里让我感到困惑的是else {bg = BitmapFactory.decodeResource(getResources(), R.drawable.bg); 行,它给了我错误bg cannot be resolved or is not a field,指的是R.drawable.bg。我在这里错过了什么?

有人吗?

【问题讨论】:

    标签: android gallery live-wallpaper


    【解决方案1】:

    这是我多年前最初的(冗长的答案),现在我对整个代码一头雾水,因为我现在根本不为 android 开发。

    但是,如果我没记错的话,你需要一张图片保存在你的 drawables 文件夹中。我叫我的'bg'。它在应用程序启动时用作默认图像,如果代码无法解析用户选择的图像(例如稍后被删除),它也用作回滚图像。

    我希望我是正确的,但大约三年前我写了这个答案。

    祝你好运。

    【讨论】:

    • 做到了!感谢您深入了解您的长期记忆以找到答案。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多