gpt4 book ai didi

java - 如何在javafx中删除图像中的空格

转载 作者:行者123 更新时间:2023-12-01 13:49:45 26 4
gpt4 key购买 nike

我有一个位于屏幕顶部中央的图像,我想删除它周围的空白区域。我将如何能够做到这一点?如果您需要查看我的代码,请说出来。

相关代码

package whowantstobeamillionairetriviagame;

import java.io.File;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class WhoWantsToBeAMillionaireTriviaGame extends Application
{
@Override
public void start(Stage startingStage) throws Exception
{
StackPane backgroundSettings = new StackPane();

Image backgroundColor = new Image("http://1.bp.blogspot.com/-p0s06MBIx_U/T8zKIBZ24pI/AAAAAAAAA7Y/n8hMZfpRic0/s1600/dark+blue+wallpaper+10.jpg");

ImageView background = new ImageView();
background.setImage(backgroundColor);

Image millionaireLogo = new Image(new File("MillionaireLogo.PNG").toURI().toString());

ImageView logoPicture = new ImageView();
logoPicture.setImage(millionaireLogo);
logoPicture.setPreserveRatio(true);
logoPicture.setSmooth(true);
logoPicture.setCache(true);
StackPane.setAlignment(logoPicture, Pos.TOP_CENTER);

backgroundSettings.getChildren().addAll(background, logoPicture);

Scene backgroundScene = new Scene(backgroundSettings);
startingStage.setScene(backgroundScene);

startingStage.setTitle("Who Wants to be a Millionaire");
startingStage.show();
}

public static void main(String[] args)
{
launch(args);
}
}

这是结果的截图 Screen with an image and whitespaces

最佳答案

一种选择是通过 java 代码调用 imagemagick 来修剪空格:
http://www.imagemagick.org/Usage/crop/#trim

这是java代码(先决条件是安装ImageMagick):

String trimCmd = "convert " + this.fileName + " -trim " + origFile;
try {
Process process = Runtime.getRuntime().exec(trimCmd);
process.waitFor();
} catch (Exception e) {
Log.exception(e);
return;
}

关于java - 如何在javafx中删除图像中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29471043/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com