zhanghua
2025-03-04 b8d8733ad9eeeb170a71897d1078acdbea7680f2
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.dahua.netsdk.module.entity;
 
import com.sun.jna.Memory;
 
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
 
/**
 * @author 47081
 * @version 1.0
 * @description 图片信息,用于一些接口需要传入图片信息和图片数据
 * @date 2021/4/26
 */
public class PictureInfo {
  private static BufferedImage bufferedImage;
  private static ByteArrayOutputStream byteArrayOutputStream;
  private int length;
  private int width;
  private int height;
  private Memory memory;
 
  public int getLength() {
    return length;
  }
 
  public void setLength(int length) {
    this.length = length;
  }
 
  public int getWidth() {
    return width;
  }
 
  public void setWidth(int width) {
    this.width = width;
  }
 
  public int getHeight() {
    return height;
  }
 
  public void setHeight(int height) {
    this.height = height;
  }
 
  public Memory getMemory() {
    return memory;
  }
 
  public void setMemory(Memory memory) {
    this.memory = memory;
  }
 
  /**
   * 读取图片数据
   *
   * @param picture 图片的字节数组
   * @return
   */
  public static PictureInfo generate(byte[] picture) {
    try {
      bufferedImage = ImageIO.read(new ByteArrayInputStream(picture));
      byteArrayOutputStream = new ByteArrayOutputStream();
      ImageIO.write(bufferedImage, "jpg", byteArrayOutputStream);
      byte[] data = byteArrayOutputStream.toByteArray();
      PictureInfo info = new PictureInfo();
      info.length = data.length;
      info.width = bufferedImage.getWidth();
      info.height = bufferedImage.getHeight();
      info.memory = new Memory(info.length);
      info.memory.write(0, data, 0, data.length);
      return info;
    } catch (IOException e) {
      e.printStackTrace();
    }
    return new PictureInfo();
  }
}