本文整理了Java中android.view.TextureView.setTransform()
方法的一些代码示例,展示了TextureView.setTransform()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextureView.setTransform()
方法的具体详情如下:
包路径:android.view.TextureView
类名称:TextureView
方法名:setTransform
暂无
代码示例来源:origin: google/ExoPlayer
/** Applies a texture rotation to a {@link TextureView}. */
private static void applyTextureViewRotation(TextureView textureView, int textureViewRotation) {
float textureViewWidth = textureView.getWidth();
float textureViewHeight = textureView.getHeight();
if (textureViewWidth == 0 || textureViewHeight == 0 || textureViewRotation == 0) {
textureView.setTransform(null);
} else {
Matrix transformMatrix = new Matrix();
float pivotX = textureViewWidth / 2;
float pivotY = textureViewHeight / 2;
transformMatrix.postRotate(textureViewRotation, pivotX, pivotY);
// After rotation, scale the rotated texture to fit the TextureView size.
RectF originalTextureRect = new RectF(0, 0, textureViewWidth, textureViewHeight);
RectF rotatedTextureRect = new RectF();
transformMatrix.mapRect(rotatedTextureRect, originalTextureRect);
transformMatrix.postScale(
textureViewWidth / rotatedTextureRect.width(),
textureViewHeight / rotatedTextureRect.height(),
pivotX,
pivotY);
textureView.setTransform(transformMatrix);
}
}
代码示例来源:origin: vondear/RxTool
matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
mTextureView.setTransform(matrix);
代码示例来源:origin: google/cameraview
matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
mTextureView.setTransform(matrix);
代码示例来源:origin: koral--/android-gif-drawable
break;
super.setTransform(transform);
代码示例来源:origin: journeyapps/zxing-android-embedded
private void startPreviewIfReady() {
if (currentSurfaceSize != null && previewSize != null && surfaceRect != null) {
if (surfaceView != null && currentSurfaceSize.equals(new Size(surfaceRect.width(), surfaceRect.height()))) {
startCameraPreview(new CameraSurface(surfaceView.getHolder()));
} else if(textureView != null && textureView.getSurfaceTexture() != null) {
if(previewSize != null) {
Matrix transform = calculateTextureTransform(new Size(textureView.getWidth(), textureView.getHeight()), previewSize);
textureView.setTransform(transform);
}
startCameraPreview(new CameraSurface(textureView.getSurfaceTexture()));
} else {
// Surface is not the correct size yet
}
}
}
代码示例来源:origin: vbier/habpanelviewer
@Override
public void setDeviceRotation(int deviceRotation) {
if (mCamera != null) {
mActivity.runOnUiThread(() -> mPreviewView.setTransform(new Matrix()));
int result = (mCameraOrientation + deviceRotation * 90) % 360;
result = (360 - result) % 360;
Log.v(TAG, "setting camera display orientation " + result);
mCamera.setDisplayOrientation(result);
mDeviceOrientation = deviceRotation;
}
}
代码示例来源:origin: QuickBlox/ChatMessagesAdapter-android
private void setCorrectRotation() {
int viewWidth = textureView.getWidth();
int viewHeight = textureView.getHeight();
Matrix matrix = new Matrix();
matrix.reset();
int px = viewWidth / 2;
int py = viewHeight / 2;
matrix.postRotate(rotationDegree, px, py);
float ratio = (float) viewHeight / viewWidth;
matrix.postScale(1 / ratio, ratio, px, py);
textureView.setTransform(matrix);
}
代码示例来源:origin: Manuiq/ZoomableTextureView
/**
* Applies a texture rotation to a {@link TextureView}.
*/
private static void applyTextureViewRotation(TextureView textureView, int textureViewRotation) {
float textureViewWidth = textureView.getWidth();
float textureViewHeight = textureView.getHeight();
if (textureViewWidth == 0 || textureViewHeight == 0 || textureViewRotation == 0) {
textureView.setTransform(null);
} else {
Matrix transformMatrix = new Matrix();
float pivotX = textureViewWidth / 2;
float pivotY = textureViewHeight / 2;
transformMatrix.postRotate(textureViewRotation, pivotX, pivotY);
// After rotation, scale the rotated texture to fit the TextureView size.
RectF originalTextureRect = new RectF(0, 0, textureViewWidth, textureViewHeight);
RectF rotatedTextureRect = new RectF();
transformMatrix.mapRect(rotatedTextureRect, originalTextureRect);
transformMatrix.postScale(
textureViewWidth / rotatedTextureRect.width(),
textureViewHeight / rotatedTextureRect.height(),
pivotX,
pivotY);
textureView.setTransform(transformMatrix);
}
}
代码示例来源:origin: stackoverflow.com
TextureView textureView = (TextureView) findViewById( R.id.texture );
Matrix m = new Matrix();
// Do matrix creation here.
textureView.setTransform( m );
// When you need to get the Bitmap
Bitmap bitmap = textureView.getBitmap();
bitmap = Bitmap.createBitmap( bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), textureView.getTransform( null ), true );
代码示例来源:origin: square1-io/rich-text-android
public static void adjustAspectRatio(TextureView textureView, int videoWidth, int videoHeight) {
int viewWidth = textureView.getWidth();
int viewHeight = textureView.getHeight();
double aspectRatio = (double) videoHeight / videoWidth;
int newWidth, newHeight;
if (viewHeight > (int) (viewWidth * aspectRatio)) {
// limited by narrow width; restrict height
newWidth = viewWidth;
newHeight = (int) (viewWidth * aspectRatio);
} else {
// limited by short height; restrict width
newWidth = (int) (viewHeight / aspectRatio);
newHeight = viewHeight;
}
int xoff = (viewWidth - newWidth) / 2;
int yoff = (viewHeight - newHeight) / 2;
Matrix txform = new Matrix();
textureView.getTransform(txform);
txform.setScale((float) newWidth / viewWidth, (float) newHeight / viewHeight);
txform.postTranslate(xoff, yoff);
textureView.setTransform(txform);
}
代码示例来源:origin: vbier/habpanelviewer
private void configureTransform(Point previewSize, int rotation) {
if (null == mPreviewView || null == mActivity) {
return;
}
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, mPreviewView.getWidth(), mPreviewView.getHeight());
RectF bufferRect = new RectF(0, 0, previewSize.y, previewSize.x);
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
float scale = Math.max(
(float) mPreviewView.getHeight() / previewSize.y,
(float) mPreviewView.getWidth() / previewSize.x);
matrix.postScale(scale, scale, centerX, centerY);
}
matrix.postRotate(-90 * rotation, centerX, centerY);
mPreviewView.setTransform(matrix);
}
代码示例来源:origin: fanbaoying/FBYIDCardRecognition-Android
private void configureTransform(int viewWidth, int viewHeight) {
if (null == textureView || null == previewSize || null == context) {
return;
}
int rotation = orientation;
Matrix matrix = new Matrix();
RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
float centerX = viewRect.centerX();
float centerY = viewRect.centerY();
if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
float scale = Math.max(
(float) viewHeight / previewSize.getHeight(),
(float) viewWidth / previewSize.getWidth());
matrix.postScale(scale, scale, centerX, centerY);
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
} else if (Surface.ROTATION_180 == rotation) {
matrix.postRotate(180, centerX, centerY);
}
textureView.setTransform(matrix);
}
代码示例来源:origin: yixia/VitamioBundleStudio
/**
* Sets the TextureView transform to preserve the aspect ratio of the video.
*/
private void adjustAspectRatio(int videoWidth, int videoHeight) {
int viewWidth = mTextureView.getWidth();
int viewHeight = mTextureView.getHeight();
double aspectRatio = (double) videoHeight / videoWidth;
int newWidth, newHeight;
if (viewHeight > (int) (viewWidth * aspectRatio)) {
// limited by narrow width; restrict height
newWidth = viewWidth;
newHeight = (int) (viewWidth * aspectRatio);
} else {
// limited by short height; restrict width
newWidth = (int) (viewHeight / aspectRatio);
newHeight = viewHeight;
}
int xoff = (viewWidth - newWidth) / 2;
int yoff = (viewHeight - newHeight) / 2;
Log.v(TAG, "video=" + videoWidth + "x" + videoHeight + " view=" + viewWidth + "x" + viewHeight
+ " newView=" + newWidth + "x" + newHeight + " off=" + xoff + "," + yoff);
Matrix txform = new Matrix();
mTextureView.getTransform(txform);
txform.setScale((float) newWidth / viewWidth, (float) newHeight / viewHeight);
//txform.postRotate(10); // just for fun
txform.postTranslate(xoff, yoff);
mTextureView.setTransform(txform);
}
代码示例来源:origin: chengzichen/KrGallery
textureView.setTransform(txform);
代码示例来源:origin: org.boofcv/boofcv-android
matrix.postRotate(90 * (rotation - 2), centerX, centerY);
mTextureView.setTransform(matrix);
代码示例来源:origin: mengzhidaren/RecyclerViewVideoDemo
textureView.setTransform(txform);
代码示例来源:origin: googlecreativelab/shadercam
mTextureView.setTransform(matrix);
代码示例来源:origin: RameshBhupathi/ImagePicker-OLX
matrix.postRotate(180, getWidth() / 2, getHeight() / 2);
mTextureView.setTransform(matrix);
代码示例来源:origin: Tastenkunst/brfv4_android_examples
RectF surfaceRect = new RectF(0, 0, width, height);
mMatrix.setRectToRect(surfaceRect, viewRect, Matrix.ScaleToFit.CENTER);
mTextureView.setTransform(mMatrix);
代码示例来源:origin: stackoverflow.com
mTextureView.setTransform(transform);
Log.i("onSurfaceTextureAvailable", "Transform: " + transform.toString());
内容来源于网络,如有侵权,请联系作者删除!