`
tao_zi
  • 浏览: 6939 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

Bitmap对象写成图片文件,加水印等 android

阅读更多
FileOutPutStream  m_fileOutPutStream = null;
try {
    m_fileOutPutStream = new FileOutputStream(filePath);//写入的文件路径
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m_newBitmap.compress(CompressFormat.PNG, 100, m_fileOutPutStream);
try {
m_fileOutPutStream.flush();
m_fileOutPutStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}



//加水印
Bitmap m_srcBitmap = BitmapFactory.decodeFile(srcPath);  //原图片
m_bmpWidth = m_srcBitmap.getWidth();
m_bmpHeight = m_srcBitmap.getWidth();
m_bmpConfig = m_srcBitmap.getConfig();

// 绘制新的bitmap
m_newBitmap = Bitmap.createBitmap(m_bmpWidth, m_bmpHeight, m_bmpConfig);
m_newCanvas = new Canvas(m_newBitmap); m_newCanvas.drawBitmap(m_srcBitmap, 0, 0, null);
m_newCanvas.drawText(WATER_TEXT, 0, m_bmpHeight - 100, m_paint);
m_newCanvas.save(Canvas.ALL_SAVE_FLAG);

// 写入新的图片
try{
    m_fileOutPutStream = new FileOutputStream(m_fileName);
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
m_newBitmap.compress(CompressFormat.PNG, 100, m_fileOutPutStream);
try {
m_fileOutPutStream.flush();
m_fileOutPutStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics