surfaceview

Switch To Front Camera and Back Camera Android SurfaceView

隐身守侯 提交于 2019-12-05 10:05:31
I want to use the switch camera function. Currently I have Developed a Camera Object That working fine for back-camera but not working for front-camera. And I am unable to find a solution for switching between front and back cameras. Here is My Code..! public class MyCamera extends Activity implements SurfaceHolder.Callback, Camera.ShutterCallback, Camera.PictureCallback { Camera mCamera; SurfaceView mPreview; String filePath; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.camera_preview); mPreview = (SurfaceView)

Android: Regaining focus using SurfaceView

[亡魂溺海] 提交于 2019-12-05 09:53:12
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 underlying surface and resume execution nicely? It feels like this should be a simple function call but I

Override onDraw() or draw()?

孤者浪人 提交于 2019-12-05 09:47:10
问题 My project is based on surfaceView and up until now I've had all of my rendering in onDraw which I am overriding. All seemed to be OK. However, I've just updated my SDK and now it gives me an error telling me: Suspicious method call; should probably call "draw" rather than "onDraw" Could someone please explain the difference between these two? I've read some similar questions around the net but I've not found an explanation that I understand. Thanks 回答1: SurfaceView.draw() basically calls

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

大兔子大兔子 提交于 2019-12-05 08:08:06
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(MeasureSpec.getSize(widthMeasureSpec))); Log.d("heightMeasureSpec", Integer.toString(MeasureSpec.getSize

android camera2 process each frame and display its preview

最后都变了- 提交于 2019-12-05 07:59:41
I use the https://github.com/googlesamples/android-Camera2Basic , but try to modify it in a way that I could get access to each frame before it is drawn on the surfaceview. I understood, I should add additional surface (ImageReader.getSurface()), and read the frame from it in this callback: private final ImageReader.OnImageAvailableListener mOnImageAvailableListener = new ImageReader.OnImageAvailableListener() { @Override public void onImageAvailable(ImageReader reader) { Log.d("Img", "onImageAvailable"); mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile)); } }; The

Restarting/Pausing Thread in onResume/onPause

断了今生、忘了曾经 提交于 2019-12-05 04:53:07
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 and suspend on the onResume and onPause respectively but nothing changed. How can I achieve this? I have

Android SurfaceView slows if no touch events occur

£可爱£侵袭症+ 提交于 2019-12-05 02:11:27
问题 I am making a game and all is going well except for the game loop. I am using a SurfaceView and drawing 2D Sprites (Bitmaps). Currently the game is a ship moving through an asteroid field. The ship stays in the center of the screen and the phone is tilted in either direction to move the the asteroids (asteroids change location instead of player). New asteroids spawn as old ones fall off the screen creating an infinite asteroid field feeling. Running on my Nexus 5, I noticed that after about 3

Android Camera - app passed NULL surface

会有一股神秘感。 提交于 2019-12-05 00:33:10
Whenever I run the cam_thread I get the error "app passed NULL surface". This code supposedly works on the HTC Incredible 1. I've reconfigured it slightly to run on a droid x. However I still get this error. public class Android_Activity extends Activity { Main_thread simulator; ToggleButton togglebutton; EditText ip_text; SensorManager sm = null; SurfaceView view; Sensors_thread the_sensors=null; String IP_address; Android_Activity the_app; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); view = new SurfaceView

Android canvas fill background color (Canvas application)

旧时模样 提交于 2019-12-04 23:04:36
问题 By having the following codes, I have some questions. public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( new View(this) { Paint mPaint = new Paint(); @Override protected void onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); int width = this.getWidth(); int height = this.getHeight(); int radius = width > height ? height/2 : width/2; int center_x = width/2;

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

拥有回忆 提交于 2019-12-04 22:13:27
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 canvas; private Rect rectangle; public MyView(Context context) { super(context); init(); } public MyView