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