當前位置: 首頁>>代碼示例>>Java>>正文


Java YuvImage類代碼示例

本文整理匯總了Java中android.graphics.YuvImage的典型用法代碼示例。如果您正苦於以下問題:Java YuvImage類的具體用法?Java YuvImage怎麽用?Java YuvImage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


YuvImage類屬於android.graphics包,在下文中一共展示了YuvImage類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: imgToByte

import android.graphics.YuvImage; //導入依賴的package包/類
private byte[] imgToByte(boolean quality) {
    Camera.Parameters parameters = getParameters();
    int width = parameters.getPreviewSize().width;
    int height = parameters.getPreviewSize().height;

    YuvImage yuv = new YuvImage(getImage(), parameters.getPreviewFormat(), width, height, null);
    ByteArrayOutputStream out =
            new ByteArrayOutputStream();
    yuv.compressToJpeg(new Rect(0, 0, width, height), 100, out);

    byte[] compressed = out.toByteArray();

    Bitmap newBmp = BitmapFactory.decodeByteArray(compressed, 0, compressed.length);
    Matrix mat = new Matrix();
    mat.postRotate(PrefsController.instance.getPrefs().getCameraPrefs(cameraId).angle);
    newBmp = Bitmap.createBitmap(newBmp, 0, 0, newBmp.getWidth(), newBmp.getHeight(), mat, true);
    ByteArrayOutputStream out2 = new ByteArrayOutputStream();
    if (quality) {
        newBmp.compress(Bitmap.CompressFormat.PNG, 100, out2);
    } else {
        newBmp.compress(Bitmap.CompressFormat.JPEG, 80, out2);
    }

    return out2.toByteArray();
}
 
開發者ID:Rai220,項目名稱:Telephoto,代碼行數:26,代碼來源:ImageShot.java

示例2: createFromNV21

import android.graphics.YuvImage; //導入依賴的package包/類
public static byte[] createFromNV21(@NonNull final byte[] data,
                                    final int width,
                                    final int height,
                                    int rotation,
                                    final Rect croppingRect,
                                    final boolean flipHorizontal)
    throws IOException
{
  byte[] rotated = rotateNV21(data, width, height, rotation, flipHorizontal);
  final int rotatedWidth  = rotation % 180 > 0 ? height : width;
  final int rotatedHeight = rotation % 180 > 0 ? width  : height;
  YuvImage previewImage = new YuvImage(rotated, ImageFormat.NV21,
                                       rotatedWidth, rotatedHeight, null);

  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  previewImage.compressToJpeg(croppingRect, 80, outputStream);
  byte[] bytes = outputStream.toByteArray();
  outputStream.close();
  return bytes;
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:21,代碼來源:BitmapUtil.java

示例3: getBitmap

import android.graphics.YuvImage; //導入依賴的package包/類
private Bitmap getBitmap(Rect cropRect, int scaleFactor) {
    if(isRotated()) {
        //noinspection SuspiciousNameCombination
        cropRect = new Rect(cropRect.top, cropRect.left, cropRect.bottom, cropRect.right);
    }

    // TODO: there should be a way to do this without JPEG compression / decompression cycle.
    YuvImage img = new YuvImage(data, imageFormat, dataWidth, dataHeight, null);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    img.compressToJpeg(cropRect, 90, buffer);
    byte[] jpegData = buffer.toByteArray();

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = scaleFactor;
    Bitmap bitmap = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length, options);

    // Rotate if required
    if (rotation != 0) {
        Matrix imageMatrix = new Matrix();
        imageMatrix.postRotate(rotation);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), imageMatrix, false);
    }

    return bitmap;
}
 
開發者ID:OpenIchano,項目名稱:Viewer,代碼行數:26,代碼來源:SourceData.java

示例4: convertYuvImageToRgb

import android.graphics.YuvImage; //導入依賴的package包/類
static public Bitmap convertYuvImageToRgb(YuvImage yuvImage, int width, int height, int downSample) {
  Bitmap rgbImage;
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  yuvImage.compressToJpeg(new Rect(0, 0, width, height), 0, out);
  byte[] imageBytes = out.toByteArray();

  BitmapFactory.Options opt;
  opt = new BitmapFactory.Options();
  opt.inSampleSize = downSample;

  // get image and rotate it so (0,0) is in the bottom left
  Bitmap tmpImage;
  Matrix matrix = new Matrix();
  matrix.postRotate(90); // to rotate the camera images so (0,0) is in the bottom left
  tmpImage = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length, opt);
  rgbImage=Bitmap.createBitmap(tmpImage , 0, 0, tmpImage.getWidth(), tmpImage.getHeight(), matrix, true);

  return rgbImage;
}
 
