Git Product home page Git Product logo

Comments (13)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
same problem on Nexus S

Original comment by g.jjoe64 on 29 Jun 2011 at 2:50

Attachments:

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
Similar issue I faces on HTC G2, Nexus S, Samsung Vibrant +. Any solution pls.

Original comment by [email protected] on 29 Jul 2011 at 7:18

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
[deleted comment]

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
[deleted comment]

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
could you please tell me the fix?

Original comment by g.jjoe64 on 28 Nov 2011 at 7:08

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
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 [email protected] on 8 Dec 2011 at 1:56

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
It's work, thanks a lot.

Original comment by [email protected] on 9 Dec 2011 at 3:45

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
Thanks a lot!!

Original comment by [email protected] on 15 Jul 2012 at 10:03

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
thanks it works

Original comment by [email protected] on 4 Sep 2012 at 12:11

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
What is the correct PORT? and What is the Screenshot object?

Original comment by [email protected] on 21 Jan 2013 at 11:29

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
    /*
     * 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 [email protected] on 22 Jan 2013 at 3:34

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
what is < and > in ur code

Original comment by [email protected] on 28 Feb 2013 at 4:39

from android-screenshot-library.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 21, 2024
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 [email protected] on 18 Mar 2014 at 2:15

from android-screenshot-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.