2013-06-27 58 views
0

我試圖挽救從ViewPagerParallax一個背景,可以在這裏找到:link如何保存畫布成位圖

當我移動,背景的變化,我想利用這個「部分」的背景並將其傳遞給另一個活動。

從一個傳遞到另一個activty我可以:

Intent intent = new Intent(context, Activity2.class); 
      ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
      //Bitmap bmp = pager.getSavedBitmap().getBitmap(); 
      Bitmap bmp = pager.getBitmap(); 
      bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); 
      byte[] byteArray = stream.toByteArray(); 
      intent.putExtra("image",byteArray); 
      context.startActivity(intent); 

byte[] byteArray = getIntent().getByteArrayExtra("image"); 
    Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); 
    @SuppressWarnings("deprecation") 
    Drawable d = new BitmapDrawable(bmp); 
    layout.setBackground(d); 

但知道拿我要的是困難的背景部分,我試圖把它從該方法的onDraw像這樣:

canvas.drawBitmap(saved_bitmap, src, dst, null); 
     if(canvas != null){   
      my_bitmap = new BitmapDrawable(); 
      my_bitmap.draw(canvas); 
     } 

但是當我使用getBitmap:

public Bitmap getBitmap(){ 
    return my_bitmap.getBitmap(); 
} 

圖像不像第一個活動那樣縮放。

+0

只是一個建議,不要使用Bitmap的強引用使用'WeakReference ' – blganesh101

回答