【问题标题】:Write bitmap messed up with horizontal lines用水平线写位图
【发布时间】:2014-06-06 17:51:48
【问题描述】:

我正在尝试在透明位图上进行手指绘制。我使用的画布可以很好地绘制图像,但是当我保存图像时,图像如下所示,所有水平透明线。

我使用以下代码进行绘制。

private void doDraw(Canvas canvas) {

    mOffScreenCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    for(int index = 0; index < mAnnotations.size(); index++) {
        InkAnnotation annotation = mAnnotations.get(index);

        annotation.draw(mOffScreenCanvas, ActivityPageToolBar.mCurrentTool.paint());
    }

    if(canvas != null && mSurface != null) {
        canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
        canvas.drawBitmap(mSurface, 0, 0, mPaint);
    }
}

文件保存使用

            Bitmap saveBitmap = Bitmap.createBitmap(map);
            Canvas c = new Canvas(saveBitmap);
            c.drawColor(0xFFFFFFFF);
            c.drawBitmap(map,0,0,null);

我使用标准文件保存来保存它

try {
              FileOutputStream out = handle.outputStream();

              if(handle.fileName().contains(".png")) {
                  ((Bitmap) handle.data()).compress(CompressFormat.PNG, quality, out);
              } else if(handle.fileName().contains(".jpg") || handle.fileName().contains(".jpeg")) {
                  ((Bitmap) handle.data()).compress(CompressFormat.JPEG, quality, out);
              } else {
                  ((Bitmap) handle.data()).compress(CompressFormat.WEBP, quality, out);
              }
              out.flush();
              out.close();
          } catch(Exception e) {
              e.printStackTrace();
          }

有什么办法可以解决这个问题吗?同时,我将位图嵌入到 pdf 中,颜色比应有的颜色深。

这是图像在我保存之前在屏幕上的样子。背景无关紧要,我可以很好地绘制到屏幕上,但是当它保存为 png 时,它看起来很乱。

【问题讨论】:

  • 抱歉不明白哪里错了。请张贴原图。

标签: android bitmap draw paint porter-duff


【解决方案1】:

我通过获取我在表面视图上创建的点并从这些点创建一个新位图来解决这个问题。一定是它对其位图的表面做某事导致了这种情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-24
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    • 2021-12-15
    • 2021-09-23
    • 2019-01-31
    • 1970-01-01
    相关资源
    最近更新 更多