ユーザーがギャラリーから静止画像を選択し、それをホームスクリーンの背景にすることができるライブ壁紙を開発しています。ここから受け入れられた回答に従っていました:ライブ壁紙の背景を選択すると、次のコードを実装する必要があるまですべてが機能しました (回答の最後の部分):
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
誰?