android.view.TextureView.setTransform()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(325)

本文整理了Java中android.view.TextureView.setTransform()方法的一些代码示例,展示了TextureView.setTransform()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextureView.setTransform()方法的具体详情如下:
包路径:android.view.TextureView
类名称:TextureView
方法名:setTransform

TextureView.setTransform介绍

暂无

代码示例

代码示例来源:origin: google/ExoPlayer

  1. /** Applies a texture rotation to a {@link TextureView}. */
  2. private static void applyTextureViewRotation(TextureView textureView, int textureViewRotation) {
  3. float textureViewWidth = textureView.getWidth();
  4. float textureViewHeight = textureView.getHeight();
  5. if (textureViewWidth == 0 || textureViewHeight == 0 || textureViewRotation == 0) {
  6. textureView.setTransform(null);
  7. } else {
  8. Matrix transformMatrix = new Matrix();
  9. float pivotX = textureViewWidth / 2;
  10. float pivotY = textureViewHeight / 2;
  11. transformMatrix.postRotate(textureViewRotation, pivotX, pivotY);
  12. // After rotation, scale the rotated texture to fit the TextureView size.
  13. RectF originalTextureRect = new RectF(0, 0, textureViewWidth, textureViewHeight);
  14. RectF rotatedTextureRect = new RectF();
  15. transformMatrix.mapRect(rotatedTextureRect, originalTextureRect);
  16. transformMatrix.postScale(
  17. textureViewWidth / rotatedTextureRect.width(),
  18. textureViewHeight / rotatedTextureRect.height(),
  19. pivotX,
  20. pivotY);
  21. textureView.setTransform(transformMatrix);
  22. }
  23. }

代码示例来源:origin: vondear/RxTool

  1. matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
  2. mTextureView.setTransform(matrix);

代码示例来源:origin: google/cameraview

  1. matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
  2. mTextureView.setTransform(matrix);

代码示例来源:origin: koral--/android-gif-drawable

  1. break;
  2. super.setTransform(transform);

代码示例来源:origin: journeyapps/zxing-android-embedded

  1. private void startPreviewIfReady() {
  2. if (currentSurfaceSize != null && previewSize != null && surfaceRect != null) {
  3. if (surfaceView != null && currentSurfaceSize.equals(new Size(surfaceRect.width(), surfaceRect.height()))) {
  4. startCameraPreview(new CameraSurface(surfaceView.getHolder()));
  5. } else if(textureView != null && textureView.getSurfaceTexture() != null) {
  6. if(previewSize != null) {
  7. Matrix transform = calculateTextureTransform(new Size(textureView.getWidth(), textureView.getHeight()), previewSize);
  8. textureView.setTransform(transform);
  9. }
  10. startCameraPreview(new CameraSurface(textureView.getSurfaceTexture()));
  11. } else {
  12. // Surface is not the correct size yet
  13. }
  14. }
  15. }

代码示例来源:origin: vbier/habpanelviewer

  1. @Override
  2. public void setDeviceRotation(int deviceRotation) {
  3. if (mCamera != null) {
  4. mActivity.runOnUiThread(() -> mPreviewView.setTransform(new Matrix()));
  5. int result = (mCameraOrientation + deviceRotation * 90) % 360;
  6. result = (360 - result) % 360;
  7. Log.v(TAG, "setting camera display orientation " + result);
  8. mCamera.setDisplayOrientation(result);
  9. mDeviceOrientation = deviceRotation;
  10. }
  11. }

代码示例来源:origin: QuickBlox/ChatMessagesAdapter-android

  1. private void setCorrectRotation() {
  2. int viewWidth = textureView.getWidth();
  3. int viewHeight = textureView.getHeight();
  4. Matrix matrix = new Matrix();
  5. matrix.reset();
  6. int px = viewWidth / 2;
  7. int py = viewHeight / 2;
  8. matrix.postRotate(rotationDegree, px, py);
  9. float ratio = (float) viewHeight / viewWidth;
  10. matrix.postScale(1 / ratio, ratio, px, py);
  11. textureView.setTransform(matrix);
  12. }

