surfaceview

surfaceview

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 15:06:43
SurfaceView 的优点 使用双缓冲技术 自带画布,支持在子线程中更新画布内容 View 和 SurfaceView 各自使用场景 界面需要被动更新:使用View 。 画面更新是依赖于onTouch 来完成的,所以可以直接使用 invalidate() 函数。这种情况下,两次onTouch()间隔时间较长,不会产生影响 界面需要主动更新:使用SurfaceView。如一个动画需要一直移动或变化,这时需要一个单独的线程不停绘制人的状态,避免阻塞主线程。 界面需要频繁刷新,或刷新时数据处理量较大:使用SurfaceView。如视频播放、camera SurfaceView继承于View,因此SurfaceView 可使用View中的所有方法,但::由于View中所有方法在主线程完成,当SurfaceView重写View的方法,那么也在主线程中完成。 总结: 原本能通过派生自View实现的控件,依然可以通过SurfaceView 实现,因为SurfaceView派生自View 当SurfaceView需要使用View的onDraw()来重绘控件时,需要在初始化的时候调用setWillNotDraw(false)【surfaceview默认为true,也就是不推荐这样】,否则onDraw()函数不会被调用 View中的所有方法都在主线程中执行

subclassing SurfaceView and overriding onDraw() to change SurfaceView parameters to generate preview of desired size

蹲街弑〆低调 提交于 2019-12-04 14:35:14
I have subclassed the SurfaceView and instantiating it in onCreate of the Activity. The preview is generated but the control never enters onDraw() which is overriden in the subclass of SurfaceView. Why is that? class ActivityClass extends Activity{ onCreate(){ mPreview = new Preview(this); setContentView(mPreview); } public void startPreview(){ rec = new MediaRecorder(); rec.setVideoSource();....... rec.setPreviewDisplay(mPreview.getSurfaceHolder.getSurface()); } } class Preview extends SurfaceView implements SurfaceHolder.Callback{ SurfaceHolder mHolder; public Preview(Context context){ super

Relationship between Surface and Canvas: Android

为君一笑 提交于 2019-12-04 14:32:56
问题 What exactly is the relationship between a Surface and Canvas. Please explain. 回答1: A surface is a buffer. A Canvas holds the drawing. Views are not attached to the Canvas nor the Surface. The window is tied to a Surface and the ViewRoot asks the Surface for a Canvas that is then used by the Views to draw onto. For a detailled anwser, you can read this whole discussion, really interesting. 来源: https://stackoverflow.com/questions/3370212/relationship-between-surface-and-canvas-android

using zxing barcode reader through surfaceview

旧巷老猫 提交于 2019-12-04 12:46:18
I am creating a Barcode Scanner app and I want to use Zxing to read barcodes, my app has a surfaceview and showing camera into that, but now I want to scan barcode from my SurfaceView camera , the reason that I use it, is that I have two Edittexts under the surface view in my layout to show content of barcode. How should I create an app like, the main problem is that how can I set zxing into surface. If there's any way I would appreciate. Layout screenshot: Customize your zxing layout with below codes. I took here a RelativeLayout for zxing Scanner. Or, Go with this references : https://github

Options to efficiently draw a stream of byte arrays to display in Android

天大地大妈咪最大 提交于 2019-12-04 10:51:29
In simple words, all I need to do is display a live stream of video frames in Android (each frame is YUV420 format). I have a callback function where I receieve individual frames as a byte array. Something that looks like this : public void onFrameReceived(byte[] frame, int height, int width, int format) { // display this frame to surfaceview/textureview. } A feasible but slow option is to convert the byte array to a Bitmap and draw to canvas on SurfaceView. In the future, I would ideally like to be able to alter brightness, contrast etc of this frame, and hence am hoping I can use OpenGL-ES

Reopening camera after intent chooser is canceled

一世执手 提交于 2019-12-04 09:35:07
I have created a custom camera preview view CameraView which extends SurfaceView , and it also implements SurfaceHolder.Callback interface. The view operates with the camera. When you open the view it shows a camera preview. On the same screen there is also overlay with two buttons - 'Take picture', 'Choose from gallery'. The activity that holds the CameraView releases and reopens the camera in onPause() and onResume() methods. If I click the 'Choose from gallery' button, the following intent is created: Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*");

Weird performance issue with Galaxy Tab

梦想的初衷 提交于 2019-12-04 09:17:59
问题 I am working on a 2d tutorial and was able to test my current tutorial part on a Samsung Galaxy Tab. The tutorial simply moves the default icon randomly over the screen. With a tap I create a new moving icon. Everything works fine (constantly 60fps) on the Galaxy as long as I have 25 elements or less on the screen. With the 26th element the frame rate drops to 25fps. When I change the size/dimension of the image to a much bigger one, I reach less than 25fps before the 26th element. Thats ok.

SurfaceView with camera preview is not destroyed

六月ゝ 毕业季﹏ 提交于 2019-12-04 09:00:30
I have a Tab Activity with 2 tabs (activities). Each tab has a 3d Open GL scene drawn on top of a SurfaceView with camera preview. Yet, depending on device orientation, tabs are being switched. The problem is that when the other activity starts, it calls camera.open(), which generates exception, saying that camera service is unavailable. In fact, the problem is that camera is not stopped when activity is paused, in other words onSurfaceDestroyed() is not called for the SurfaceView. I tried to stop camera when onPause() for activities is called, but get the same error still. Anyone had same

Android SurfaceView Preview Blurry

两盒软妹~` 提交于 2019-12-04 05:58:40
I have a quick question. I'm using Android's SurfaceView to take a picture and save it. However, the preview size and the picture quality itself is both terrible; as in, it is very blurry. There's no sharpness to the picture quality at all. Here's where I initialize my surfaceView: camera.setDisplayOrientation(90); Parameters parameters = camera.getParameters(); parameters.setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO); parameters.setExposureCompensation(0); parameters.setPictureFormat(ImageFormat.JPEG); parameters.setJpegQuality(100); Camera.Size picSize = getOptimalPreviewSize

Using camera inside an app using surfaceview in android

三世轮回 提交于 2019-12-04 05:16:41
问题 I am creating an app where i can use the camera inside it without going to the default app of the phone.So i have used a surface view and tried to save it onto the phone, but the onPictureTaken never gets called.The complete code is shown below: package com.example.surfaceviewcamera; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.hardware.Camera; import android.os.Bundle;