Предварительный просмотр камеры не ПОЛНЫЙ ЭКРАН в AndroidAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Предварительный просмотр камеры не ПОЛНЫЙ ЭКРАН в Android

Сообщение Anonymous »

Я пытаюсь сделать предварительный просмотр камеры, изменить его в onPreviewFrame() и показать пользователю. Я уже добился необходимой функциональности, но проблема в РАЗМЕРЕ ПРЕДВАРИТЕЛЬНОГО ПРОСМОТРА КАМЕРЫ. Он всегда занимает меньшую часть экрана, и я хочу сделать его полноэкранным, т. е. хочу сделать предварительный просмотр камеры, который должен заполнить весь экран устройства. У меня есть прочитал и попробовал все решения, доступные в сети, но ни одно из них не работает в моем случае. Это класс Surface View:

public class MySurfaceView extends SurfaceView implements Callback, Camera.PreviewCallback, android.view.SurfaceHolder.Callback {

private static final String TAG = "MySurfaceView";
private int width;
private int height;
public SurfaceHolder mHolder;
private Camera mCamera;
private int[] rgbints;
private int mMultiplyColor;

public MySurfaceView(Context context, AttributeSet attrs , Camera camera ,
int width , int height)
{
super(context, attrs);

mCamera = camera;

this.width = width;
this.height = height;

mHolder = getHolder();
mHolder.addCallback(this);

mMultiplyColor = getResources().getColor(R.color.honeydew);
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
{
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
synchronized (this) {
this.setWillNotDraw(false); // This allows us to make our own draw calls to this canvas

rgbints = new int[width * height];

// try { mCamera.setPreviewDisplay(holder); } catch (IOException e)
// { Log.e("Camera", "mCamera.setPreviewDisplay(holder);"); }

mCamera.startPreview();
mCamera.setPreviewCallback(this);

}
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
synchronized (this) {
try
{
CameraActivity cameraActivity = new CameraActivity();
cameraActivity.releaseCamera();
cameraActivity = null;
} catch (Exception e) {
Log.e("Camera", e.getMessage());
}
}
}

@Override
public void onPreviewFrame(byte[] data, Camera camera) {
Canvas canvas = null;

if (mHolder == null)
{
return;
}

try {
synchronized (mHolder)
{
canvas = mHolder.lockCanvas(null);

int canvasWidth = canvas.getWidth();
int canvasHeight = canvas.getHeight();

decodeYUV(rgbints, data, width, height);

// draw the decoded image, centered on canvas
canvas.drawBitmap(rgbints, 0, width, canvasWidth-((width+canvasWidth)>>1), canvasHeight-((height+canvasHeight)>>1), width, height, false, null);

// use some color filter
canvas.drawColor(mMultiplyColor, Mode.MULTIPLY);

}
} catch (Exception e){
e.printStackTrace();
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (canvas != null)
{
mHolder.unlockCanvasAndPost(canvas);
canvas = null;
}
}
}

public void decodeYUV(int[] out, byte[] fg, int width, int height) throws NullPointerException, IllegalArgumentException {
int sz = width * height;
if (out == null)
throw new NullPointerException("buffer out is null");
if (out.length < sz)
throw new IllegalArgumentException("buffer out size " + out.length + " < minimum " + sz);
if (fg == null)
throw new NullPointerException("buffer 'fg' is null");
if (fg.length < sz)
throw new IllegalArgumentException("buffer fg size " + fg.length + " < minimum " + sz * 3 / 2);
int i, j;
int Y, Cr = 0, Cb = 0;
for (j = 0; j < height; j++) {
int pixPtr = j * width;
final int jDiv2 = j >> 1;
for (i = 0; i < width; i++) {
Y = fg[pixPtr];
if (Y < 0)
Y += 255;
if ((i & 0x1) != 1) {
final int cOff = sz + jDiv2 * width + (i >> 1) * 2;
Cb = fg[cOff];
if (Cb < 0)
Cb += 127;
else
Cb -= 128;
Cr = fg[cOff + 1];
if (Cr < 0)
Cr += 127;
else
Cr -= 128;
}
int R = Y + Cr + (Cr >> 2) + (Cr >> 3) + (Cr >> 5);
if (R < 0)
R = 0;
else if (R > 255)
R = 255;
int G = Y - (Cb >> 2) + (Cb >> 4) + (Cb >> 5) - (Cr >> 1) + (Cr >> 3) + (Cr >> 4) + (Cr >> 5);
if (G < 0)
G = 0;
else if (G > 255)
G = 255;
int B = Y + Cb + (Cb >> 1) + (Cb >> 2) + (Cb >> 6);
if (B < 0)
B = 0;
else if (B > 255)
B = 255;
out[pixPtr++] = 0xff000000 + (B

Подробнее здесь: https://stackoverflow.com/questions/171 ... in-android
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»