-
图片合成
2019-04-18 15:21:28# 将两张图片合成一张,但是这个代码的毛病就是两个图像的尺寸要一样,并且只能合成png的实例图 import cv2 import numpy as np import matplotlib.pyplot as plt # 读取图片 src1 = cv2.imread('C:/Users/...# 将两张图片合成一张,但是这个代码的毛病就是两个图像的尺寸要一样,并且只能合成png的实例图 import cv2 import numpy as np import matplotlib.pyplot as plt # 读取图片 src1 = cv2.imread('C:/Users/Administrator/Desktop/123.png') src2 = cv2.imread('C:/Users/Administrator/Desktop/4.png') # 图像融合 result = cv2.addWeighted(src1, 0.8, src2, 0.2, 10) # 显示图像 #cv2.imshow("src1", src1) #cv2.imshow("src2", src2) cv2.imshow("result", result) # 等待显示 cv2.waitKey(0) cv2.destroyAllWindows()
-
图片合成编码,二维码+图片合成,两张图片合成编码最终版
2017-11-14 17:11:48图片合成编码,二维码+图片合成,两张图片合成编码最终版 -
二维码生成,图片合成,文字图片合成工具类
2018-05-21 14:47:19二维码生成, 图片合成, 文字图片合成工具类 亲测有效,可以生成二维码,两张图片合成一张图片,在图片上添加文字 -
php图片合成方法(多张图片合成一张)
2020-10-18 23:12:00下面小编就为大家分享一篇php图片合成方法(多张图片合成一张),具有很好的参考价值。希望对大家有所帮助。一起跟随小编过来看看吧 -
易语言图片合成源码
2020-07-16 03:11:19易语言图片合成源码,图片合成,图片宽度高度文件名,设置大小,左键,被移动,SendMessage -
YUV图片合成
2015-06-01 11:34:15YUV JGP 图片合成 上下合成 -
易语言桌面图片合成源码
2020-07-17 11:46:11易语言桌面图片合成源码,桌面图片合成 -
ios 图片合成 处理合成模糊 水印 模板图片合成
2017-07-26 20:59:00今天要项目中要用到图片合成,所以看了下网上的资料和系统 API 图片合成可以用到很多的地方 添加水印 二维码生成的模板合成图片 //开始合成图片 /* *1. 需要绘制的大小 *2. 背景是否是黑色 *3. scale 当前设备的...今天要项目中要用到图片合成,所以看了下网上的资料和系统 API
图片合成可以用到很多的地方 添加水印 二维码生成的模板合成图片
//开始合成图片
/*
*1. 需要绘制的大小
*2. 背景是否是黑色
*3. scale 当前设备的是几倍大小像素 不知道怎么描述 就先这样说不明白可以评论交流
* 还有一个方法UIGraphicsBeginImageContext 大家用的比较多,单是默认只是生成一倍大小的图片,如果你用的事2X或者是3x 的图片绘制的话会模糊
*/
UIGraphicsBeginImageContextWithOptions(superImage.size, NO,[UIScreen mainScreen].scale);
//绘制最下面一层的图片
[superImage drawInRect:CGRectMake(0, 0, superImage.size.width, superImage.size.height)];
//绘制上层图片 当然可以绘制多个图片 一层一层的添加
[subImage drawInRect:posRect];
//获取会之后的 图片
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
// 绘制后结束
UIGraphicsEndImageContext();
-
.NET 图片合成,图片加文字,图片加二维码
2019-04-12 09:53:15.NET 图片合成,图片加文字,图片加二维码,可直接设置背景图绝对路径、要合成的图片地址、宽度、高度、margin-left、margin-top位置进行图片合成。 设置文字位置、文字大小进行图片文字合成,已在多个项目中使用。 -
php 图片合成imagick合成求助
2020-09-12 17:10:36# 请将第一第二图片合成为下列图片4: 图片4 ![图片3]... -
关于图片合成
2020-12-02 09:40:451.为什么要在iPhone模拟器上进行图片合成? 2.如果是安卓真机要怎么合成图片,依然可以在iPhone模拟器上进行合成吗? 不胜感激。</p><p>该提问来源于开源项目:fengjian0106/hed-tutorial-... -
图片合成视频
2020-11-29 18:59:33<div><p>你好,图片合成视频的命令有吗,我这边网上搜索命令运行出错</p><p>该提问来源于开源项目:yangjie10930/EpMedia</p></div> -
图片合成分割工具软件(exe)
2020-10-13 09:51:38图片合成分割工具 图片合成分割工具 图片合成分割工具 图片合成分割工具 图片合成分割工具 图片合成分割工具 图片合成分割工具 图片合成分割工具 图片合成分割工具 -
java 处理图片图片合成
2020-12-11 16:08:40最近写了一个java的图片合成相关的项目,真的是一踩一个坑,下面博主说说遇见的一些坑和怎么解决的这些问题。 本文主要讲图片合成,加文字还是比较简单的。 先讲下我的需求,把一张图片盖到另外一张图片上面,然后在...最近写了一个java的图片合成相关的项目,真的是一踩一个坑,下面博主说说遇见的一些坑和怎么解决的这些问题。 本文主要讲图片合成,加文字还是比较简单的。
先讲下我的需求,把一张图片盖到另外一张图片上面,然后在图片上加上字
第一个版本
最开始的时候我用的是thumbnailator工具包,如上图效果
但是问题来了,这张图有很大的问题,两个图都是透明度发生了变化。
第二个版本
使用java自带的Graphics2D
代码如下
String blackPath = ""; String fontPath = ""; // 水印图 URL frontUrl = new URL(fontPath); // 地图 URL blackUrl = new URL(blackPath); BufferedImage blackImage = ImageIO.read(blackUrl ); BufferedImage frontImage = ImageIO.read(frontUrl ); // 拉伸下 Thumbnails.Builder<BufferedImage> of = Thumbnails.of(blackImage).size(750, 750); blackImage = of.asBufferedImage(); Graphics2D g2d = blackImage.createGraphics(); // 在地图上绘制水印 g2d.drawImage(frontImage, 0, 0, 750, 750, null); g2d.dispose();
这个代码可以合成图片,但是有两个问题
- 图片失真
- 图片合成后在叠加的部分颜色发生了变化
第三个版本
使用Toolkit.getDefaultToolkit() 读取image
图片image转化为bufferImage方法
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage)image; } // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Determine if the image has transparent pixels; for this method's // implementation, see e661 Determining If an Image Has Transparent Pixels //boolean hasAlpha = hasAlpha(image); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { // Determine the type of transparency of the new buffered image int transparency = Transparency.OPAQUE; /* if (hasAlpha) { transparency = Transparency.BITMASK; }*/ // Create the buffered image GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); bimage = gc.createCompatibleImage( image.getWidth(null), image.getHeight(null), transparency); } catch (HeadlessException e) { // The system does not have a screen } if (bimage == null) { // Create a buffered image using the default color model int type = BufferedImage.TYPE_INT_RGB; //int type = BufferedImage.TYPE_3BYTE_BGR;//by wang /*if (hasAlpha) { type = BufferedImage.TYPE_INT_ARGB; }*/ bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); } // Copy image to buffered image Graphics g = bimage.createGraphics(); // Paint the image onto the buffered image g.drawImage(image, 0, 0, null); g.dispose(); return bimage; }
图片合成方法
String blackPath = ""; String fontPath = ""; // 水印图 URL frontUrl = new URL(fontPath); // 地图 URL blackUrl = new URL(blackPath); // 读取背景图 Image blackImage = Toolkit.getDefaultToolkit().getImage(blackUrl); // 读取水印图 Image frontImage = Toolkit.getDefaultToolkit().getImage(frontUrl); BufferedImage image = toBufferedImage(blackImage); // 拉伸下, Thumbnails.Builder<BufferedImage> of = Thumbnails.of(image).size(750, 750); image = of.asBufferedImage(); Graphics2D g2d = image.createGraphics(); // 在地图上绘制水印 g2d.drawImage(frontImage, 0, 0, 750, 750, null); g2d.dispose();
改进之后图片的失真问题解决了, 图片的颜色变化问题也解决了。
但是新问题又来了,合成的时候有时候成功有时候失败上面这个问题真的是日了狗了。
在这里抱怨一下,程序员不怕不成功的代码,就怕这代码有时候成功,有时候失败,最后我找到问题所在,这个读取image的方法它不是同步的,也就是说必须把它变成同步。
第四个版本
这个方法是把图片读取从异步变成同步
@Slf4j public class MediaTrackerRunner extends Applet implements Runnable { int speed = 5; private String path; public MediaTrackerRunner(String path) throws HeadlessException { this.path = path; } @Override public void init() { super.init(); } @Override public void run() { while (true) { repaint(); // 重绘 try { // 休眠,休眠时间根据图像显示速度计算 Thread.sleep(1000 / speed); } catch (InterruptedException e) { throw new RuntimeException(e); } } } /** * [简要描述]:<br/> 根据图片路径读取图片, 同步 * [详细描述]:<br/> * @return java.awt.Image * 2020/12/9 - 19:05 **/ public Image execute() { MediaTracker tracker = new MediaTracker(this); URL fontUrl = null; try { fontUrl = new URL(path); } catch (MalformedURLException e) { e.printStackTrace(); } // 此方法为异步 Image fotImage = Toolkit.getDefaultToolkit().getImage(fontUrl); tracker.addImage(fotImage, 1); try { tracker.waitForAll(); } catch (InterruptedException e) { e.printStackTrace(); } return fotImage; } }
楼主在本地添加参数-Djava.awt.headless=false调试并且运行成功,但是一上linux服务,fuck又不行
最后报错
Can’t connect to X11 window server using ‘:0.0′ as the value of the DISPLAY variable楼主去研究了下,最后得出结论,使用这个api必须系统要支持图形化操作界面
当到这里的时候,楼主想死的心都有了
最后改进
不能使用同步的方法了,经过我观察,总是水印图加载部分,或者加载失败。最后试了试水印图使用ImageIo.read方法来读取,代码如下
这个toBufferedImage方法在上面
String blackPath = ""; String fontPath = ""; // 水印图 URL frontUrl = new URL(fontPath); // 地图 URL blackUrl = new URL(blackPath); // 读取水印图 Image frontImage = ImageIO.read(frontUrl); // 读取背景图 Image blackImage = Toolkit.getDefaultToolkit().getImage(blackUrl); BufferedImage image = toBufferedImage(blackImage); // 拉伸下, Thumbnails.Builder<BufferedImage> of = Thumbnails.of(image).size(750, 750); image = of.asBufferedImage(); Graphics2D g2d = image.createGraphics(); // 在地图上绘制水印 g2d.drawImage(frontImage, 0, 0, 750, 750, null); g2d.dispose();
最后附图
最后还真的让楼主成功了,这些问题记录下,顺便述说下楼主的辛酸。如果哪位大佬有更好的方法,或者更好的工具包出来,欢迎指点。
-
图片合成视频OpenCV
2015-04-29 22:13:37利用OpenCV3.0,将多张图片合成一个视频。代码加可执行程序加样例图片。 图片合成视频OpenCV代码加执行程序加样例图片。 -
android 图片合成
2017-07-05 10:51:41android 图片合成图片合成
public static Bitmap potoMix(int direction, Bitmap... bitmaps) { if (bitmaps.length <= 0) { return null; } if (bitmaps.length == 1) { return bitmaps[0]; } Bitmap newBitmap = bitmaps[0]; // newBitmap = createBitmapForFotoMix(bitmaps[0],bitmaps[1],direction); for (int i = 1; i < bitmaps.length; i++) { newBitmap = createBitmapForFotoMix(newBitmap, bitmaps[i], direction); } return newBitmap; } private static Bitmap createBitmapForFotoMix(Bitmap first, Bitmap second, int direction) { if (first == null) { return null; } if (second == null) { return first; } int fw = first.getWidth(); int fh = first.getHeight(); int sw = second.getWidth(); int sh = second.getHeight(); Bitmap newBitmap = null; if (direction == 1) { newBitmap = Bitmap.createBitmap(fw + sw, fh > sh ? fh : sh, Config.ARGB_8888); Canvas canvas = new Canvas(newBitmap); canvas.drawBitmap(first, sw, 0, null); canvas.drawBitmap(second, 0, 0, null); } else if (direction == 2) { newBitmap = Bitmap.createBitmap(fw + sw, fh > sh ? fh : sh, Config.ARGB_8888); Canvas canvas = new Canvas(newBitmap); canvas.drawBitmap(first, 0, 0, null); canvas.drawBitmap(second, fw, 0, null); } else if (direction == 3) { newBitmap = Bitmap.createBitmap(sw > fw ? sw : fw, fh + sh, Config.ARGB_8888); Canvas canvas = new Canvas(newBitmap); canvas.drawBitmap(first, 0, sh, null); canvas.drawBitmap(second, 0, 0, null); } else if (direction == 4) { newBitmap = Bitmap.createBitmap(sw > fw ? sw : fw, fh + sh, Config.ARGB_8888); Canvas canvas = new Canvas(newBitmap); canvas.drawBitmap(first, 0, 0, null); canvas.drawBitmap(second, 0, fh, null); } return newBitmap; }
-
JS多张图片合成一张图片代码.zip
2019-07-11 10:43:38JS多张图片合成一张图片代码是一款基于canvas制作多张元素图片合成一张效果代码。
-
浙大版《数据结构(第2版)》题目集习题3.10 汉诺塔的非递归实现 (25分)
-
【数据分析-随到随学】机器学习模型及应用
-
LEInstaller.exe
-
MFC开发简单聊天程序
-
在谈静态磁化率的计算
-
线程
-
PHP响应button的onclick事件
-
国际专利分类IPC介绍.ppt
-
【数据分析-随到随学】数据分析基础及方法论
-
2021-01-20
-
跟我练内测小分队学习礼包
-
gcruntime-7.4.1-windows-installer.exe
-
MySQL数据库操作.doc
-
jquery如何判断浏览器是否是ie6
-
迈向高级的Java面试突围课
-
回流重绘方向的性能优化
-
(必背)670. 最大交换(贪心法)
-
axios 封装上传图片与thinkphp6.0后端接收图片
-
TCP粘包原因及解决办法
-
01-03vue学习资料.zip