I just checked this approach out as a user had emailed me asking about 
screenshot capability.  This definitely does the trick, but a another poster 
pointed out, any output from certain components (in my case the camera 
preview surfaceview) does not show up.
Perhaps the correct approach then is to capture the output of the surface 
views as bitmaps, and then draw on top of them, it's not quite an "instant" 
screenshot, but will probably serve the purpose?  I'll experiment with this 
and if I have good results will post back.

Mark Murphy, you said this is impossible, did you mean in the sense of the 
way DDMS grabs the full-monty screenshot?

I do hope that Android Handset/Tablet manufacturers catch on and implement 
hardware screen capturing options, a la iOS -- I don't believe screenshots 
are programmatically possible there either, for the same reasons, but the 
user can capture one at any time with a combination of hardware buttons.  It 
will prevent us from having to come up with adhoc solutions like this, and 
allow the screenshot process to be user driven, and thus alleviating 
security concerns.  I believe I read that either Samsung or Motorola may do 
this in future handsets?



On Friday, June 3, 2011 8:30:10 AM UTC-4, New Developer wrote:
>
> Well after much trial and error I managed to capture the entire  layout  or 
> activity
> using the following code
>
> View   myView = findViewById(R.id.form);
> Bitmap bmp    = Bitmap.createBitmap( myView.getMeasuredWidth() , 
> myView.getMeasuredHeight() , Config.ARGB_8888);
> Canvas canvas = new Canvas(bmp);
> myView.draw(canvas);
> try {
>    FileOutputStream out = new FileOutputStream( "/sdcard/screen.jpg"  );
>    bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
>    out.flush();
>    out.close();
> } catch (Exception e) {
>    e.printStackTrace();
> }
>
> Not sure if this will help or not ?  NOTE: that you can also save as a PNG 
> if you want .
>
>
>
>
>
> On Jun 3, 2011, at 8:11 AM, Bharathi raja wrote:
>
> Hi,
> Thanks for sharing code.
>
> Code u shared will capture the entire screen, even if it is not widget 
> component.
> [mean screen may have android or flash or web component]
> i wanted to capture all the three.
>
> Regards,
> Bharathiraja R
>
> On Fri, Jun 3, 2011 at 1:39 AM, New Developer <[email protected]> wrote:
>
>> Okay I output my bitmap to file  as PNG and it only shows the  visible
>> portion of the layout
>> What is currently seen on the screen  not the entire layout.
>> So would I change the  onClick Code to capture the entire layout ?
>>
>> thanks in advance
>>
>>
>> On Jun 2, 3:35 pm, New Developer <[email protected]> wrote:
>> > I'm trying to do something similar
>> >
>> > Inside my button's OnClick I have
>> >
>> > View    myView  = arg0.getRootView();
>> > myView.setDrawingCacheEnabled( true );
>> > mPDF.addImage( myView.getDrawingCache() );
>> >
>> > I'm hoping this will capture the screen to a bitmap
>> >
>> > my PDF.addImage   is as follows:
>> >
>> >         public void addImage(Bitmap bmp) {
>> >                 ByteArrayOutputStream bos = new ByteArrayOutputStream();
>> >                 bmp.compress(CompressFormat.JPEG, 100 , bos);
>> >
>> >                 mImage += "5 0 obj \n" +
>> >                                  "<< /Type /XObject\n" +
>> >                                  "  /Subtype /Image\n" +
>> >                                  "  /Width  " + bmp.getWidth()  + " \n" 
>> +
>> >                                  "  /Height " + bmp.getHeight() + " \n" 
>> +
>> >                                  "  /ColorSpace  /DeviceRGB\n" +
>> >                                  "  /BitsPerComponent 8\n" +
>> >                                  "  /Length " + bos.size()  + "\n" +
>> >                                  "  /Filter  /ASCIIHexDecode\n" +
>> >                                  ">>\n\n" +
>> >                                  "stream\n";
>> >
>> >                 mImage += bos.toString() + "\n";
>> >
>> >                 mImage += "endstream\n" +
>> >                                  "endobj\n\n";
>> >         }
>> >
>> > 1) Is the onClick the correct way to capture the screen to bitmap ?
>> > 2) Is the PDF code the correct way to store an image inside a PDF ?
>> >
>> > thanks in advance
>> >
>> > On Jun 2, 3:11 pm, Paul Turchenko <[email protected]> wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > Your process will need permission to do that. ADB has it by default,
>> > > but regular apps don't. Unless you're rooted, you can't do that.
>> >
>> > > On Jun 2, 4:27 am, Bharathiraja R <[email protected]>
>> > > wrote:
>> >
>> > > > Hi All,
>> >
>> > > > Want sample code to capture screenshot of current screen from phone,
>> > > > same like ddms (screen capture).
>> > > > Please help me out.
>> >
>> > > > Regards,
>> > > > Bharathiraja R
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>>
>
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to