代码示例来源:origin: Manuiq/ZoomableTextureView

  1. /**
  2. * Applies a texture rotation to a {@link TextureView}.
  3. */
  4. private static void applyTextureViewRotation(TextureView textureView, int textureViewRotation) {
  5. float textureViewWidth = textureView.getWidth();
  6. float textureViewHeight = textureView.getHeight();
  7. if (textureViewWidth == 0 || textureViewHeight == 0 || textureViewRotation == 0) {
  8. textureView.setTransform(null);
  9. } else {
  10. Matrix transformMatrix = new Matrix();
  11. float pivotX = textureViewWidth / 2;
  12. float pivotY = textureViewHeight / 2;
  13. transformMatrix.postRotate(textureViewRotation, pivotX, pivotY);
  14. // After rotation, scale the rotated texture to fit the TextureView size.
  15. RectF originalTextureRect = new RectF(0, 0, textureViewWidth, textureViewHeight);
  16. RectF rotatedTextureRect = new RectF();
  17. transformMatrix.mapRect(rotatedTextureRect, originalTextureRect);
  18. transformMatrix.postScale(
  19. textureViewWidth / rotatedTextureRect.width(),
  20. textureViewHeight / rotatedTextureRect.height(),
  21. pivotX,
  22. pivotY);
  23. textureView.setTransform(transformMatrix);
  24. }
  25. }

代码示例来源:origin: stackoverflow.com

  1. TextureView textureView = (TextureView) findViewById( R.id.texture );
  2. Matrix m = new Matrix();
  3. // Do matrix creation here.
  4. textureView.setTransform( m );
  5. // When you need to get the Bitmap
  6. Bitmap bitmap = textureView.getBitmap();
  7. bitmap = Bitmap.createBitmap( bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), textureView.getTransform( null ), true );

代码示例来源:origin: square1-io/rich-text-android

  1. public static void adjustAspectRatio(TextureView textureView, int videoWidth, int videoHeight) {
  2. int viewWidth = textureView.getWidth();
  3. int viewHeight = textureView.getHeight();
  4. double aspectRatio = (double) videoHeight / videoWidth;
  5. int newWidth, newHeight;
  6. if (viewHeight > (int) (viewWidth * aspectRatio)) {
  7. // limited by narrow width; restrict height
  8. newWidth = viewWidth;
  9. newHeight = (int) (viewWidth * aspectRatio);
  10. } else {
  11. // limited by short height; restrict width
  12. newWidth = (int) (viewHeight / aspectRatio);
  13. newHeight = viewHeight;
  14. }
  15. int xoff = (viewWidth - newWidth) / 2;
  16. int yoff = (viewHeight - newHeight) / 2;
  17. Matrix txform = new Matrix();
  18. textureView.getTransform(txform);
  19. txform.setScale((float) newWidth / viewWidth, (float) newHeight / viewHeight);
  20. txform.postTranslate(xoff, yoff);
  21. textureView.setTransform(txform);
  22. }

代码示例来源:origin: vbier/habpanelviewer

  1. private void configureTransform(Point previewSize, int rotation) {
  2. if (null == mPreviewView || null == mActivity) {
  3. return;
  4. }
  5. Matrix matrix = new Matrix();
  6. RectF viewRect = new RectF(0, 0, mPreviewView.getWidth(), mPreviewView.getHeight());
  7. RectF bufferRect = new RectF(0, 0, previewSize.y, previewSize.x);
  8. float centerX = viewRect.centerX();
  9. float centerY = viewRect.centerY();
  10. if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
  11. bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
  12. matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
  13. float scale = Math.max(
  14. (float) mPreviewView.getHeight() / previewSize.y,
  15. (float) mPreviewView.getWidth() / previewSize.x);
  16. matrix.postScale(scale, scale, centerX, centerY);
  17. }
  18. matrix.postRotate(-90 * rotation, centerX, centerY);
  19. mPreviewView.setTransform(matrix);
  20. }

