空屏幕也会保存

时间:2018-02-07 09:17:06

标签: java android

绘制应用程序,您可以在其中删除和保存。基本上我不想保存空屏幕。位图转换为base64。但是现在它显示了日志中的base64值,即使它是空的。怎么做? 故障排除:我已经厌倦检查位图是否为空,如果bytearray为空,也会尝试。没有任何效果。任何指导??

import { DateFormatPipe } from "angular2-moment";
constructor(public dfp: DateFormatPipe) { }
var date = this.dfp.transform(value, 'DD/MM/YYYY');

MainActivity.java

 public class PaintView extends View { 
 Canvas mCanvas;  // 1
Bitmap mBitmap ,emptyBitmap ; //2 , to hold the pixels
Path mPath; // 3, encapsulates outline representing (multiple contuer) straight lines ,curves. can be drawn with canvas.drawpath(path,paint)
Paint mPaint; //4
private float mX, mY;
private static final float TOUCH_TOLERANCE = 5;
Context context;
public PaintView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
    mPath = new Path();
    mPaint = new Paint();
    mPaint.setAntiAlias(true); //smoothes the edges of what is being drawn
    mPaint.setStyle(Paint.Style.STROKE); // style is specifies as stroke. Options: Fill,fill and stroke
    mPaint.setColor(Color.BLACK);
    mPaint.setStrokeJoin(Paint.Join.ROUND); //more options for round
    mPaint.setStrokeWidth(4f);
}


@Override //called when the size of view is changed
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
  mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
       mCanvas = new Canvas(mBitmap);
}
    public String getEncoded64ImageStringFromBitmap(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100 , stream);
    byte[] byteFormat = stream.toByteArray();
    String imgString = Base64.encodeToString(byteFormat, Base64.DEFAULT);
    Log.d("check", "saved successfully");
    return imgString;
}

0 个答案:

没有答案