I'm developing a live wallpaper that allows the user to choose a static image from their Gallery and make that the background on the homescreen. I was following the accepted answer from here: Choosing background for Live Wallpaper and everything worked up until I had to implement the following code (the last portion in the answer):
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 = "";
}
Everything else worked pretty much as-is after adding in the appropriate variables. What is confusing me here is the line else {bg = BitmapFactory.decodeResource(getResources(), R.drawable.bg);
, which gives me the error bg cannot be resolved or is not a field
, referring to R.drawable.bg
. What am I missing here?
Anyone?