android整合两个bitmap
来源:互联网 发布:sqlserver 数据库设计 编辑:程序博客网 时间:2024/06/08 05:09
有时候会遇到这样的需求,将两个bitmap对象整合并保存为一张图片,代码如下:
private Bitmap toConformBitmap(Bitmap background, Bitmap foreground) {
if( background == null ) {
return null;
}
int bgWidth = background.getWidth();
int bgHeight = background.getHeight();
//int fgWidth = foreground.getWidth();
//int fgHeight = foreground.getHeight();
//create the new blank bitmap 创建一个新的和SRC长度宽度一样的位图
Bitmap newbmp = Bitmap.createBitmap(bgWidth, bgHeight, Config.ARGB_8888);
Canvas cv = new Canvas(newbmp);
//draw bg into
cv.drawBitmap(background, 0, 0, null);//在 0,0坐标开始画入bg
//draw fg into
cv.drawBitmap(foreground, 0, 0, null);//在 0,0坐标开始画入fg ,可以从任意位置画入
//save all clip
cv.save(Canvas.ALL_SAVE_FLAG);//保存
//store
cv.restore();//存储
return newbmp;
}
此方法分别传入两个bitmap对象,一个为底图(背景图background),另一个则位于其上面(前景图foreground),若上面的bitmap是不透明的话,就会完全遮住下面的bitmap,那么保存为图片后,就只能看到位于上面的bitmap的信息,图片的大小为两个bitmap叠加的大小。
保存bitmap为一张图片:
private String saveBitmap(Bitmap bitmap) {
String imagePath = getApplication().getFilesDir().getAbsolutePath() + "/temp.png";
File file = new File(imagePath);
if(file.exists()) {
file.delete();
}
try{
FileOutputStream out = new FileOutputStream(file);
if(bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)){
out.flush();
out.close();
}
} catch (Exception e) {
Toast.makeText(this, "保存失败, 1).show();
e.printStackTrace();
}
return imagePath;
private Bitmap toConformBitmap(Bitmap background, Bitmap foreground) {
if( background == null ) {
return null;
}
int bgWidth = background.getWidth();
int bgHeight = background.getHeight();
//int fgWidth = foreground.getWidth();
//int fgHeight = foreground.getHeight();
//create the new blank bitmap 创建一个新的和SRC长度宽度一样的位图
Bitmap newbmp = Bitmap.createBitmap(bgWidth, bgHeight, Config.ARGB_8888);
Canvas cv = new Canvas(newbmp);
//draw bg into
cv.drawBitmap(background, 0, 0, null);//在 0,0坐标开始画入bg
//draw fg into
cv.drawBitmap(foreground, 0, 0, null);//在 0,0坐标开始画入fg ,可以从任意位置画入
//save all clip
cv.save(Canvas.ALL_SAVE_FLAG);//保存
//store
cv.restore();//存储
return newbmp;
}
此方法分别传入两个bitmap对象,一个为底图(背景图background),另一个则位于其上面(前景图foreground),若上面的bitmap是不透明的话,就会完全遮住下面的bitmap,那么保存为图片后,就只能看到位于上面的bitmap的信息,图片的大小为两个bitmap叠加的大小。
保存bitmap为一张图片:
private String saveBitmap(Bitmap bitmap) {
String imagePath = getApplication().getFilesDir().getAbsolutePath() + "/temp.png";
File file = new File(imagePath);
if(file.exists()) {
file.delete();
}
try{
FileOutputStream out = new FileOutputStream(file);
if(bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)){
out.flush();
out.close();
}
} catch (Exception e) {
Toast.makeText(this, "保存失败, 1).show();
e.printStackTrace();
}
return imagePath;
}
- android整合两个bitmap
- android整合两个bitmap
- android整合两个bitmap
- 将两个bitmap整合成一个bitmap
- android 多张bitmap整合
- Android将两个bitmap合并
- Android Bitmap、BitmapDrawable、Stream转换整合
- Android两个项目整合成一个
- Android上在两个Activity之间传递Bitmap对象
- Android上在两个Activity之间传递Bitmap对象
- Bitmap资料整合记录
- 将两个Bitmap资源合成一张bitmap
- android Bitmap
- android Bitmap
- android bitmap
- android Bitmap
- android bitmap
- android Bitmap
- nutch -1.2 command
- For Linux New Users
- Solute the problems by yourself from primary sources
- 在linux终端和shell显示中文
- 基本DNS服务器的配置
- android整合两个bitmap
- DNS服务器的搭建(二)
- Android 入门
- Linux ls order
- Linux下使用bind搭建DNS主从服务器
- dp优化专辑 A - Starship Troopers [dp+背包]
- 普通无法使用sudo命令
- vi无法使用方向键和退格键
- dp优化专辑 B - The more, The Better [dp+背包]