Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 在Groovy中从两个源png创建合成图像_Image Processing_Groovy_Png_Transparency_Filemaker - Fatal编程技术网

Image processing 在Groovy中从两个源png创建合成图像

Image processing 在Groovy中从两个源png创建合成图像,image-processing,groovy,png,transparency,filemaker,Image Processing,Groovy,Png,Transparency,Filemaker,我看过一些Groovy代码,它允许您将图像和文本进行组合,但不能将图像和图像进行组合 基本上,我需要在地图上的特定坐标处覆盖符号:我有一些地图和符号作为.png文件。我可以做坐标计算没有问题,所以问题更多的是,考虑到两个透明的PNG,如何在不失去透明度的情况下组合它们?(地图和符号可能都需要保持其透明度) 理想情况下,我需要一个函数,比如 combinePngImage(background_src, foreground_src, foreground_x, foreground_y) 给定

我看过一些Groovy代码,它允许您将图像和文本进行组合,但不能将图像和图像进行组合

基本上,我需要在地图上的特定坐标处覆盖符号:我有一些地图和符号作为.png文件。我可以做坐标计算没有问题,所以问题更多的是,考虑到两个透明的PNG,如何在不失去透明度的情况下组合它们?(地图和符号可能都需要保持其透明度)

理想情况下,我需要一个函数,比如

combinePngImage(background_src, foreground_src, foreground_x, foreground_y)
给定前景图像的左上角和右上角坐标,这将返回两者的png组合

[背景:我在FileMaker中的容器字段中存储了一些映射和符号作为.png文件,我需要将它们合并到FileMaker解决方案中。我曾尝试使用ImageMagick和命令行来实现这一点,但我突然想到,这可能是使用ScriptMaster可以实现的,ScriptMaster使用Groovy创建external职能。]


感谢收到所有的指针!

与其使用ImageMagick命令行,不如尝试使用纯Java ImageMagick API。

与其使用ImageMagick命令行,不如尝试使用纯Java ImageMagick API。

好吧,不管它值多少钱,这里是一些拼凑起来的烹饪书片段,似乎可以实现job-任何关于(糟糕的)编码风格的评论都被广泛接受

给ScriptMaster调用

combineImage ( backgroundImg ; foregroundImg ; x ; y )
所需代码为:

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;

// get container data
InputStream bgImgContainer

try{
  bgImgContainer = fmpro.getContainerStream(backgroundImg)
}catch(e){
  throw new Exception('Could not get data from background image container (make sure container field name is passed as text)')
}

// test if container field is empty
if( bgImgContainer == null ) {
  throw new Exception('Background image container field is empty')
}

bgImgName = fmpro.getContainerFileName(backgroundImg);

InputStream fgImgContainer

try{                                         
  fgImgContainer = fmpro.getContainerStream(foregroundImg)
}catch(e){
  throw new Exception('Could not get data from foreground image container (make sure container field name is passed as text)')
}

// test if container field is empty
if( fgImgContainer == null ) {
  throw new Exception('Foreground image container field is empty')
}

fgImgName = fmpro.getContainerFileName(foregroundImg);

int xCoord = Integer.parseInt(x);
int yCoord = Integer.parseInt(y);

// load image from container data
BufferedImage result = ImageIO.read(bgImgContainer);
BufferedImage overlay = ImageIO.read(fgImgContainer);

int fgWidth  = overlay.getWidth(null);
int fgHeight = overlay.getHeight(null);

Graphics2D graphics = result.createGraphics();

// overlay the foreground at given coordinates and actual size
graphics.drawImage(overlay, xCoord, yCoord, fgWidth, fgHeight, null);

graphics.dispose();

File output = File.createTempFile(bgImgName, ".png");
ImageIO.write(result, "png", output);
return output;

好吧,值得一提的是——这里有一些拼凑而成的烹饪书片段,似乎很管用——关于(糟糕的)编码风格的任何评论都广受欢迎

给ScriptMaster调用

combineImage ( backgroundImg ; foregroundImg ; x ; y )
所需代码为:

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;

// get container data
InputStream bgImgContainer

try{
  bgImgContainer = fmpro.getContainerStream(backgroundImg)
}catch(e){
  throw new Exception('Could not get data from background image container (make sure container field name is passed as text)')
}

// test if container field is empty
if( bgImgContainer == null ) {
  throw new Exception('Background image container field is empty')
}

bgImgName = fmpro.getContainerFileName(backgroundImg);

InputStream fgImgContainer

try{                                         
  fgImgContainer = fmpro.getContainerStream(foregroundImg)
}catch(e){
  throw new Exception('Could not get data from foreground image container (make sure container field name is passed as text)')
}

// test if container field is empty
if( fgImgContainer == null ) {
  throw new Exception('Foreground image container field is empty')
}

fgImgName = fmpro.getContainerFileName(foregroundImg);

int xCoord = Integer.parseInt(x);
int yCoord = Integer.parseInt(y);

// load image from container data
BufferedImage result = ImageIO.read(bgImgContainer);
BufferedImage overlay = ImageIO.read(fgImgContainer);

int fgWidth  = overlay.getWidth(null);
int fgHeight = overlay.getHeight(null);

Graphics2D graphics = result.createGraphics();

// overlay the foreground at given coordinates and actual size
graphics.drawImage(overlay, xCoord, yCoord, fgWidth, fgHeight, null);

graphics.dispose();

File output = File.createTempFile(bgImgName, ".png");
ImageIO.write(result, "png", output);
return output;

我将对此进行研究……但代码需要在FileMaker内部运行的插件中运行。如果我要这样做,我希望使用Groovy纯代码路由,而不是依赖外部调用。我将对此进行研究……但代码需要在FileMaker内部运行的插件中运行。我希望使用Groovy纯代码路由如果我要这样做的话,就不用依赖外部电话了。