代码示例来源:origin: fanbaoying/FBYIDCardRecognition-Android

  1. private void configureTransform(int viewWidth, int viewHeight) {
  2. if (null == textureView || null == previewSize || null == context) {
  3. return;
  4. }
  5. int rotation = orientation;
  6. Matrix matrix = new Matrix();
  7. RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
  8. RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
  9. float centerX = viewRect.centerX();
  10. float centerY = viewRect.centerY();
  11. if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
  12. bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
  13. matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
  14. float scale = Math.max(
  15. (float) viewHeight / previewSize.getHeight(),
  16. (float) viewWidth / previewSize.getWidth());
  17. matrix.postScale(scale, scale, centerX, centerY);
  18. matrix.postRotate(90 * (rotation - 2), centerX, centerY);
  19. } else if (Surface.ROTATION_180 == rotation) {
  20. matrix.postRotate(180, centerX, centerY);
  21. }
  22. textureView.setTransform(matrix);
  23. }

代码示例来源:origin: yixia/VitamioBundleStudio

  1. /**
  2. * Sets the TextureView transform to preserve the aspect ratio of the video.
  3. */
  4. private void adjustAspectRatio(int videoWidth, int videoHeight) {
  5. int viewWidth = mTextureView.getWidth();
  6. int viewHeight = mTextureView.getHeight();
  7. double aspectRatio = (double) videoHeight / videoWidth;
  8. int newWidth, newHeight;
  9. if (viewHeight > (int) (viewWidth * aspectRatio)) {
  10. // limited by narrow width; restrict height
  11. newWidth = viewWidth;
  12. newHeight = (int) (viewWidth * aspectRatio);
  13. } else {
  14. // limited by short height; restrict width
  15. newWidth = (int) (viewHeight / aspectRatio);
  16. newHeight = viewHeight;
  17. }
  18. int xoff = (viewWidth - newWidth) / 2;
  19. int yoff = (viewHeight - newHeight) / 2;
  20. Log.v(TAG, "video=" + videoWidth + "x" + videoHeight + " view=" + viewWidth + "x" + viewHeight
  21. + " newView=" + newWidth + "x" + newHeight + " off=" + xoff + "," + yoff);
  22. Matrix txform = new Matrix();
  23. mTextureView.getTransform(txform);
  24. txform.setScale((float) newWidth / viewWidth, (float) newHeight / viewHeight);
  25. //txform.postRotate(10); // just for fun
  26. txform.postTranslate(xoff, yoff);
  27. mTextureView.setTransform(txform);
  28. }

代码示例来源:origin: chengzichen/KrGallery

  1. textureView.setTransform(txform);

代码示例来源:origin: org.boofcv/boofcv-android

  1. matrix.postRotate(90 * (rotation - 2), centerX, centerY);
  2. mTextureView.setTransform(matrix);

代码示例来源:origin: mengzhidaren/RecyclerViewVideoDemo

  1. textureView.setTransform(txform);

代码示例来源:origin: googlecreativelab/shadercam

  1. mTextureView.setTransform(matrix);

代码示例来源:origin: RameshBhupathi/ImagePicker-OLX

  1. matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
  2. mTextureView.setTransform(matrix);

代码示例来源:origin: Tastenkunst/brfv4_android_examples

  1. RectF surfaceRect = new RectF(0, 0, width, height);
  2. mMatrix.setRectToRect(surfaceRect, viewRect, Matrix.ScaleToFit.CENTER);
  3. mTextureView.setTransform(mMatrix);

代码示例来源:origin: stackoverflow.com

  1. mTextureView.setTransform(transform);
  2. Log.i("onSurfaceTextureAvailable", "Transform: " + transform.toString());

相关文章