【发布时间】: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