把两张bitmap覆盖合成为一张图

    /**
* 把两个位图覆盖合成为一个位图,以底层位图的长宽为基准
* @param backBitmap 在底部的位图
* @param frontBitmap 盖在上面的位图
* @return
*/
public static Bitmap mergeBitmap(Bitmap backBitmap, Bitmap frontBitmap) { if (backBitmap == null || backBitmap.isRecycled()
|| frontBitmap == null || frontBitmap.isRecycled()) {
Log.e(TAG, "backBitmap=" + backBitmap + ";frontBitmap=" + frontBitmap);
return null;
}
Bitmap bitmap = backBitmap.copy(Config.ARGB_8888, true);
Canvas canvas = new Canvas(bitmap);
Rect baseRect = new Rect(0, 0, backBitmap.getWidth(), backBitmap.getHeight());
Rect frontRect = new Rect(0, 0, frontBitmap.getWidth(), frontBitmap.getHeight());
canvas.drawBitmap(frontBitmap, frontRect, baseRect, null);
return bitmap;
} /**
* 把两个位图覆盖合成为一个位图,左右拼接
* @param leftBitmap
* @param rightBitmap
* @param isBaseMax 是否以宽度大的位图为准,true则小图等比拉伸,false则大图等比压缩
* @return
*/
public static Bitmap mergeBitmap_LR(Bitmap leftBitmap, Bitmap rightBitmap, boolean isBaseMax) { if (leftBitmap == null || leftBitmap.isRecycled()
|| rightBitmap == null || rightBitmap.isRecycled()) {
JDLog.logError(TAG, "leftBitmap=" + leftBitmap + ";rightBitmap=" + rightBitmap);
return null;
}
int height = 0; // 拼接后的高度,按照参数取大或取小
if (isBaseMax) {
height = leftBitmap.getHeight() > rightBitmap.getHeight() ? leftBitmap.getHeight() : rightBitmap.getHeight();
} else {
height = leftBitmap.getHeight() < rightBitmap.getHeight() ? leftBitmap.getHeight() : rightBitmap.getHeight();
} // 缩放之后的bitmap
Bitmap tempBitmapL = leftBitmap;
Bitmap tempBitmapR = rightBitmap; if (leftBitmap.getHeight() != height) {
tempBitmapL = Bitmap.createScaledBitmap(leftBitmap, (int)(leftBitmap.getWidth()*1f/leftBitmap.getHeight()*height), height, false);
} else if (rightBitmap.getHeight() != height) {
tempBitmapR = Bitmap.createScaledBitmap(rightBitmap, (int)(rightBitmap.getWidth()*1f/rightBitmap.getHeight()*height), height, false);
} // 拼接后的宽度
int width = tempBitmapL.getWidth() + tempBitmapR.getWidth(); // 定义输出的bitmap
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap); // 缩放后两个bitmap需要绘制的参数
Rect leftRect = new Rect(0, 0, tempBitmapL.getWidth(), tempBitmapL.getHeight());
Rect rightRect = new Rect(0, 0, tempBitmapR.getWidth(), tempBitmapR.getHeight()); // 右边图需要绘制的位置,往右边偏移左边图的宽度,高度是相同的
Rect rightRectT = new Rect(tempBitmapL.getWidth(), 0, width, height); canvas.drawBitmap(tempBitmapL, leftRect, leftRect, null);
canvas.drawBitmap(tempBitmapR, rightRect, rightRectT, null);
return bitmap;
} /**
* 把两个位图覆盖合成为一个位图,上下拼接
* @param leftBitmap
* @param rightBitmap
* @param isBaseMax 是否以高度大的位图为准,true则小图等比拉伸,false则大图等比压缩
* @return
*/
public static Bitmap mergeBitmap_TB(Bitmap topBitmap, Bitmap bottomBitmap, boolean isBaseMax) { if (topBitmap == null || topBitmap.isRecycled()
|| bottomBitmap == null || bottomBitmap.isRecycled()) {
JDLog.logError(TAG, "topBitmap=" + topBitmap + ";bottomBitmap=" + bottomBitmap);
return null;
}
int width = 0;
if (isBaseMax) {
width = topBitmap.getWidth() > bottomBitmap.getWidth() ? topBitmap.getWidth() : bottomBitmap.getWidth();
} else {
width = topBitmap.getWidth() < bottomBitmap.getWidth() ? topBitmap.getWidth() : bottomBitmap.getWidth();
}
Bitmap tempBitmapT = topBitmap;
Bitmap tempBitmapB = bottomBitmap; if (topBitmap.getWidth() != width) {
tempBitmapT = Bitmap.createScaledBitmap(topBitmap, width, (int)(topBitmap.getHeight()*1f/topBitmap.getWidth()*width), false);
} else if (bottomBitmap.getWidth() != width) {
tempBitmapB = Bitmap.createScaledBitmap(bottomBitmap, width, (int)(bottomBitmap.getHeight()*1f/bottomBitmap.getWidth()*width), false);
} int height = tempBitmapT.getHeight() + tempBitmapB.getHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap); Rect topRect = new Rect(0, 0, tempBitmapT.getWidth(), tempBitmapT.getHeight());
Rect bottomRect = new Rect(0, 0, tempBitmapB.getWidth(), tempBitmapB.getHeight()); Rect bottomRectT = new Rect(0, tempBitmapT.getHeight(), width, height); canvas.drawBitmap(tempBitmapT, topRect, topRect, null);
canvas.drawBitmap(tempBitmapB, bottomRect, bottomRectT, null);
return bitmap;
}

bitmap 合并图片的更多相关文章

  1. c# 根据窗口截图,合并图片

    c# 根据窗口截图,合并图片 public class CaptureWindows { #region 类 /// <summary> /// Helper class containi ...

  2. C#放缩、截取、合并图片并生成高质量新图的类

    原文:C#放缩.截取.合并图片并生成高质量新图的类 using System;using System.Drawing;using System.Drawing.Imaging;using Syste ...

  3. C#一些常用的图片操作方法:生成文字图片 合并图片等

    生成文字图片: /// <summary> /// 生成文字图片 /// </summary> /// <param name="text">& ...

  4. C#.NET 合并图片

    引用:https://www.cnblogs.com/stulzq/p/6137715.html util: using System; using System.Collections.Generi ...

  5. Android下利用Bitmap切割图片

    在自己自定义的一个组件中由于需要用图片显示数字编号,而当前图片就只有一张,上面有0-9是个数字,于是不得不考虑将其中一个个的数字切割下来,需要显示什么数字,只需要组合一下就好了. 下面是程序的关键代码 ...

  6. 用DIV+CSS切割多背景合并图片 CSS Sprites 技术

    很久之前就在互联网网站和一些js插件中见过这种技术的应用,当时觉得很麻烦,就没有用,也没有去深究. 近段时间一直在做前台的一些东西,涉及到很多div+css的问题.这个东东我又碰到了,所以我花了点时间 ...

  7. Android ListView SimpleAdapter支持Bitmap类型图片显示

    // 处理simpleAdapter中包括bitmap类型 adapter.setViewBinder(new ViewBinder() { public boolean setViewValue(V ...

  8. 减少HTTP请求之合并图片详解(大型网站优化技术)

    原文:减少HTTP请求之合并图片详解(大型网站优化技术) 一.相关知识讲解 看过雅虎的前端优化35条建议,都知道优化前端是有多么重要.页面的加载速度直接影响到用户的体验.80%的终端用户响应时间都花在 ...

  9. python合并图片

    因项目需求需要将图片合并故写了一个python脚本,在这里放个笔记 #!/usr/bin/env python #coding=utf-8 import Image import os import ...

随机推荐

  1. Educational Codeforces Round 55 (Rated for Div. 2)

    D. Maximum Diameter Graph 题意 给出每个点的最大度,构造直径尽可能长的树 思路 让度数大于$1$的点构成链,考虑是否能在链的两端加度为$1$的点 代码 #include &l ...

  2. hibernate之SessionFactory对象

    Factory --- 工厂 利用Configuration得到 hibernate3.版本 SessionFactory factory = Configuration.buildSessionFa ...

  3. BZOJ 5093: [Lydsy1711月赛]图的价值

    第二类斯特林数模版题 需要一些组合数的小$ trick$ upd:这里更新了本题巧妙的$ O(k)$做法,虽然常数很大就是了 传送门:here 题意:求所有$ n$个节点的无重边自环图的价值和,定义一 ...

  4. 2018-2019-1 20165234 实现mypwd

    实现mypwd(选做,加分) 1 学习pwd命令 2 研究pwd实现需要的系统调用(man -k; grep),写出伪代码 3 实现mypwd 4 测试mypwd 提交过程博客的链接

  5. CVE_2012_1876堆溢出分析

    首先用windbg附加进程ie页面内容进程,!gflag +hpa添加堆尾检查,.childdbg 1允许子进程调试,然后加载POC. POC: <html> <body> & ...

  6. Linux 运维工作中的经典应用ansible(批量管理)Docker容器技术(环境的快速搭建)

    一 Ansible自动化运维工具 Python 在运维工作中的经典应用 ansible(批量管理操作) .安装ansible(需要bese epel 2种源) wget -O /etc/yum.rep ...

  7. 用vue 写h5页面-摇一摇

    vue配合其他ui框架除了开发一个完整的web项目外,也有不少的项目做一些h5的活动页面开发.你的页面现在需要模拟微信的摇一摇动作. 项目环境: vue-cli 完成的一个项目 准备插件(包):依赖的 ...

  8. unity 网页加载AB问题

    下载一次后会缓存,清理一下就能加载新的同名AB了 AssetBundle.onload

  9. 第二章:Linux 基础篇章

    一.shell 在系统中,人所输入到系统内部的命令,以字符类型的形式输入刡系统当中,然而系统 只识别2进制码,就如以前 doc 界面为例,输入的都是字符类的英文字母作为输入的命令代 码,然 而明显二进 ...

  10. word 内容控件属性编辑

    场景: 别人发给自己一份word模板,基于统一性,里面包含了很多“内容控件”,一般情况下,只需要根据内容控件进行编辑即可,但如果想对内容控件本身做编辑操作,例如删除等. 操作: 单击 文件>选项 ...