開發者ID:cheer4ftc,項目名稱:OpModeCamera,代碼行數:20,代碼來源:OpModeCamera.java

示例5: saveFace

import android.graphics.YuvImage; //導入依賴的package包/類
private void saveFace(final int x, final int y, final int r, final int b) {
    if (DEBUG) Log.d(TAG, "[saveFace()]");
    new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized (mVideoSource) {
                mImageYuv = new YuvImage(mVideoSource, ImageFormat.NV21, CameraWrapper.IMAGE_WIDTH, CameraWrapper.IMAGE_HEIGHT, null);
            }
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            mImageYuv.compressToJpeg(new Rect(0, 0, CameraWrapper.IMAGE_WIDTH, CameraWrapper.IMAGE_HEIGHT), 100, stream);
            Bitmap bitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());

            int left = (x > 0) ? x : 0;
            int top = (y > 0) ? y : 0;
            int creatW = (r < CameraWrapper.IMAGE_WIDTH) ? (r - x) : (CameraWrapper.IMAGE_HEIGHT - x - 1);
            int creatH = (b < CameraWrapper.IMAGE_WIDTH) ? (b - y) : (CameraWrapper.IMAGE_HEIGHT - y - 1);

            mImage = Bitmap.createBitmap(bitmap, left, top, creatW, creatH, null, false);
            if (DEBUG) Log.d(TAG, "[saveFace()] x:" + x + "  y:" + y + "\n" +
                    "[saveFace()] h:" + mImage.getHeight() + "  w:" + mImage.getWidth());
            if (null != mImage)
                FaceUtil.saveBitmapToFile(mImage);
        }
    }).start();
}
 
開發者ID:Yee-chen,項目名稱:seeta4Android,代碼行數:26,代碼來源:FaceDetector.java

示例6: decodeToBitMap

import android.graphics.YuvImage; //導入依賴的package包/類
private Bitmap decodeToBitMap(byte[] data) {
	try {
		YuvImage image = new YuvImage(data, ImageFormat.NV21, PREVIEW_WIDTH,
				PREVIEW_HEIGHT, null);
		if (image != null) {
			ByteArrayOutputStream stream = new ByteArrayOutputStream();
			image.compressToJpeg(new Rect(0, 0, PREVIEW_WIDTH, PREVIEW_HEIGHT),
					80, stream);
			Bitmap bmp = BitmapFactory.decodeByteArray(
					stream.toByteArray(), 0, stream.size());
			stream.close();
			return bmp ;
		}
	} catch (Exception ex) {
		Log.e("Sys", "Error:" + ex.getMessage());
	}
	return null;
}
 
開發者ID:JosephPai,項目名稱:WithYou,代碼行數:19,代碼來源:VideoVerify.java

示例7: captureBitmapFromYuvFrame

import android.graphics.YuvImage; //導入依賴的package包/類
private Bitmap captureBitmapFromYuvFrame(I420Frame i420Frame) {
    YuvImage yuvImage = i420ToYuvImage(i420Frame.yuvPlanes,
            i420Frame.yuvStrides,
            i420Frame.width,
            i420Frame.height);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    Rect rect = new Rect(0, 0, yuvImage.getWidth(), yuvImage.getHeight());

    // Compress YuvImage to jpeg
    yuvImage.compressToJpeg(rect, 100, stream);

    // Convert jpeg to Bitmap
    byte[] imageBytes = stream.toByteArray();
    Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);
    Matrix matrix = new Matrix();

    // Apply any needed rotation
    matrix.postRotate(i420Frame.rotationDegree);
    bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix,
            true);

    return bitmap;
}
 
開發者ID:twilio,項目名稱:video-quickstart-android,代碼行數:24,代碼來源:SnapshotVideoRenderer.java

示例8: fastI420ToYuvImage

