Reputation: 19
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.image.WritableRaster;
public class drim {
public static void drimage() {
try {
BufferedImage input =
ImageIO.read( new File( "/root/project/de.jpg" ));
int w = input.getWidth();
int h = input.getHeight();
int h1 = h * 2;
int w1 = w * 2;
BufferedImage im = new BufferedImage( w1, h1,
BufferedImage.TYPE_BYTE_BINARY );
WritableRaster raster = im.getRaster();
for( int i = 0; i < w; i++ ) {
for( int j = 0; j < h; j++ ) {
int rgb = input.getRGB( i, j );
if( rgb == -1 ) {
raster.setSample( i * 2, j * 2, 0, 1 );
raster.setSample( i * 2, ( j * 2 ) + 1, 0, 0 );
raster.setSample( ( i * 2 ) + 1, j * 2, 0, 0 );
raster.setSample( ( i * 2 ) + 1, ( j * 2 ) + 1, 0, 1 );
} else {
raster.setSample( i * 2, j * 2, 0, 0 );
raster.setSample( i * 2, ( j * 2 ) + 1, 0, 1 );
raster.setSample( ( i * 2 ) + 1, j * 2, 0, 1 );
raster.setSample( ( i * 2 ) + 1, ( j * 2 ) + 1, 0, 0 );
}
}
}
ImageIO.write( im, "JPG", new File( "/root/project/dde.jpg" ) );
}
catch( Exception e )
{
e.printStackTrace();
}
}
public static void main( String[] args ) throws IOException {
drimage();
}
}
The above given is a java code for resizing the image by substituting each pixel by a group of 4 pixels keeping the diagonal pixel in the group with the same color as in the original image.The images we consider is a binary image with black and white colors. But the problem now is how to retrieve the original image from the resized image. Please help us.
Upvotes: 1
Views: 1049
Reputation: 6050
You might want to look into ImageMagick to do the resizing for you. You'll need to install the ImageMagick pkg on your server since the IM4Java API just makes the command line calls for you from your Java program.
http://im4java.sourceforge.net/ - Java API/developer guide, etc.
http://www.imagemagick.org/script/command-line-options.php#resize - imagemagick app tutorial
If you don't like imagemagick, there are other image manipulation APIs out there but I can't comment on them since I haven't use them before.
Upvotes: 1