package art.servers.gost.access.utils; import art.library.model.devices.gost.access.information.AccessEnforcementInformation_OSD; import art.library.model.devices.gost.access.types.AccessEnforcement_Detection; import art.library.model.devices.gost.access.types.AccessEnforcement_Detection_Image; import art.servers.gost.access.Shared; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.text.SimpleDateFormat; import javax.imageio.ImageIO; public class OSD { public static AccessEnforcement_Detection_Image osd(AccessEnforcement_Detection detection, AccessEnforcement_Detection_Image image, AccessEnforcementInformation_OSD osd) { try { if (osd != null) { SimpleDateFormat formato1 = new SimpleDateFormat(Shared.getMessage("dd/MM/yyyy HH:mm:ss")); ByteArrayInputStream bis = new ByteArrayInputStream(image.data); BufferedImage bufferedimage = ImageIO.read(bis); bis.close(); Graphics2D g2 = (Graphics2D)bufferedimage.getGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HBGR); g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); String text = " " + formato1.format(detection.timestamp) + " - " + detection.device.location + " - " + detection.device.model + ", " + Shared.getMessage("s/n")+ " " + detection.device.serial; g2.setFont(new Font(osd.font, osd.type, osd.size)); Rectangle2D rectangle = g2.getFont().getStringBounds(text, g2.getFontRenderContext()); g2.setColor(Color.black); g2.fill(new Rectangle2D.Double(0,0,bufferedimage.getWidth(),rectangle.getHeight())); g2.setColor(Color.white); g2.drawString(text, (float)rectangle.getX(), (float)-rectangle.getY()); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ImageIO.write(bufferedimage, image.format, bos); image.data = bos.toByteArray(); bos.close(); } } catch (Exception exception) { } return image; } }