1

我有一个用于绘图的位图对象,我想使用 JPEG 格式将其图像保存在 SDCARD 上。我有以下代码:

    public void saveBitmap() throws IOException {

        String path=Environment.getExternalStorageDirectory().getAbsolutePath()+"/output.jpg";
        File output=new File(path);

        BufferedOutputStream ous = null;
        try {
            ous=new BufferedOutputStream(new FileOutputStream(output));
            mBitmap.compress(CompressFormat.JPEG, 100, ous);
            ous.flush();
            ous.close();
        } finally {
            if (ous!=null) {
                try {
                    ous.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Log.e("closing", e.getMessage());
                }
            }
        }
    }

但在执行此功能后,我总是可以看到黑色背景的 jpeg 文件。如果我将格式更改为 PNG,一切都会好的。我在哪里犯了错误?

绘图代码:

    @Override
    protected void onDraw(Canvas canvas) {

        canvas.drawColor(0x00FFFFFF);
        canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
        canvas.drawPath(mPath, mPaint);
    }
4

1 回答 1

1

jpeg 格式不支持透明度。这就是为什么它在保存时将透明度呈现为黑色。

于 2012-05-29T17:47:36.290 回答