Java 如何将画布保存到位图中
我正在尝试从ViewPagerParallax保存背景,可在此处找到: 当我移动时,背景会发生变化,我想将背景的这一部分传递给另一个活动 要将其从一个活动传递到另一个活动,我可以:Java 如何将画布保存到位图中,java,android,bitmap,android-canvas,ondraw,Java,Android,Bitmap,Android Canvas,Ondraw,我正在尝试从ViewPagerParallax保存背景,可在此处找到: 当我移动时,背景会发生变化,我想将背景的这一部分传递给另一个活动 要将其从一个活动传递到另一个活动,我可以: Intent intent = new Intent(context, Activity2.class); ByteArrayOutputStream stream = new ByteArrayOutputStream(); //Bitmap bmp = pager
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);
但是,要知道获取我想要的部分背景是很困难的,我试图从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();
}
图像没有像第一次活动中那样缩放。这篇文章没有类似的问题吗
也许会有帮助。只是一个建议,不要对位图使用强引用使用
WeakReference
public Bitmap getBitmap(){
return my_bitmap.getBitmap();
}