How to read copy and paste an image using Java (read/write).

优质
小牛编辑
124浏览
2023-12-01

问题描述 (Problem Description)

如何使用Java读取复制和粘贴图像。

解决方案 (Solution)

以下是使用Java复制和粘贴图像的程序。

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
public class CopyAndPasteAnImage {
   public static void main(String args[]) {
      //Loading the OpenCV core library
      System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
      //Reading the Image from the file and storing it in to a Matrix object
      String file = "C:/opencv/logo.jpg";
      Mat matrix = Imgcodecs.imread(file);
      System.out.println("Image Loaded ..........");
      String file2 = "C:/opencv/logoResaved.jpg";
      //Writing the image
      Imgcodecs.imwrite(file2, matrix);
      System.out.println("Image Saved ............");
   }
}

输入 (Input)

OpenCV复制输入

输出 (Output)

OpenCV复制输入