80,472
社区成员




public class MainActivity extends Activity {
protected static Bitmap bmp = null;
private LinearLayout ll;
private Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("1***", MainActivity.bmp + "");
// 该线性布局中有两个ImageView、一个TextView
ll = (LinearLayout) findViewById(R.id.ll);
bt = (Button) findViewById(R.id.next);
bmp = ll.getDrawingCache();// 将线性布局中的整个内容转换为位图
Log.d("2***", MainActivity.bmp + "");
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent it = new Intent(MainActivity.this, TwoActivity.class);
startActivity(it);
}
});
}
}
mCenter.buildDrawingCache();
mCenter.setDrawingCacheEnabled(true);
Bitmap b1 = mCenter.getDrawingCache();
//mCenter.setDrawingCacheEnabled(false);
//mCenter.destroyDrawingCache();
把这后面的屏蔽就行了public class MainActivity extends Activity {
protected static Bitmap bmp = null;
private LinearLayout ll;
private Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("1***", MainActivity.bmp + "");
// 该线性布局中有两个ImageView、一个TextView
ll = (LinearLayout) findViewById(R.id.ll);
bt = (Button) findViewById(R.id.next);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ll.buildDrawingCache();
ll.setDrawingCacheEnabled(true);
bmp = ll.getDrawingCache();// 将线性布局中的整个内容转换为位图
Log.d("2***", MainActivity.bmp + "");
ll.setDrawingCacheEnabled(false);
ll.destroyDrawingCache();
Intent it = new Intent(MainActivity.this, TwoActivity.class);
startActivity(it);
}
});
}
}
Log日志里面也显示有对象了
public class TwoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setImageBitmap(MainActivity.bmp);
Log.d("3***", MainActivity.bmp + "");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.two, menu);
return true;
}
}
[/quote]
destroyDrawingCache 先去掉。我这么写是因为我取到之后就使用完了,中间使用bitmap的代码我去掉了。
要是下个界面的话,把bitmap 传递过去就好了,要是传递过去为null,就先copy到native 层的内存里。要用的时候再取就行了。public class MainActivity extends Activity {
protected static Bitmap bmp = null;
private LinearLayout ll;
private Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("1***", MainActivity.bmp + "");
// 该线性布局中有两个ImageView、一个TextView
ll = (LinearLayout) findViewById(R.id.ll);
bt = (Button) findViewById(R.id.next);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ll.buildDrawingCache();
ll.setDrawingCacheEnabled(true);
bmp = ll.getDrawingCache();// 将线性布局中的整个内容转换为位图
Log.d("2***", MainActivity.bmp + "");
ll.setDrawingCacheEnabled(false);
ll.destroyDrawingCache();
Intent it = new Intent(MainActivity.this, TwoActivity.class);
startActivity(it);
}
});
}
}
Log日志里面也显示有对象了
public class TwoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
ImageView iv = (ImageView) findViewById(R.id.iv);
iv.setImageBitmap(MainActivity.bmp);
Log.d("3***", MainActivity.bmp + "");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.two, menu);
return true;
}
}
mCenter.buildDrawingCache();
mCenter.setDrawingCacheEnabled(true);
Bitmap b1 = mCenter.getDrawingCache();
mCenter.setDrawingCacheEnabled(false);
mCenter.destroyDrawingCache();