Open GoogleCodeExporter opened 9 years ago
same problem on Nexus S
Original comment by g.jjoe64
on 29 Jun 2011 at 2:50
Attachments:
Similar issue I faces on HTC G2, Nexus S, Samsung Vibrant +. Any solution pls.
Original comment by grv...@gmail.com
on 29 Jul 2011 at 7:18
[deleted comment]
[deleted comment]
could you please tell me the fix?
Original comment by g.jjoe64
on 28 Nov 2011 at 7:08
private Screenshot retreiveRawScreenshot() throws Exception {
try {
// connect to native application
//We use SocketChannel,because is more convenience and fast
SocketChannel socket = SocketChannel.open(new InetSocketAddress("localhost", PORT));
socket.configureBlocking(false);
//Send Commd to take screenshot
ByteBuffer cmdBuffer = ByteBuffer.wrap("SCREEN".getBytes("ASCII"));
socket.write(cmdBuffer);
//build a buffer to save the info of screenshot
//3 parts,width height cpp
byte[] info = new byte[3 + 3 + 2 + 2];//3 bytes width + 1 byte space + 3 bytes heigh + 1 byte space + 2 bytes bpp
ByteBuffer infoBuffer = ByteBuffer.wrap(info);
//we must make sure all the data have been read
while(infoBuffer.position() != infoBuffer.limit())
socket.read(infoBuffer);
//we must read one more byte,because after this byte,we will read the image byte
socket.read(ByteBuffer.wrap(new byte[1]));
//set the position to zero that we can read it.
infoBuffer.position(0);
StringBuffer sb = new StringBuffer();
for(int i = 0;i < (3 + 3 + 2 + 2);i++)
{
sb.append((char)infoBuffer.get());
}
String[] screenData = sb.toString().split(" ");
if (screenData.length >= 3) {
Screenshot ss = new Screenshot();
ss.width = Integer.parseInt(screenData[0]);
ss.height = Integer.parseInt(screenData[1]);
ss.bpp = Integer.parseInt(screenData[2]);
// retreive the screenshot
// (this method - via ByteBuffer - seems to be the fastest)
ByteBuffer bytes = ByteBuffer.allocate (ss.width * ss.height * ss.bpp / 8);
while(bytes.position() != bytes.limit())
{
//in the cycle,we must make sure all the image data have been read,maybe sometime the socket will delay a bit time and return some invalid bytes.
socket.read(bytes); // reading all at once for speed
}
bytes.position(0); // reset position to the beginning of ByteBuffer
ss.pixels = bytes;
return ss;
}
}
catch (Exception e) {
throw new Exception(e);
}
finally {}
return null;
}
Original comment by cwlay90...@gmail.com
on 8 Dec 2011 at 1:56
It's work, thanks a lot.
Original comment by ggx1...@gmail.com
on 9 Dec 2011 at 3:45
Thanks a lot!!
Original comment by dERos...@gmail.com
on 15 Jul 2012 at 10:03
thanks it works
Original comment by jitendra...@gmail.com
on 4 Sep 2012 at 12:11
What is the correct PORT? and What is the Screenshot object?
Original comment by grego...@gmail.com
on 21 Jan 2013 at 11:29
/*
* Port number used to communicate with native process.
*/
private static final int PORT = 42380;
Please check ScreenshotService.java for above details, and better understanding
use demo project from download.
Original comment by dERos...@gmail.com
on 22 Jan 2013 at 3:34
what is < and > in ur code
Original comment by gnr19...@gmail.com
on 28 Feb 2013 at 4:39
I saw this issue lately! I fixed this issue by modifying original source below
"part of retreiveRawScreenshot moethod"
org:
// retreive the screenshot
// (this method - via ByteBuffer - seems to be the fastest)
ByteBuffer bytes = ByteBuffer.allocate (ss.width * ss.height * ss.bpp / 8);
is = new BufferedInputStream(is); // buffering is very important apparently
is.read(bytes.array()); // reading all at once for speed
bytes.position(0); // reset position to the beginning of ByteBuffer
ss.pixels = bytes;
modify:
/*
* BufferedInputStream default providing buff size
*/
private static final int BUF_SIZE = 8192;
ByteBuffer bytes = ByteBuffer.allocate (ss.width * ss.height * ss.bpp / 8);
is = new BufferedInputStream(is);// buffering is very important apparently
bytes.position(0);
while(true) {
final int remain_size = bytes.limit() - bytes.position();
if (remain_size > BUF_SIZE) {
is.read(bytes.array(), bytes.position(), BUF_SIZE);
bytes.position(bytes.position() + BUF_SIZE);
} else {
is.read(bytes.array(), bytes.position(), remain_size);
bytes.position(0);
break;
}
}
ss.pixels = bytes;
the key is, not reading buffer at once. I fix reading whole of data explicitly.
It could be slow but handler would not cause ANR and that is what I
intended(entirely full screen), thanks!
Original comment by asg...@gmail.com
on 18 Mar 2014 at 2:15
Original issue reported on code.google.com by
arne.se...@gmail.com
on 17 Jan 2011 at 1:46