獲取圖片座標,後端使用Graphics2D畫圖
阿新 • • 發佈:2021-10-28
獲取圖片座標:
img標籤中加入
@click='tapMap($event)'tapMap(e){ letx=e.layerX; lety=e.layerY; },
和Graphics2D座標不一致需要減去偏移量。
Graphics2D讀取圖片並畫圖:
public void createImg() throws IOException { BufferedImage bufferedImage = null; try { bufferedImage = ImageIO.read(new FileInputStream("D:\\1.png")); }catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } Graphics2D graphics2D = (Graphics2D) bufferedImage.getGraphics(); graphics2D.setBackground(Color.RED); graphics2D.clearRect(33,34,20,20); graphics2D.setPaint(Color.BLUE); graphics2D.drawRect(33, 34, 20, 20); try { ImageIO.write(bufferedImage, "png",new FileOutputStream("D:\\2.png")); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }