如何使用此库在Android模拟器上进行截图,并在哪里获取截图

4

我安装了这个库http://code.google.com/p/android-screenshot-library/

我启动了我的Android模拟器,运行run.sh文件后它显示“服务启动成功”。

我该如何获取模拟器的屏幕截图,或者我应该从哪里获取?我使用的是最新版本。谢谢。


@Hitendra 不是,我直接从终端使用adb运行..我想截取手机上正在运行的任何活动的屏幕截图。实际上,我的项目是ScreenCast。 - albert
嘿,阿尔伯特!你得到答案了吗?如果是的话,请指导一下。 - user1517153
3个回答

4

打开Eclipse > 打开DDMS视图 > 从列表中选择您的模拟器 > 在您选择模拟器的位置附近按下闪烁的小相机图标

希望您能找到它。


我想要一段代码,可以启动一个服务,将模拟器(手机)上显示的任何内容发送给PC的帧缓冲区,实际上我的项目是屏幕广播。 - albert

0
import pl.polidea.asl.*;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection; 
import android.content.res.Resources.NotFoundException;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.graphics.*;

public class ScreenshotDemo extends Activity {

/*
 * The ImageView used to display taken screenshots.
 */
private ImageView imgScreen;

private ServiceConnection aslServiceConn = new ServiceConnection() {

    @Override
    public void onServiceDisconnected(ComponentName name) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
        aslProvider = IScreenshotProvider.Stub.asInterface(service);
    }
};
private IScreenshotProvider aslProvider = null;


/** Called when the activity is first created. */
@Override 
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    imgScreen = (ImageView)findViewById(R.id.imgScreen);
    Button btn = (Button)findViewById(R.id.btnTakeScreenshot); 
    btn.setOnClickListener(btnTakeScreenshot_onClick); 

    // connect to ASL service
    //Intent intent = new Intent(ScreenshotService.class.getName());
    Intent intent = new Intent();
    intent.setClass(this, ScreenshotService.class);
    //intent.addCategory(Intent.ACTION_DEFAULT);
    bindService (intent, aslServiceConn, Context.BIND_AUTO_CREATE);
}

@Override
public void onDestroy() {
    unbindService(aslServiceConn);
    super.onDestroy();
}


private View.OnClickListener btnTakeScreenshot_onClick = new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        try {
            if (aslProvider == null)
                Toast.makeText(ScreenshotDemo.this, R.string.n_a, Toast.LENGTH_SHORT).show();
            else if (!aslProvider.isAvailable())
                Toast.makeText(ScreenshotDemo.this, R.string.native_n_a, Toast.LENGTH_SHORT).show();
            else {
                String file = aslProvider.takeScreenshot();
                if (file == null)
                    Toast.makeText(ScreenshotDemo.this, R.string.screenshot_error, Toast.LENGTH_SHORT).show();
                else {
                    Toast.makeText(ScreenshotDemo.this, R.string.screenshot_ok, Toast.LENGTH_SHORT).show();
                    Bitmap screen = BitmapFactory.decodeFile(file);
                    imgScreen.setImageBitmap(screen);

                }
            }
        } catch (NotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (RemoteException e) {
            // squelch
        }

    }
};
}

1). 这段代码会将屏幕上显示的内容发送到电脑吗? 2). 这段代码应该在哪里编译和运行?它需要安装在模拟器中吗?我的项目是屏幕广播。 - albert

0

DDMS具有截取视图截图的功能。

在Eclipse中,打开DDMS透视图并在设备布局中单击屏幕截图图标。


我想要一段代码,可以启动一个服务,将模拟器(手机)上显示的任何内容发送到PC的帧缓冲区中,实际上我的项目是屏幕广播。 - albert

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接