From cdf4040c6cb8c7f3f200d64f754b6773554c6555 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 08 十月 2024 15:27:51 +0800 Subject: [PATCH] 1 --- src/main/java/com/se/simu/service/ResultService.java | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/se/simu/service/ResultService.java b/src/main/java/com/se/simu/service/ResultService.java index b40b757..00aa1cd 100644 --- a/src/main/java/com/se/simu/service/ResultService.java +++ b/src/main/java/com/se/simu/service/ResultService.java @@ -8,7 +8,6 @@ import com.se.simu.domain.dto.ResultDto; import com.se.simu.helper.GdalHelper; import lombok.extern.slf4j.Slf4j; -import nonapi.io.github.classgraph.utils.FileUtils; import org.gdal.gdal.Band; import org.gdal.gdal.Dataset; import org.gdal.gdal.WarpOptions; @@ -461,7 +460,35 @@ } private static void createFlowPng(float[] vxBuffer, float[] vyBuffer, String png, int width, int height) { - // + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + Graphics2D graphic = image.createGraphics(); + Color transparent = new Color(0, 0, 0, 0); + graphic.setColor(transparent); + graphic.clearRect(0, 0, width, height); + + // 鐢� R閫氶亾琛ㄧず锛屾祦鍚戜负褰掍竴鍖栫殑浜岀淮鍚戦噺锛坸,y锛夛紝G閫氶亾琛ㄧず涓� x *255 , B閫氶亾琛ㄧず涓� y * 255 + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + int offset = x + y * width; + float fx = getFloatValue(vxBuffer[offset]); + float fy = getFloatValue(vyBuffer[offset]); + if (Float.isNaN(fx) && Float.isNaN(fy) || (fx == 0 && fy == 0)) continue; + + fx = Float.isNaN(fx) ? 0 : fx; + fy = Float.isNaN(fy) ? 0 : fy; + double dr = Math.sqrt(Math.pow(fx, 2) + Math.pow(fy, 2)); + + int r = (int) (dr / 4 * 255); + int g = (int) ((fx / dr * 0.5 + 0.5) * 255); + int b = (int) ((fy / dr * 0.5 + 0.5) * 255); + + Color color = new Color(getSafeValue(r), getSafeValue(g), getSafeValue(b), 127); + //image.setRGB(x, y, color.getRGB()); + graphic.drawImage(image, x, y, 1, 1, color, null); + } + } + graphic.dispose(); + savePng(image, png); } private static float getFloatValue(float val) { -- Gitblit v1.9.3