假设我有一个从库中选择图像的活动,并将其作为BitMap检索,就像示例:here
现在,我想传递此BitMap以在ImageView中用于另一个活动.我知道bundle可以在活动之间传递,但是我如何将这个BitMap存储到bundle中?
还是我应该采取另一种方法?
我正在开发一个绘画应用程序,我想在其中将Bitmap图像从一个活动传递到另一个活动,但项目没有响应.我将相对布局截图转换为位图并将其传递给Intent但问题仍未解决.这是我的代码....
DrawingActivity
package com.newdrawing;
public class DrawingActivity extends Activity {
private Bitmap mBitmap;
private Canvas mCanvas;
private Path mPath;
private Paint mBitmapPaint;
private Paint mPaint;
MyDrawView myDrawView;
RelativeLayout parent;
Bitmap bitmap;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawing);
parent = (RelativeLayout) findViewById(R.id.singleparent);
myDrawView = new MyDrawView(this);
parent.addView(myDrawView);
Activity context;
//RelativeLayout item = (RelativeLayout)findViewById(R.id.item);
View child = getLayoutInflater().inflate(R.layout.trans, null);
parent.addView(child);
}
public void color(View v) {
switch (v.getId()) {
case R.id.button3:
parent.setBackgroundColor(Color.RED);
break;
case R.id.button4:
parent.setBackgroundColor(Color.GREEN);
break;
case R.id.button5:
parent.setBackgroundColor(Color.BLUE); …Run Code Online (Sandbox Code Playgroud) 我必须将图像从一个活动转移到另一个活动.在第一个活动中,用户从滚动视图中选择几个图像中的图像,并且该图像必须显示在下一个活动的图像视图中.需要帮助.
我需要通过从其他活动中选择图像来动态更改活动的背景.并将所选图像传递回调用活动,但是当我尝试获取图像时,它为空.这是我的代码.
public class SelectGoalBackground extends OrmLiteBaseActivity<DatabaseHelper> {// implements{
GridView gridview ;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_goal_background);
final String from = getIntent().getExtras().getString("from");
goalsList = new ArrayList<Goal>();
try {
goalsList = getTop3Goals();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (java.sql.SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
ImageView l = (ImageView)gridview.getChildAt(position);
Drawable …Run Code Online (Sandbox Code Playgroud) 主要活动
holder.cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String title = ((TextView) view.findViewById(R.id.recipe_title)).getText().toString();
String time = ((TextView) view.findViewById(R.id.time)).getText().toString();
String servings = ((TextView) view.findViewById(R.id.servings)).getText().toString();
String calories = ((TextView) view.findViewById(R.id.calories)).getText().toString();
ImageView thumbnail = (ImageView) view.findViewById(R.id.recipe_img);
Intent intent = new Intent(context, ActivityDetail.class);
intent.putExtra("RecipeTitle", title);
intent.putExtra("RecipeTotalTime", time);
intent.putExtra("RecipeServings", servings);
intent.putExtra("RecipeCalories", calories);
context.startActivity(intent);
}
});
Run Code Online (Sandbox Code Playgroud)
详细活动
TextView time = (TextView)findViewById(R.id.time_detail);
TextView servings = (TextView)findViewById(R.id.servings_detail);
TextView calories = (TextView)findViewById(R.id.calories_detail);
ImageView thumbnail = (ImageView)findViewById(R.id.image_paralax);
time.setText(getIntent().getExtras().getString("RecipeTotalTime"));
servings.setText(getIntent().getExtras().getString("RecipeServings"));
calories.setText(getIntent().getExtras().getString("RecipeCalories"));
Run Code Online (Sandbox Code Playgroud)
如何将缩略图从第一个发送Activity到第二个Activity。在第二个“活动”中,缩略图将显示在 ImageView 上。