How to capture screen with coding

Put your problem here if it does not fit any of the other categories.

Re: How to capture screen with coding

Postby Taiko3615 » Mon Jun 21, 2010 10:54 am

I have tried your code samples, I can get a screenshot, but only of the background.

I am running android 1.5
here is my code (nothing more needed to see my example, just paste in your main)
Code: Select all
package test.test;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Test extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
       //Generation of the ViewGroup
       Button button = new Button(this);
       button.setText("salut");      
       LinearLayout layout1 = new LinearLayout(this);
       LinearLayout layout2 = new LinearLayout(this);
       LinearLayout layout3 = new LinearLayout(this);
       layout1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      layout1.setOrientation(LinearLayout.VERTICAL);
      layout1.setBackgroundColor(Color.YELLOW);
      layout1.addView(button); 
      layout2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      layout2.setOrientation(LinearLayout.VERTICAL);
      layout2.setBackgroundColor(Color.RED);
      layout3.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
      layout3.setOrientation(LinearLayout.VERTICAL);
      layout3.setBackgroundColor(Color.CYAN);
      layout3.addView(layout1);
      layout3.addView(layout2);
      //we'll call it cardview
      ViewGroup cardview = layout3;
      

      
      //We build a bitmap called originalImage
           cardview.layout(0, 0, 150, 183);
          cardview.setDrawingCacheEnabled(true);
           cardview.buildDrawingCache();
             setContentView(cardview);
Bitmap originalImage = cardview.getDrawingCache();

       
        //Then we try to display it
             ImageView imview = new ImageView(this);
             imview.setImageBitmap(originalImage);
             // only the backgroung is displayed
            setContentView(imview);
         //If we display it normally, it works
             //setContentView(cardview);
    }
}
Taiko3615
Freshman
Freshman
 
Posts: 3
Joined: Fri Jun 18, 2010 4:41 pm

Top

Re: How to capture screen with coding

Postby Taiko3615 » Mon Jun 21, 2010 1:07 pm

I have exactly the same problem if I render the screenshot by brawing a canvas, then a bitmap. What did I do wrong?
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package test.test;
  2.  
  3. import android.app.Activity;
  4. import android.graphics.Bitmap;
  5. import android.graphics.Canvas;
  6. import android.graphics.Color;
  7. import android.graphics.Matrix;
  8. import android.graphics.Paint;
  9. import android.os.Bundle;
  10. import android.view.ViewGroup;
  11. import android.view.ViewGroup.LayoutParams;
  12. import android.widget.Button;
  13. import android.widget.ImageView;
  14. import android.widget.LinearLayout;
  15.  
  16. public class Test extends Activity {
  17.     /** Called when the activity is first created. */
  18.     @Override
  19.     public void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         setContentView(R.layout.main);
  22.        
  23.             //Generation of the ViewGroup
  24.             Button button = new Button(this);
  25.             button.setText("salut");       
  26.             LinearLayout layout1 = new LinearLayout(this);
  27.             LinearLayout layout2 = new LinearLayout(this);
  28.             LinearLayout layout3 = new LinearLayout(this);
  29.             layout1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  30.            layout1.setOrientation(LinearLayout.VERTICAL);
  31.            layout1.setBackgroundColor(Color.YELLOW);
  32.            layout1.addView(button);  
  33.            layout2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
  34.            layout2.setOrientation(LinearLayout.VERTICAL);
  35.            layout2.setBackgroundColor(Color.RED);
  36.            layout3.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
  37.            layout3.setOrientation(LinearLayout.VERTICAL);
  38.            layout3.setBackgroundColor(Color.CYAN);
  39.            layout3.addView(layout1);
  40.            layout3.addView(layout2);
  41.            //we'll call it cardview
  42.            ViewGroup cardview = layout3;
  43.            
  44.  
  45.            
  46.          //test generation of the bitmap  
  47.        Bitmap originalImage = Bitmap.createBitmap(150, 183, Bitmap.Config.ARGB_4444);
  48.    Paint paint = new Paint();
  49.    cardview.layout(0, 0, 100, 100);
  50.        Canvas canvas = new Canvas(originalImage);
  51.        cardview.draw(canvas);
  52.   canvas.drawBitmap(originalImage, new Matrix(), paint);
  53.         //end test generation of the bitmap
  54.  
  55.        
  56.         //Then we try to display it
  57.              ImageView imview = new ImageView(this);
  58.              imview.setImageBitmap(originalImage);
  59.              // only the backgroung is displayed
  60.            setContentView(imview);
  61.          //If we display it normally, it works
  62.              //setContentView(cardview);
  63.     }
  64. }
Parsed in 0.042 seconds, using GeSHi 1.0.8.4
Taiko3615
Freshman
Freshman
 
Posts: 3
Joined: Fri Jun 18, 2010 4:41 pm

Re: How to capture screen with coding

Postby Taiko3615 » Fri Jun 25, 2010 3:43 pm

This code works:

CardView cardView = Your View ;
cardView.measure(150, 183);
cardView.layout(0, 0, 150, 183);
cardView.setDrawingCacheEnabled(true);
Bitmap originalImage= cardView.getDrawingCache();

In fact, the measure and layout are needed.
Taiko3615
Freshman
Freshman
 
Posts: 3
Joined: Fri Jun 18, 2010 4:41 pm

Re: How to capture screen with coding

Postby sridharbandi » Fri Jul 02, 2010 7:38 pm

hi guys...
can u mail me the full souce code for screen capturing...am in need of it please help me...
thanks in advance.. My id: bpandub4u@yahoo.co.in
sridharbandi
Freshman
Freshman
 
Posts: 4
Joined: Fri Jul 02, 2010 12:31 pm

Re: How to capture screen with coding

Postby muthu4_u » Wed Oct 06, 2010 6:56 pm

Hi,

Can you upload the working source code? So that it will be useful for all...

Thanks in Advance,
Muthu Kumar K.
muthu4_u
Freshman
Freshman
 
Posts: 3
Joined: Wed Oct 06, 2010 6:53 pm

Re: How to capture screen with coding

Postby oijkn » Tue May 31, 2011 8:08 pm

Hi i'm new in android dev and i'm interested by this source code for a better learn :) if some can upload the full project for an import in eclipse that will be fine :D

thanks in advance for the share !
oijkn
Once Poster
Once Poster
 
Posts: 1
Joined: Tue May 31, 2011 7:23 pm

Top

Re: How to capture screen with coding

Postby mol » Wed Jul 27, 2011 8:32 am

as for me, i prefer to capture screen using this prog http://www.geovid.com/Screen_VidShot/
mol
Freshman
Freshman
 
Posts: 4
Joined: Tue Jul 05, 2011 7:14 am

Re: How to capture screen with coding

Postby dharmin007 » Wed Aug 10, 2011 6:13 am

Hey thank you soo much for the complete code. It works like a charm.
dharmin007
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Aug 10, 2011 6:12 am

Re: How to capture screen with coding

Postby ArchanaBasavaraj » Thu Apr 19, 2012 2:46 pm

Could you plz post the complete working code of screen shot
ArchanaBasavaraj
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 19, 2012 11:10 am

Re: How to capture screen with coding

Postby ArchanaBasavaraj » Thu Apr 19, 2012 2:48 pm

Please help me guys. Its too urgent. Please guys. Thanks in advance.
ArchanaBasavaraj
Freshman
Freshman
 
Posts: 2
Joined: Thu Apr 19, 2012 11:10 am

Top
Previous

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 15 guests