| | |
| | | package com.se.simu.utils; |
| | | |
| | | import org.apache.commons.imaging.*; |
| | | import org.gdal.gdal.Band; |
| | | import org.gdal.gdal.Dataset; |
| | | import org.gdal.gdal.Band; |
| | | import org.gdal.gdal.gdal; |
| | | import org.gdal.gdalconst.gdalconstConstants; |
| | | |
| | |
| | | import java.io.IOException; |
| | | |
| | | public class TiffToRGBUtil { |
| | | public static void main(String[] args) throws Exception{ |
| | | tifToPng("D:\\城市内涝\\sem\\tongzhou_1m_tif\\tongzhou_raster_4548_1m_clip_river_fill.tif","D:\\城市内涝\\sem\\tongzhou_1m_tif\\tongzhou_raster_4548_1m_clip_river_fill.png"); |
| | | } |
| | | public static void tifToPng(String tifPath, String pngPath) throws Exception { |
| | | // 注册所有的 GDAL 驱动 |
| | | gdal.AllRegister(); |
| | |
| | | // 假设高度信息存储在像素值中 |
| | | double pixelHeight = pixelValue * geoTransform[5]; |
| | | //height = -10000 + ((R * 256 * 256 + G * 256 + B) * 0.1) |
| | | int value = (int) (pixelHeight + 10000) * 10; |
| | | int value = (int) ((pixelHeight + 10000) * 10); |
| | | //value=(R * 256 * 256 + G * 256 + B); |
| | | int r = value / (256 * 256); |
| | | value = value % (256 * 256); |
| | | int g = value / 256; |
| | | int b = value % 256; |
| | | Color color = new Color(r, g, b); |
| | | System.out.printf("Pixel (%d, %d): R=%d, G=%d, B=%d%n", x, y, r, g, b); |
| | | int newRgb = color.getRGB(); |
| | | // 将处理后的像素颜色值设置到新的 PNG 图像中 |
| | | pngImage.setRGB(x, y, newRgb); |