This how-to demonstrates how to crop an image using Java and Marvin.

First, use static import for MarvinPluginCollection class to have access to its static methods directly on your class.

import static marvin.MarvinPluginCollection.*;

You can crop an image using crop(...) passing the x,y coordinates and the width and height of the subimage.

original:


cropped:


Source:

MarvinImage image = MarvinImageIO.loadImage("./res/famousFace.jpg");
crop(image.clone(), image, 60, 32, 182, 62);
MarvinImageIO.saveImage(image, "./res/famousFace_cropped.jpg");

Was this how-to helpful? Share it:

Do not you know how to setup Marvin? Read how to develop your First Application.