`
ET焖猪仔
  • 浏览: 233636 次
  • 性别: Icon_minigender_1
  • 来自: 广东
社区版块
存档分类
最新评论

api demos中的里面的FingerPaint所画的保存到sdcard上

阅读更多
转载:http://www.eoeandroid.com/thread-12270-1-1.html
每个canvas对应着一个Bitmap,像素信息保存在里面,将Bitmap保存为文件
先在sd卡上创建Note目录
直接在api demos上改的,touch_up中保存,这样每次保存最新的
 

private void touch_up() {
            mPath.lineTo(mX, mY);
            // commit the path to our offscreen
            mCanvas.drawPath(mPath, mPaint);
            // kill this so we don't double draw
            mPath.reset();
            
            try {
                saveMyBitmap(Integer.toString(count++));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

public void saveMyBitmap(String bitName) throws IOException {
File f = new File("/sdcard/Note/" + bitName + ".png");
f.createNewFile();
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics