相关疑难解决方法(0)

在Android上将画布保存到位图

关于将Canvas的内容放入Bitmap,我遇到了一些困难.当我尝试这样做时,文件的文件大小约为5.80KB但看起来完全是空的(每个像素都是'#000').

画布绘制了一系列由手写形成的相互连接的线条.下面是我对视图的onDraw.(我知道它阻止了UI线程/不良做法等等,但是我只需要让它工作)

谢谢.

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);

        if (IsTouchDown) {

            // Calculate the points
            Path currentPath = new Path();
            boolean IsFirst = true;
            for(Point point : currentPoints){
                if(IsFirst){
                    IsFirst = false;
                        currentPath.moveTo(point.x, point.y);
                    } else {
                        currentPath.lineTo(point.x, point.y);
                    }
                }

            // Draw the path of points
            canvas.drawPath(currentPath, pen);

            // Attempt to make the bitmap and write it to a file.
            Bitmap toDisk = null;
            try {

                // TODO: Get the size of …
Run Code Online (Sandbox Code Playgroud)

java android bitmapfactory android-canvas

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×1

android-canvas ×1

bitmapfactory ×1

java ×1