Alejandro Acuña
2024-07-30 65a64a81d30f00f1fffd5da6866850e1308e1135
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
    }
    
}