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.