- Java Programming Examples
- Example - Home
- Example - Environment
- Example - Strings
- Example - Arrays
- Example - Date & Time
- Example - Methods
- Example - Files
- Example - Directories
- Example - Exceptions
- Example - Data Structure
- Example - Collections
- Example - Networking
- Example - Threading
- Example - Applets
- Example - Simple GUI
- Example - JDBC
- Example - Regular Exp
- Example - Apache PDF Box
- Example - Apache POI PPT
- Example - Apache POI Excel
- Example - Apache POI Word
- Example - OpenCV
- Example - Apache Tika
- Example - iText
- Java Tutorial
- Java - Tutorial
- Java Useful Resources
- Java - Quick Guide
- Java - Useful Resources
How to read copy and paste an image using Java
Problem Description
How to read copy and paste an image using Java.
Solution
Following is the program to copy and paste an image using 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
Output
java_opencv
Advertisements