我已经建立了一个基本上由HorizontalScrollView内部完成的表ScrollView.我让用户可以编辑字段.
现在我想将表保存在屏幕上,jpg,png,pdf或其他任何内容.
问题是 - 表几乎总是比屏幕大.
有没有办法制作整个ScrollView布局的屏幕截图?如果不是你认为可以做什么工作?
我试图通过代码获取我的游戏截图并通过意图分享.我可以做这些事情,但屏幕截图总是显示为黑色.以下是与共享屏幕截图相关的代码:
View view = MainActivity.getView();
view.setDrawingCacheEnabled(true);
Bitmap screen = Bitmap.createBitmap(view.getDrawingCache(true));
.. save Bitmap
Run Code Online (Sandbox Code Playgroud)
这是在MainActivity中:
view = new GameView(this);
view.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT));
public static SurfaceView getView() {
return view;
}
Run Code Online (Sandbox Code Playgroud)
而观点本身:
public class GameView extends SurfaceView implements SurfaceHolder.Callback {
private static SurfaceHolder surfaceHolder;
...etc
Run Code Online (Sandbox Code Playgroud)
这就是我绘制一切的方式:
Canvas canvas = surfaceHolder.lockCanvas(null);
if (canvas != null) {
Game.draw(canvas);
...
Run Code Online (Sandbox Code Playgroud)
好的,根据一些答案,我构建了这个:
public static void share() {
Bitmap screen = GameView.SavePixels(0, 0, Screen.width, Screen.height);
Calendar c = Calendar.getInstance();
Date d = c.getTime();
String path = …Run Code Online (Sandbox Code Playgroud) 我想以编程方式拍摄我的游戏的屏幕截图,就像你进入Eclipse DDMS一样.
通过此处提出的解决方案截取屏幕截图:如何以编程方式在Android中截取屏幕截图?在大多数其他SO问题中,只有View元素可见,但SurfaceView不是.
SCREENSHOTS_LOCATIONS = Environment.getExternalStorageDirectory().toString() + "/screenshots/";
// Get root view
View view = activity.getWindow().getDecorView().getRootView();
// Create the bitmap to use to draw the screenshot
final Bitmap bitmap = Bitmap.createBitmap(screenWidth, screenHeight, Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
// Get current theme to know which background to use
final Theme theme = activity.getTheme();
final TypedArray ta = theme
.obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
final int res = ta.getResourceId(0, 0);
final Drawable background = activity.getResources().getDrawable(res);
// Draw background …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我希望能够捕获屏幕截图
这是我的代码:
public class Screenshot {
private final View view;
/** Create snapshots based on the view and its children. */
public Screenshot(View root) {
this.view = root;
}
/** Create snapshot handler that captures the root of the whole activity. */
public Screenshot(Activity activity) {
final View contentView = activity.findViewById(android.R.id.content);
this.view = contentView.getRootView();
}
/** Take a snapshot of the view. */
public Bitmap snap() {
Bitmap bitmap = Bitmap.createBitmap(this.view.getWidth(), this.view.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现一种功能,包括录制视频时拍摄照片.这就是我结束使用SurfaceView的截图方法的原因.
但是,当我尝试使用SurfaceView的屏幕截图时.我总是得到一张空白图片.
这是我用于拍摄快照的代码:
View tempView = (View)MY_SURFACE_VIEW;
tempView.setDrawingCacheEnabled(true);
Bitmap tempBmp = Bitmap.createBitmap(tempView.getDrawingCache());
tempView.setDrawingCacheEnabled(false);
//Saving this Bitmap to a File....
Run Code Online (Sandbox Code Playgroud)
如果您认为这是一个重复的问题,请允许我向您保证,在询问此问题之前,我已经尝试过针对相同问题在SO上提供的以下解决方案.
互联网上的其他资源:
1.http ://www.coderanch.com/t/622613/Android/Mobile/capture-screenshot-simple-animation-project
2. http://www.phonesdevelopers.com/1795894/
到目前为止,这对我来说都没有.我也知道我们需要创建一些与Surface Holder交互并从中获取位图的Thread.但我不知道如何实现这一点.
任何帮助都得到高度赞赏.
我正在Android应用程序中使用H264视频渲染SurfaceView.它有一个功能,可以在表面视图上渲染视频时拍摄快照.每当我拍摄快照时,我只会获得透明/黑屏.我使用getDrawingCache()方法来捕获仅返回空值的屏幕.我使用下面的代码来捕获屏幕.
SurfaceView mSUrfaceView = new SurfaceView(this); //Member variable
if(mSUrfaceView!=null)
mSUrfaceView.setDrawingCacheEnabled(true); // After video render on surfaceview i enable the drawing cache
Bitmap bm = mSUrfaceView.getDrawingCache(); // return null
Run Code Online (Sandbox Code Playgroud) 我正在尝试截取增强现实屏幕的屏幕截图并将其作为位图传递给另一个活动。
这是我用来截取屏幕截图的代码:
截图功能
public static void tmpScreenshot(Bitmap bmp, Context context){
try {
//Write file
String filename = "bitmap.png";
FileOutputStream stream = context.openFileOutput(filename, Context.MODE_PRIVATE);
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
//Cleanup
stream.close();
bmp.recycle();
//Pop intent
Intent in1 = new Intent(context, CostActivity.class);
in1.putExtra("image", filename);
context.startActivity(in1);
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
接收截图功能
private void loadTmpBitmap() {
Bitmap bmp = null;
String filename = getIntent().getStringExtra("image");
try {
FileInputStream is = this.openFileInput(filename);
bmp = BitmapFactory.decodeStream(is);
ImageView imageView = findViewById(R.id.test);
imageView.setImageBitmap(Bitmap.createScaledBitmap(bmp, 120, 120, false));
is.close();
} …Run Code Online (Sandbox Code Playgroud)