首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

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

2012-08-26 
Bitmap对象写成图片文件,加水印等 androidFileOutPutStreamm_fileOutPutStream nulltry {m_fileOutPutS

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();
}

热点排行