To: asjj() 但是有个问题不知道你想过没有,这个数值数组将会非常大,可能会OutOfMemory,通常这样处理几K的图片没有问题,几十K的图片就比较缓慢了,何况是整屏的图象,难以想象啊。 ----------------------------------------------------------------------------------------- 我确实没想过数组的容量问题,但是我想知道的是:数组里边存放的是什么值呢?谢谢!
截屏用这个,非常简单,提示你一下,后面的自己写吧java.awt.Robot createScreenCapture public BufferedImage createScreenCapture(Rectangle screenRect) Creates an image containing pixels read from the screen. Parameters: screenRect - Rect to capture in screen coordinates Returns: The captured image Throws: IllegalArgumentException - if screenRect width and height are not greater than zero SecurityException - if readDisplayPixels permission is not granted See Also: SecurityManager.checkPermission(java.security.Permission), AWTPermission
问题是截屏可能要调用系统API。
数组好办。
问题是截屏可能要调用系统API。
-------------------------------
我有点不太明白,愿闻其详。谢谢先!!
如果我理解没错的话你是首先要ctrl+print screen抓屏(这个可能要调用dll),然后转换成java Image获得图象数值数组?调用哪个dll我就不清楚了,知道了调用一下也好办。我倒是非常有兴趣试下。但是有个问题不知道你想过没有,这个数值数组将会非常大,可能会OutOfMemory,通常这样处理几K的图片没有问题,几十K的图片就比较缓慢了,何况是整屏的图象,难以想象啊。
但是有个问题不知道你想过没有,这个数值数组将会非常大,可能会OutOfMemory,通常这样处理几K的图片没有问题,几十K的图片就比较缓慢了,何况是整屏的图象,难以想象啊。
-----------------------------------------------------------------------------------------
我确实没想过数组的容量问题,但是我想知道的是:数组里边存放的是什么值呢?谢谢!
255,255,255
int[] pixels={...,255,255,255,...}
截屏的图象大小是1024*768,那么
int[] pixels大小就是pixels=new int[1024*768*3]
截屏用这个,非常简单,提示你一下,后面的自己写吧java.awt.Robot
createScreenCapture
public BufferedImage createScreenCapture(Rectangle screenRect)
Creates an image containing pixels read from the screen. Parameters:
screenRect - Rect to capture in screen coordinates
Returns:
The captured image
Throws:
IllegalArgumentException - if screenRect width and height are not greater than zero
SecurityException - if readDisplayPixels permission is not granted
See Also:
SecurityManager.checkPermission(java.security.Permission), AWTPermission
谢谢你给的这个方法,我想知道的是:
方法public BufferedImage createScreenCapture(Rectangle screenRect)的返回值是BufferedImage类型,那么怎样得到这个图像的值呢?另外,图象的值只能是它的象素值吗,还有其他值可得吗?谢谢。
To: asjj()
这个数组确实太大了:(
那表征图像的还有什么值,而且这个值我们可以得到的呢?
我对图象处理方面知道的不多,因为作毕业设计会用到一些,所以会麻烦到各位,真是不好意思。不过,我也长了不少见识,在这里再次真心表示谢意,并会将谢意付诸实际,加分相送!
可以详细一点描述以下你做过的程序马?
我要做的是:先截屏,然后转换为数组形式并发送到远程客户端,客户端再将数组“组装”从而显示截取得图像。另外,你认为这样的功能应该怎样实现比较合适呢?我现在优点怀疑我最初的想法是否合理了:(
向你要求的这种功能就简单多了,截图我没弄过,不过当你已经有了图片的时候,你可以用imageIO将图片用某种格式编码成数据,然后在网络上传递这些数据就行了啊。
.......
我的意思刚被大家弄明白,不好意思,是我的失误,那么,各位大侠请帮帮忙吧,可以给我写代码示例吗?谢谢谢谢...
我可以向 binny(骑个破车看夕阳) 请教如何截屏,向 eyes2near(eyes2near) 请教编码,这样我的问题就好说了:)...请两位大侠帮忙。
传二进制数据?我没想过,因为我对图象处理方面知之甚少,惭愧...只是做毕业设计用到一部分。所以...
那么,二进制数据市图像的什么数据呢?怎么传?
另外,binny(骑个破车看夕阳) 、eyes2near(eyes2near)两位大侠,你们怎么不理我了?是不是问题太简单了?不够我还是希望得到你们的帮助,谢谢先...
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize); try {
File fileout = new File("serverState.jpg"); if (fileout.exists()) {
fileout.delete();
} Robot robot = new Robot();
BufferedImage image = robot.createScreenCapture(screenRect);
ImageIO.write(image, "jpg", fileout);
}
catch(AWTException e) {
System.err.println(e.toString());
}
catch(IOException e) {
System.err.println(e.toString());
}
把图片当作流传送出去: requestedFile = new File("serverState.jpg");
FileInputStream fs = new FileInputStream(requestedFile); int fileLength = (int)requestedFile.length();
byte[] requestedData = new byte[fileLength];
fs.read(requestedData);
fs.close(); if(httpVersion.startsWith("HTTP/")) {
os.print("HTTP/1.0 200 OK\r\n");
Date now = new Date();
os.print("Date: " + now + "\r\n");
os.print("Server: SimpleRemoteState v0.1\r\n");
os.print("Content-type: text/html\r\n\r\n");
}
os.write(requestedData);
os.close(); 再配合Socket建立连接,这个程序很容易就完成了自己多动手,多动脑。
BufferedImage buffimg= ImageIO.read(new File("C:\\sample.jpg"));// 取得彩色图的 RGB 像素数组。
DataBufferInt dbi = (DataBufferInt) (buffimg.getRaster().getDataBuffer());
int[] pixels = dbi.getData();
谢谢几位大侠相助。 eyes2near(eyes2near) 说得对!我先自己试试,有问题还得请教各位,希望还会得到你们的帮助,谢谢先。
实现诺言的时候到了,揭帖送分。不够我的分不太多,请不要见笑...