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();
}
}
上面给出的是一个java代码,通过用一组4个像素替换每个像素来调整图像大小,保持组中的对角像素与原始图像中的颜色相同。我们考虑的图像是黑白的二值图像颜色。但现在的问题是如何从调整大小的图像中检索原始图像。请帮助我们。