本人JAVA刚入门,希望能够编个小软件进行图片切割。例如,将数学试卷扫描后,按照题号将试卷进行切割,最终将切割完的部分保存。现在找了很多图形学 的书,似乎都没有什么大的进展,不知道该怎样处理,希望大家可以帮帮忙,并解答详细些。谢谢
解决方案 »
- 开发语言互相调用
- 如何取得用户ID~(谢谢!急,在线等)
- Thread.sleep()睡眠的准确时间是括号里的指定时间吗?
- 关于createImage,能帮上忙的都给分,分不够再加
- 什么是JAVA卡
- 请问如何转换时间字符串成为GregorianCalendar类
- 日期转换问题
- 通过main(String argv[])的argv[]接收一个数字字符,怎样转换成int啊?谢谢,
- PreparedStatement是在什么时候预编译呀?
- 怎么解决A java exception has occurred,求救求救..........
- 如何多次使用一个inputstream?
- 打算学JSP,想听听大家对JSP学习的意见
建议看图象识别的书,或找相关网站咨询,我估计这里会的人可能不会很多。
* Computes and returns an arbitrary region of the
* <code>BufferedImage</code>. The <code>Raster</code> returned is a
* copy of the image data and is not updated if the image is
* changed.
* @param rect the region of the <code>BufferedImage</code> to be
* returned.
* @return a <code>Raster</code> that is a copy of the image data of
* the specified region of the <code>BufferedImage</code>
* @see #setData(Raster)
*/
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;import javax.imageio.ImageIO;public class ImageTest
{ public static void main(String[] args)
{
try {
BufferedImage image = ImageIO.read(new File("test.jpg"));
saveSubImage(image, new Rectangle(10, 10, 100, 100), new File("sub1.jpg"));
saveSubImage(image, new Rectangle(150, 150, 200, 300), new File("sub2.png"));
saveSubImage(image, new Rectangle(20, 50, 70, 30), new File("sub3.bmp"));
} catch (IOException e) {
e.printStackTrace();
return;
}
} private static void saveSubImage(BufferedImage image,
Rectangle subImageBounds, File subImageFile) throws IOException {
if (subImageBounds.x <= 0 || subImageBounds.y <= 0 ||
subImageBounds.x + subImageBounds.width >= image.getWidth() ||
subImageBounds.y + subImageBounds.height >= image.getHeight()) {
System.out.println("Bad subimage bounds");
return;
}
BufferedImage subImage = image.getSubimage(
subImageBounds.x, subImageBounds.y,
subImageBounds.width, subImageBounds.height);
String fileName = subImageFile.getName();
String formatName = fileName.substring(fileName.lastIndexOf('.') + 1); ImageIO.write(subImage, formatName, subImageFile);
}
}
更要多谢gtlang78()
我的问题解决了。
作为菜鸟的我,你们的指点无疑给我增添了很多信心。呵呵