|
|
@@ -90,38 +90,45 @@ public class TbVmsDsplHsService {
|
|
|
try {
|
|
|
dto.setImagData(createVmsDsplImage(dto.getImagFmt(), obj.getVms(), id, obj.getVmsDsplMsgData(), obj.getDsplPhaseNum()));
|
|
|
result.add(dto);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (ImageReadException e) {
|
|
|
- e.printStackTrace();
|
|
|
+ } catch (IOException | ImageReadException e) {
|
|
|
+ log.error("{}", e.getMessage());
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * VMS 이미지를 그린다
|
|
|
+ * @param imagFmt
|
|
|
+ * @param obj
|
|
|
+ * @param id
|
|
|
+ * @param msgData
|
|
|
+ * @param phaseNum
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ * @throws ImageReadException
|
|
|
+ */
|
|
|
public byte[] createVmsDsplImage(String imagFmt, TbVmsCtlr obj, Long id, String msgData, int phaseNum) throws IOException, ImageReadException {
|
|
|
+
|
|
|
String saveDir = ItsUtils.createUserDir("/image/vms/dspl-hs/");
|
|
|
if (obj == null || obj.getType() == null) {
|
|
|
log.error("Not Found VMS Controller: {}, {}", id, obj);
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- //log.error("msgData: {}, {}", phaseNum, msgData);
|
|
|
-
|
|
|
//int formKind = Integer.parseInt(msgData.substring(0, 2), 16);
|
|
|
//int dispTime = Integer.parseInt(msgData.substring(2, 4), 16);
|
|
|
int formColor = Integer.parseInt(msgData.substring(4, 6), 16);
|
|
|
- //log.error("{}, {}, {}", formKind, dispTime, formColor);
|
|
|
|
|
|
/**
|
|
|
* 배경 이미지를 만든다.
|
|
|
*/
|
|
|
int width = obj.getType().getVmsWdth();
|
|
|
int height = obj.getType().getVmsHght();
|
|
|
- //BufferedImage imgBack = createBitmap(obj.getType().getVmsWdth(), obj.getType().getVmsHght(), getCodeColor(formColor));
|
|
|
- BufferedImage formImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);//TYPE_INT_ARGB);
|
|
|
- Graphics2D g2d = (Graphics2D)formImage.getGraphics();
|
|
|
+ // TYPE_INT_ARGB specifies the image format: 8-bit RGBA packed
|
|
|
+ BufferedImage formImage = new BufferedImage(width, height, (imagFmt.equals("png") ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB));
|
|
|
+ Graphics2D g2d = (Graphics2D)formImage.createGraphics(); //createGraphics();getGraphics();
|
|
|
//g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
g2d.setColor(getColor(formColor));
|
|
|
g2d.fillRect(0, 0, width, height);
|
|
|
@@ -148,19 +155,19 @@ public class TbVmsDsplHsService {
|
|
|
|
|
|
/**
|
|
|
* 문자를 이미지에 그린다.
|
|
|
+ * 1.35f : 텍스트상자 패딩값
|
|
|
*/
|
|
|
- //int screenRes = Toolkit.getDefaultToolkit().getScreenResolution();
|
|
|
- //fontSize = (int)Math.round(fontSize * screenRes / 72.0);
|
|
|
-
|
|
|
//g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
- fontSize = (int)(fontSize * (float)1.35);
|
|
|
- int fontStyle = fontBold == 1 ? Font.BOLD : Font.PLAIN;
|
|
|
+ //g2d.setFont(g2d.getFont().deriveFont(g2d.getFont().getSize() * 1.35f));
|
|
|
+ int fontStyle = (fontBold == 1) ? Font.BOLD : Font.PLAIN;
|
|
|
Font txtFont = new Font(getFontName(fontName), fontStyle, fontSize);
|
|
|
+ txtFont = txtFont.deriveFont(fontSize * 1.35f);
|
|
|
g2d.setFont(txtFont);
|
|
|
+ FontMetrics fm = g2d.getFontMetrics(txtFont);
|
|
|
g2d.setColor(getColor(fontColor));
|
|
|
- /*FontMetrics fontMetrics = g2d.getFontMetrics(txtFont);
|
|
|
- g2d.drawString(text, left, top + fontMetrics.getHeight() - fontMetrics.getDescent() - fontMetrics.getLeading());*/
|
|
|
- g2d.drawString(text, left, top + fontSize);
|
|
|
+ g2d.drawString(text, left, top + fm.getAscent());//fm.getHeight() - fm.getDescent() - fm.getLeading());
|
|
|
+ //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ //g2d.drawString(text, left, top + fontSize);
|
|
|
}
|
|
|
else if (objType == 2) { // symbol id
|
|
|
String symbLibId = tmp.substring(16, tmp.length());
|
|
|
@@ -215,7 +222,7 @@ public class TbVmsDsplHsService {
|
|
|
floodFill.fill(cellX, cellY, getTrafColor(gradF));
|
|
|
}
|
|
|
}
|
|
|
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ //g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
g2d.drawImage(floodFill.getImage(), left, top, imgBmp.getWidth(null), imgBmp.getHeight(null), null);
|
|
|
}
|
|
|
}
|
|
|
@@ -231,7 +238,6 @@ public class TbVmsDsplHsService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //ItsUtils.saveImageFile(formImage, "bmp", saveDir+phaseNum + ".bmp");
|
|
|
ItsUtils.saveImageFile(formImage, imagFmt, saveDir + obj.getVmsCtlrNmbr() + "_" + phaseNum + "." + imagFmt);
|
|
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
@@ -280,13 +286,5 @@ public class TbVmsDsplHsService {
|
|
|
if (grad == 3) return Color.RED;
|
|
|
return Color.GRAY;
|
|
|
}
|
|
|
- public BufferedImage createBitmap(int w, int h, int bkColor) {
|
|
|
- final BufferedImage res = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
|
|
|
- for (int x = 0; x < w; x++){
|
|
|
- for (int y = 0; y < h; y++){
|
|
|
- res.setRGB(x, y, bkColor);
|
|
|
- }
|
|
|
- }
|
|
|
- return res;
|
|
|
- }
|
|
|
+
|
|
|
}
|