固定
最后,我在最后一个活动上创建了我的位图,而不是通过意图传递它来解决问题。
所以我正在拍摄图像和一些文字,然后将其放在图像上,然后我缩放位图并从中创建一个新的位图。然后将该位图传递给显示图像的下一个活动,并提供将该图像保存到SD的选项。
虽然我确实得到了失败的绑定器事务,这似乎是由意图之间传递过多数据引起的,但是图像仍然可以正常传递,所以我应该担心错误还是忽略它,因为它仍然可以正常工作? / p>
我像这样创建/缩小位图
strTop = txtTop.getText().toString();
strButtom = txtButtom.getText().toString();
combinedBitmap = BitmapFactory.decodeResource(getResources(), lstImages.get(index)).copy(Bitmap.Config.ARGB_8888, true);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.RED);
paint.setTextSize(combinedBitmap.getHeight()/10);
paint.setTextAlign(Paint.Align.CENTER);
Canvas canvas = new Canvas(combinedBitmap);
canvas.drawText(strTop, (canvas.getWidth() / 2), paint.getTextSize()+10, paint);
canvas.drawText(strButtom, (canvas.getWidth() / 2), combinedBitmap.getHeight()-paint.getTextSize()-10, paint);
Intent intent = new Intent(this, SaveToSD.class);
int width = combinedBitmap.getWidth();
int height = combinedBitmap.getHeight();
int newWidth = 400;
int newHeight = 240;
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap newbm = Bitmap.createBitmap(combinedBitmap, 0, 0, width, height, matrix,true);
intent.putExtra("combinedBitmap", newbm);
startActivity(intent);
我用这段代码检索它:
combinedBitmap = getIntent().getExtras().getParcelable("combinedBitmap");
imgView.setImageBitmap(combinedBitmap);