import android.graphics.YuvImage; //導入依賴的package包/類
private YuvImage fastI420ToYuvImage(ByteBuffer[] yuvPlanes,
                                    int[] yuvStrides,
                                    int width,
                                    int height) {
    byte[] bytes = new byte[width * height * 3 / 2];
    int i = 0;
    for (int row = 0 ; row < height ; row++) {
        for (int col = 0 ; col < width ; col++) {
            bytes[i++] = yuvPlanes[0].get(col + row * yuvStrides[0]);
        }
    }
    for (int row = 0 ; row < height / 2 ; row++) {
        for (int col = 0 ; col < width / 2; col++) {
            bytes[i++] = yuvPlanes[2].get(col + row * yuvStrides[2]);
            bytes[i++] = yuvPlanes[1].get(col + row * yuvStrides[1]);
        }
    }
    return new YuvImage(bytes, NV21, width, height, null);
}
 
開發者ID:twilio,項目名稱:video-quickstart-android,代碼行數:20,代碼來源:SnapshotVideoRenderer.java

示例9: yuv2Img

import android.graphics.YuvImage; //導入依賴的package包/類
/**
 * yuv轉換圖像
 * @param frameData
 * @param yuvFormat
 * @param prevWidth
 * @param prevHeight
 * @param quality
 * @return
 */
public static Bitmap yuv2Img(byte[] frameData, int yuvFormat, int prevWidth, int prevHeight,
    int quality) {
  Long start = System.currentTimeMillis();
  Bitmap img = null;
  try {
    YuvImage image = new YuvImage(frameData, yuvFormat, prevWidth, prevHeight, null);
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.RGB_565;
    if (image != null) {
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      image.compressToJpeg(new Rect(0, 0, prevWidth, prevHeight), quality, stream);
      img = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size(), options);
      stream.close();
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return img;
}
 
開發者ID:kong-jing,項目名稱:PreRect,代碼行數:29,代碼來源:ImgUtil.java

示例10: getFramePicture

import android.graphics.YuvImage; //導入依賴的package包/類
public byte[] getFramePicture(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    int format = parameters.getPreviewFormat();

    //YUV formats require conversion
    if (format == ImageFormat.NV21 || format == ImageFormat.YUY2 || format == ImageFormat.NV16) {
        int w = parameters.getPreviewSize().width;
        int h = parameters.getPreviewSize().height;

        // Get the YuV image
        YuvImage yuvImage = new YuvImage(data, format, w, h, null);
        // Convert YuV to Jpeg
        Rect rect = new Rect(0, 0, w, h);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        yuvImage.compressToJpeg(rect, 80, outputStream);
        return outputStream.toByteArray();
    }
    return data;
}
 
開發者ID:erperejildo,項目名稱:cordova-plugin-preview-camera,代碼行數:20,代碼來源:CameraActivity.java

示例11: onPictureTaken

import android.graphics.YuvImage; //導入依賴的package包/類
public void onPictureTaken(byte[] data, Camera camera) {
    //new SaveImageTask().execute(data);
    long b = System.currentTimeMillis()-a;

    Log.d(TAG, "onPictureTaken - jpeg");
    String str = "Data: " + data.length;
    Log.d(TAG, str);
    // Convert to JPG
    Camera.Size previewSize = camera.getParameters().getPreviewSize();
    YuvImage yuvimage=new YuvImage(data, ImageFormat.NV21, previewSize.width, previewSize.height, null);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    yuvimage.compressToJpeg(new Rect(0, 0, previewSize.width, previewSize.height), 100, baos);
    byte[] jdata = baos.toByteArray();

    // Convert to Bitmap
    Bitmap bmp = BitmapFactory.decodeByteArray(jdata, 0, jdata.length);

    str = "BMP: " + bmp.getPixel(35, 84);
    Log.d(TAG, str);


    str = "Time: " + b;
    Log.d(TAG, str);
    resetCam();
}
 
開發者ID:asriram3,項目名稱:VisiSynth,代碼行數:26,代碼來源:MainActivity.java

示例12: onPreviewFrame

import android.graphics.YuvImage; //導入依賴的package包/類
public void onPreviewFrame(byte[] data, Camera camera){
    Log.d("TAG", "frame1 "+data.length);
    Camera.Size previewSize = mCamera.getParameters().getPreviewSize();
    YuvImage yuvimage=new YuvImage(data, ImageFormat.NV21, previewSize.width, previewSize.height, null);

    // Convert to Bitmap
    final double [][] imgmat = imgpro.BufferedYUVImage2Mat(yuvimage.getYuvData(),
            yuvimage.getWidth(), yuvimage.getHeight(), 640, 480);

    List<Double> ld = imgpro.AnalyzeMat(imgmat, 0.6);

    String logline = "points:";
    for(Double p : ld)
        logline += " " + (1-p);
    Log.d("TAG", logline);
    double [] f = new double[ld.size()];
    for(int i = 0; i < f.length; i ++)
        f[i] = Math.pow(2.0, ld.get(i) * 2) * 440.0;
    play(f);
}
 
開發者ID:asriram3,項目名稱:VisiSynth,代碼行數:21,代碼來源:Preview.java

示例13: rawByteArray2RGBABitmap2

import android.graphics.YuvImage; //導入依賴的package包/類
public void rawByteArray2RGBABitmap2(FileOutputStream b)
{
	int yuvi = yuv_w * yuv_h;
	int uvi = 0;
	byte[] yuv = new byte[yuv_w * yuv_h * 3 / 2];
	System.arraycopy(y, 0, yuv, 0, yuvi);
	for (int i = 0; i < yuv_h / 2; i++)
	{
		for (int j = 0; j < yuv_w / 2; j++)
		{
			yuv[yuvi++] = v[uvi];
			yuv[yuvi++] = u[uvi++];
		}
	}
	YuvImage yuvImage = new YuvImage(yuv, ImageFormat.NV21, yuv_w, yuv_h, null);
	Rect rect = new Rect(0, 0, yuv_w, yuv_h);
	yuvImage.compressToJpeg(rect, 100, b);
}
 
開發者ID:OpenIchano,項目名稱:Viewer,代碼行數:19,代碼來源:MyRenderer.java

示例14: onPreviewFrame

import android.graphics.YuvImage; //導入依賴的package包/類
@Override
public void onPreviewFrame(final byte[] data, final Camera camera) {
    if (mInitAck && mDataAck) {
        mInitAck = false;
        mDataAck = false;
        previewMissedCount = 0;
        ThreadHandler.getInstance().doInBackground(new Runnable() {
            @Override
            public void run() {
                Camera.Size size = camera.getParameters().getPreviewSize();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21, size.width, size.height, null);
                yuvImage.compressToJpeg(new Rect(0, 0, size.width, size.height), 50, out);
                byte[] imageBytes = out.toByteArray();
                mBluetoothHandler.write(BluetoothHandler.DATA_START.getBytes());
                mPendingImageBytes = imageBytes;
            }
        });
    } else {
        previewMissedCount++;
        if (previewMissedCount > 50) {
            mInitAck = true;
            mDataAck = true;
        }
    }
}
 
