surfaceview

Surface view as a bitmap in android

廉价感情. 提交于 2019-12-07 11:00:53
问题 I'm using cocos2d. Now I've added some images in the layer, and played around a bit. I'm trying to save the whole screen as image file. How can I do this? 回答1: It is my understanding that cocos2d-android also has a CCRenderTexture class with the saveBuffer method. In that case have a look at my CCRenderTexture demo program and blog post for cocos2d-iphone which gives you an example for how to create a screenshot using CCRenderTexture and saveBuffer. The same principle should be applicable to

Low FPS with android SurfaceView

与世无争的帅哥 提交于 2019-12-07 09:28:33
问题 I have some trubles with my framerate using a SurfaceView. Im doing the tipical stuff i found in some tutorials (all of them said the same), but i cant reach a decent framerate on my samsung galaxy S (the old one, i9000). Here's the code i have for the loop thread. FPS is initialized at 30. @Override public void run() { long ticksPS = 1000/FPS; long startTime; long sleepTime; //fps checker long contms=0; long lasttimecheck = System.currentTimeMillis(); int fps=0; while (running) { long time =

Is it possible to manually destroy SurfaceView?

帅比萌擦擦* 提交于 2019-12-07 09:18:03
问题 My SurfaceView is not getting destroyed even if onPause of the activity is called. I am taking care of the thread in public void surfaceCreated(SurfaceHolder holder) { if (mGameThread.getState() == Thread.State.TERMINATED) { createGameThread(getHolder(), getContext()); } mGameThread.setRunning(true); mGameThread.start(); } public void surfaceDestroyed(SurfaceHolder holder) { boolean retry = true; mGameThread.setRunning(false); while (retry) { try { mGameThread.join(); retry = false; } catch

End SurfaceView and GameThread on exiting app

独自空忆成欢 提交于 2019-12-07 06:33:20
问题 I've got a surfaceview and a gameThread class. The gameThread keeps updating and painting on the SurfaceView class. Now when I exit the app (By pressing the home or back button) I get a message that the app force closed. That's because the GameThread still tries to draw on the erased surfaceview... So how do i properly end the app without getting this force close notification? I would like the GameThread class to stop when the back button is pressed. It should pause when pressing on home and

Android: Regaining focus using SurfaceView

北战南征 提交于 2019-12-07 05:02:21
问题 I'm currently getting to grips with Android, playing around with the Lunar Lander sample. I've found that if you navigate away from the app (eg, hit the call button) it will destroy the underlying surface (calling surfaceDestroyed ). Navigating back (which will trigger onWindowVisibilityChanged ) the app will crash, as it will try to draw to the surface without recreating it. Is there some code I can put in onWindowVisibilityChanged (or anywhere else) that will regenerate the SurfaceView's

getWidth() and getHeight return zero after onMeasure() (specific devices)

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 03:07:44
问题 I noticed that my application's view returns 0 for getWidth() and getHeight() after onMeasure() has already been called. This only happens on a handful of devices, for most android devices the following code works fine. My checkViewAndLoad() function loads a scaled bitmap depending on the size of the view. @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); Log.d("widthMeasureSpec", Integer.toString

Restarting/Pausing Thread in onResume/onPause

我怕爱的太早我们不能终老 提交于 2019-12-07 01:15:44
问题 I'm have a game that's uses SurfaceView implementation to display the objects. I have a thread which draws the SurfaceView time-to-time to the screen. The game is running completely. Unfortunately, it needed to have a pause function whenever the game is interrupted. Well, I know that I need to manipulate onResume and onPause . But I can't get it right. The error points me back to surfaceCreated where I start the thread telling me that the thread has started already. I tried using the resume

How to place UI widgets on top of multiple Z ordered Surface Views in Android

本小妞迷上赌 提交于 2019-12-06 17:06:58
I have 2 SurfaceViews and 1 button and they need to be arranged in a way similar to the attached screenshot. I was able to get SurfaceView B to be on top of SurfaceView A by calling surfaceViewB.setZOrderOnTop(true); The problem is that, once I do that, SurfaceView B is placed above the actual Window and I'm no longer able to get the Button to be on top of it (eg. calling button.bringToFront() is useless here). Any idea how this layout could be accomplished? You can use setZOrderMediaOverlay(boolean) to place SurfaceView B over SurfaceView A, but still behind the window. From documentation:

Two layers, but can't show the bottom layer in android

强颜欢笑 提交于 2019-12-06 16:49:20
I am working on an Android project similar to a scratch card. I have two layers in RelativeLayout. Bottom layer contains an ImageView, and top layer contains a SurfaceView. The problem is the display stays black and doesn't show the ImageView even if I set canvas.drawColor(Color.TRANSPARENT) . What should I do if I want to scratch and erase the part of SurfaceView and reveal the ImageView below? Thanks in advance. And I am sorry for the bad English. Here's my layout: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android

Change background color to a limited area of a view - Android

ぃ、小莉子 提交于 2019-12-06 15:09:29
问题 I am trying to develop a BarcodeReader using Google play services, and i would like to get a camera surface background like Zxing sample. Actually I view with a black transparent background and a white Rect Canvas, and i would like this Rect to be transparent, so my question is if can change the view background without this Rect bounds. This is my Custom View where i draw some lines public class MyView extends View { private Paint paint; private Path path; private int width, height; Canvas