0

ライブ壁紙で実行中に画像を変更しようとしています。メソッド changeFlowers を呼び出しています。Log.W() を出力できますが、ビットマップを変更できません。前もって感謝します。


ここから f1.changeColor(this._theme) を呼び出すと機能しません。実行時に魚のビットマップ画像を変更したい

public void changeFlowers(int i)
{


    FlowerOne f1 = (FlowerOne)(this._fishes.get(i));   
    f1.changeColor(this._theme); // 


}

FishOne.java の changeColor 関数

public void changeColor(int mfishColor)
{


    switch(mfishColor) {
    case 1:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;
    this.leftBitmap = BitmapFactory.decodeResource(getContext().getResources(), com.gotit.livewallpaper.fishshd.R.drawable.fish1, options);

    BitmapFactory.Options options1 = new BitmapFactory.Options();
    options1.inPurgeable = true;
    this.rightBitmap = BitmapFactory.decodeResource(getContext().getResources(), com.gotit.livewallpaper.fishshd.R.drawable.fish2, options1);

    break;

    case 2:
    BitmapFactory.Options options2 = new BitmapFactory.Options();
    options2.inPurgeable = true;
    this.leftBitmap = BitmapFactory.decodeResource(getContext().getResources(), com.gotit.livewallpaper.fishshd.R.drawable.redfish1, options2);

    BitmapFactory.Options options3 = new BitmapFactory.Options();
    options3.inPurgeable = true;
    this.rightBitmap = BitmapFactory.decodeResource(getContext().getResources(), com.gotit.livewallpaper.fishshd.R.drawable.redfish2, options3);

    break;
    default:
    }


}

水族館.java

public class Aquarium {
private AquariumThread _aquariumThread; 
private SurfaceHolder _surfaceHolder;   
private ArrayList<Renderable> _fishes;  
private Bitmap _backgroundImage;
private Context _context;


public void render(){
    Canvas canvas = null;
    try{

    canvas = this._surfaceHolder.lockCanvas(null);
    synchronized (this._surfaceHolder) {
        this.onDraw(canvas);
    }

    }finally{
        if(canvas != null){
            this._surfaceHolder.unlockCanvasAndPost(canvas);
        }
    }   
}


protected void onDraw(Canvas canvas) {
    this.renderBackGround(canvas);
    for (Renderable renderable : this._fishes) {
        renderable.render(canvas);
    }
};

public void initialize(Context context, SurfaceHolder surfaceHolder) {
    this._fishes = new ArrayList<Renderable>();
}



protected void onDraw(Canvas canvas) {
    this.renderBackGround(canvas);
    for (Renderable renderable : this._fishes) {
        renderable.render(canvas);
    }
};


public void start(){
    this._aquariumThread.switchOn();
}


public void stop(){
    boolean retry = true;
    this._aquariumThread.switchOff();
    while (retry) {
    try {
     this._aquariumThread.join();
        retry = false;
    } catch (InterruptedException e) {
        // we will try it again and again...
}
}
}


public synchronized void addFishes() {      

Point startPoint1 = new Point(1,300);
this._fishes.add(new fishOne(this._context, this, startPoint1, 90));

Point startPoint2 = new Point(100,300);
this._fishes.add(new fishOne(this._context, this, startPoint2, 90));

Point startPoint3 = new Point(200,300);
this._fishes.add(new fishOne(this._context, this, startPoint3, 90));

}





public void changeFlowers(int i)
{


    FlowerOne f1 = (FlowerOne)(this._fishes.get(i));
    f1.changeColor(this._theme);


}


}

FishOne.java

public class fishOne extends Animal {
private static final int TOTAL_FRAMES_IN_SPRITE = 1;
private static final int CLOWN_FISH_FPS = 1; 

int _fishColor;
Bitmap leftBitmap;
Bitmap rightBitmap;


public fishOne(Context context, Aquarium aquarium,  Point startPoint, int speed){       

super(context, aquarium);   
this.changeColor(1);
this.initialize(this.leftBitmap, this.rightBitmap, CLOWN_FISH_FPS, TOTAL_FRAMES_IN_SPRITE, startPoint, speed);

    }


public void changeColor(int mfishColor)
{


    switch(mfishColor) {
    case 1:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;
    this.leftBitmap = BitmapFactory.decodeResource(getContext().getResources(), com.gotit.livewallpaper.fishshd.R.drawable.fish1, options);

    BitmapFactory.Options options1 = new BitmapFactory.Options();
    options1.inPurgeable = true;
    this.rightBitmap = BitmapFactory.decodeResource(getContext().getResources(), com.gotit.livewallpaper.fishshd.R.drawable.fish2, options1);

    break;

    case 2:
    BitmapFactory.Options options2 = new BitmapFactory.Options();
    options2.inPurgeable = true;
    this.leftBitmap = BitmapFactory.decodeResource(getContext().getResources(), com.gotit.livewallpaper.fishshd.R.drawable.redfish1, options2);

    BitmapFactory.Options options3 = new BitmapFactory.Options();
    options3.inPurgeable = true;
    this.rightBitmap = BitmapFactory.decodeResource(getContext().getResources(), com.gotit.livewallpaper.fishshd.R.drawable.redfish2, options3);

    break;
    default:
    }


}


public void render(Canvas canvas){
    super.render(canvas);   
}

}
4

1 に答える 1