開發者ID:sujithkanna,項目名稱:BluetoothCameraAndroid,代碼行數:27,代碼來源:CameraModelImpl.java

示例15: convertToYuvImageLineByLine

import android.graphics.YuvImage; //導入依賴的package包/類
/**
 * YuvImage converter (line by line).
 * @param width The width of image.
 * @param height The height of image.
 * @param yuvStrides yuvStrides array.
 * @param yuvPlanes yuvPlanes array.
 * @return YuvImage data.
 */
public static YuvImage convertToYuvImageLineByLine(final int width, final int height, final int[] yuvStrides, final ByteBuffer[] yuvPlanes) {
    byte[] bytes = new byte[width * height * 3 / 2];
    byte[] yuvPlanes0 = yuvPlanes[0].array();
    byte[] yuvPlanes1 = yuvPlanes[1].array();
    byte[] yuvPlanes2 = yuvPlanes[2].array();

    int i = 0;
    for (int row = 0; row < height; row++) {
        for (int col = 0; col < width; col++) {
            bytes[i++] = yuvPlanes0[col + row * yuvStrides[0]];
        }
    }
    for (int row = 0; row < height / 2; row++) {
        for (int col = 0; col < width / 2; col++) {
            bytes[i++] = yuvPlanes2[col + row * yuvStrides[2]];
            bytes[i++] = yuvPlanes1[col + row * yuvStrides[1]];
        }
    }
    return new YuvImage(bytes, ImageFormat.NV21, width, height, null);
}
 
開發者ID:DeviceConnect,項目名稱:DeviceConnect-Android,代碼行數:29,代碼來源:YuvConverter.java


注:本文中的android.graphics.YuvImage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。