当前位置: 首页>>代码示例>>Java>>正文


Java YuvImage.compressToJpeg方法代码示例

本文整理汇总了Java中android.graphics.YuvImage.compressToJpeg方法的典型用法代码示例。如果您正苦于以下问题:Java YuvImage.compressToJpeg方法的具体用法?Java YuvImage.compressToJpeg怎么用?Java YuvImage.compressToJpeg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.YuvImage的用法示例。


在下文中一共展示了YuvImage.compressToJpeg方法的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: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: saveImageToPath

import android.graphics.YuvImage; //导入方法依赖的package包/类
public String saveImageToPath(byte[] data, Camera.Parameters parameters, String desPath) {
    Camera.Size size = parameters.getPreviewSize();
    String filePath = Environment.getExternalStorageDirectory().getPath() + desPath;
    try {
        data = rotateYUV90(data, size.width, size.height);
        int rotatedHeight = size.width;
        int rotatedWidth = size.height;
        YuvImage image = new YuvImage(data, parameters.getPreviewFormat(),
                rotatedWidth, rotatedHeight, null);
        File file = new File(filePath);
        if (!file.exists()) {
            FileOutputStream fos = new FileOutputStream(file);
            image.compressToJpeg(new Rect(0, 0, image.getWidth(), image.getHeight()), 90, fos);
        }

    } catch (FileNotFoundException e) {

    }
    return filePath;
}
 
开发者ID:Oh233,项目名称:Ancaffe,代码行数:21,代码来源:Util.java

示例12: 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)
    throws IOException
{
  byte[] rotated = rotateNV21(data, width, height, rotation);
  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:SilenceIM,项目名称:Silence,代码行数:20,代码来源:BitmapUtil.java

示例13: onPreviewFrame

import android.graphics.YuvImage; //导入方法依赖的package包/类
@Override
public void onPreviewFrame(byte[] bytes, Camera camera) {
    if(!isRecording)return;

    ++frame_skipped;
    if(frame_skipped==SKIP_FRAME)frame_skipped=0;
    else return;

    try{
        if(bytes!=null){
            YuvImage img = new YuvImage(bytes,videoFormatIndex,
                    bestSize.width,bestSize.height,null);
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            img.compressToJpeg(new Rect(0,0,bestSize.width,bestSize.height),
                    VIDEO_QUALITY,outputStream);
            //sendImage(outputStream.toByteArray());
            send(outputStream.toByteArray());
        }
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:BrotherJing,项目名称:smartcar,代码行数:23,代码来源:SimpleVideoActivity.java

示例14: getBitmapImageFromYUV

import android.graphics.YuvImage; //导入方法依赖的package包/类
public static Bitmap getBitmapImageFromYUV(byte[] data, int width,
		int height, Rect rect) {
	YuvImage yuvimage = new YuvImage(data, ImageFormat.NV21, width, height,
			null);
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	yuvimage.compressToJpeg(new Rect(0, 0, width, height), 90, baos);

	byte[] jdata = baos.toByteArray();
	BitmapFactory.Options bitmapFatoryOptions = new BitmapFactory.Options();
	bitmapFatoryOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
	Bitmap bmp = BitmapFactory.decodeByteArray(jdata, 0, jdata.length,
			bitmapFatoryOptions);
	
	Log.d(TAG,"getBitmapImageFromYUV w:"+bmp.getWidth()+" h:"+bmp.getHeight());

	
	return bmp;
}
 
开发者ID:mplackowski,项目名称:previewOCR,代码行数:19,代码来源:CameraTool.java

示例15: getBitMap

import android.graphics.YuvImage; //导入方法依赖的package包/类
public Bitmap getBitMap(byte[] data, Camera camera, boolean mIsFrontalCamera) {
	int width = camera.getParameters().getPreviewSize().width;
	int height = camera.getParameters().getPreviewSize().height;
	YuvImage yuvImage = new YuvImage(data, camera.getParameters()
			.getPreviewFormat(), width, height, null);
	ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
	yuvImage.compressToJpeg(new Rect(0, 0, width, height), 80,
			byteArrayOutputStream);
	byte[] jpegData = byteArrayOutputStream.toByteArray();
	// 获取照相后的bitmap
	Bitmap tmpBitmap = BitmapFactory.decodeByteArray(jpegData, 0,
			jpegData.length);
	Matrix matrix = new Matrix();
	matrix.reset();
	if (mIsFrontalCamera) {
		matrix.setRotate(-90);
	} else {
		matrix.setRotate(90);
	}
	tmpBitmap = Bitmap.createBitmap(tmpBitmap, 0, 0, tmpBitmap.getWidth(),
			tmpBitmap.getHeight(), matrix, true);
	tmpBitmap = tmpBitmap.copy(Bitmap.Config.ARGB_8888, true);

	int hight = tmpBitmap.getHeight() > tmpBitmap.getWidth() ? tmpBitmap
			.getHeight() : tmpBitmap.getWidth();

	float scale = hight / 800.0f;

	if (scale > 1) {
		tmpBitmap = Bitmap.createScaledBitmap(tmpBitmap,
				(int) (tmpBitmap.getWidth() / scale),
				(int) (tmpBitmap.getHeight() / scale), false);
	}
	return tmpBitmap;
}
 
开发者ID:FacePlusPlus,项目名称:MegviiFacepp-Android-SDK,代码行数:36,代码来源:ICamera.java


注:本文中的android.graphics.YuvImage.compressToJpeg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。