如何使用 Java 读取复制粘贴图片



问题描述

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

解决方案

以下是使用 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 ............");
   }
}

输入

OpenCV Copy Input

输出

OpenCV Copy Input
java_opencv
广告