3

已修复
最后,我在最后一个活动上创建了位图,而不是通过解决问题的意图传递它。

所以我正在拍摄图像和一些文本,然后将其放在图像上,然后我缩放位图并从中创建一个新位图。然后将带有意图的位图传递给下一个显示图像并提供将该图像保存到 sd 的选项的活动。

虽然我确实得到了失败的活页夹事务,这似乎是由于在意图之间传递了太多数据引起的,但是图像仍然可以很好地传递,所以我应该担心错误还是忽略它,因为它仍然可以正常工作?

我像这样创建/缩小位图

    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);

4

0 回答 0