Note that there are some explanatory texts on larger screens.

plurals
  1. POChoosing background for live wallpaper from gallery
    primarykey
    data
    text
    <p>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: <a href="https://stackoverflow.com/questions/3679330/choosing-background-for-live-wallpaper">Choosing background for Live Wallpaper</a> and everything worked up until I had to implement the following code (the last portion in the answer):</p> <pre><code>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 = ""; } </code></pre> <p>Everything else worked pretty much as-is after adding in the appropriate variables. What is confusing me here is the line <code>else {bg = BitmapFactory.decodeResource(getResources(), R.drawable.bg);</code>, which gives me the error <code>bg cannot be resolved or is not a field</code>, referring to <code>R.drawable.bg</code>. What am I missing here?</p> <p>Anyone?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload