把两张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. Leetcode#344. Reverse String(反转字符串)

    题目描述 编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man ...

  2. Jmeter学习笔记03-元件作用域及执行顺序

    Jmeter可以通过鼠标拖拽来随意改变元件之间的顺序以及元件的层级关系,随着元件所在域的不同,在执行时候,会有不同效果 层级关系和元件类型决定了在测试计划中各元件的执行顺序. 1)元件的作用域: jm ...

  3. Error while Installing APKs

    这一篇帖子 会写的比较简单 不过相信大家也可能遇到这些问题   为了怕自己忘记  记录下来  顺便也和大家一起分享 描述:在一些机型上安装软件 提示卸载原先的软件  但是又安装不上新软件DELETE_ ...

  4. ESP8266代码中的存储标记

    const uint8 MyArr[1024] ICACHE_RODATA_ATTR = {0}; void MyFun() ICACHE_FLASH_ATTR { } 这种 ICACHE 开头的宏作 ...

  5. br-lan、eth0、eth1及lo (转)

    如果你的设备含有不少于1个的LAN接口,那这个设备在不同的接口之间可能有一个被称为交换(switch)的特殊连接.大多数的内部构造如下图所示: Linux 系统下输入ifconfig命令,会有如下输出 ...

  6. 微信H5支付坑一--手续费未结算

    简单随笔小记: 场景:在微信H5支付的过程中,无论怎么支付完成,在微信商户后台查询手续费依然未扣除,当时手续费账户月为5元. 解决方法:起初无论怎么测试都不知道代码到底问题出在哪里了,想一下手续费账户 ...

  7. vue项目关闭eslint检查

    前言 vue项目在用旧版本的vue-cli创建的时候,会询问是否添加eslint的检查, 后来的版本在创建的时候是直接添加了eslint检查. 有时候我们开发习惯不是那么严格的时候, 会不在意这些缩进 ...

  8. [转] Redux入门教程(快速上手)

    学习前提 在我们开始以前,确保你熟悉以下知识: 函数式JavaScript 面向对象JavaScript JavaScript ES6 语法 同时,确保你的设备已经安装: NodeJS Yarn(或者 ...

  9. pandas处理丢失数据-【老鱼学pandas】

    假设我们的数据集中有缺失值,该如何进行处理呢? 丢弃缺失值的行或列 首先我们定义了数据集的缺失值: import pandas as pd import numpy as np dates = pd. ...

  10. Imcash:坐下来认真和你们说说话

    筹备已久的Imcash终于快上线了,上线后会用作品向你们证明你们的选择是正确的.在准备的半年期间里,团队从调研.设计.市场.人员.技术方面都尽量按照最高要求来配置.从一站式服务平台到现在的资产管家,每 ...