Skip to content

Commit dc1829e

Browse files
authored
Merge pull request #94 from ChillingVan/dev
v1.5.2 add rotate sample code
2 parents 9e54146 + 927664c commit dc1829e

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

canvasglsample/src/main/java/com/chillingvan/canvasglsample/textureView/CameraPreviewTextureView.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
public class CameraPreviewTextureView extends GLSurfaceTextureProducerView {
4040

4141
private TextureFilter textureFilter = new BasicTextureFilter();
42+
private int mRotation = 0;
4243

4344
public CameraPreviewTextureView(Context context) {
4445
super(context);
@@ -64,9 +65,19 @@ public void setTextureFilter(TextureFilter textureFilter) {
6465
@Override
6566
protected void onGLDraw(ICanvasGL canvas, GLTexture producedGLTexture, @Nullable GLTexture outsideGLTexture) {
6667
super.onGLDraw(canvas, producedGLTexture, outsideGLTexture);
68+
canvas.save();
6769
RawTexture producedRawTexture = producedGLTexture.getRawTexture();
6870
SurfaceTexture producedSurfaceTexture = producedGLTexture.getSurfaceTexture();
71+
// note the rotate center point.
72+
canvas.rotate(mRotation, getWidth() / 2f, getHeight() / 2f);
6973
canvas.drawSurfaceTexture(producedRawTexture, producedSurfaceTexture, 0, 0, producedRawTexture.getWidth(), producedRawTexture.getHeight(), textureFilter);
74+
canvas.restore();
7075
}
71-
}
7276

77+
public void rotateSurface(int rotation) {
78+
mRotation += rotation;
79+
if (mRotation >= 360) {
80+
mRotation = 0;
81+
}
82+
}
83+
}

canvasglsample/src/main/java/com/chillingvan/canvasglsample/textureView/TextureCameraActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ private void openCamera() {
142142
}
143143

144144
Camera.Parameters parms = mCamera.getParameters();
145+
mCamera.setDisplayOrientation(270);
145146

146147
CameraUtils.choosePreviewSize(parms, 1280, 720);
147148
}
@@ -189,4 +190,12 @@ public void onClickChangeLayoutSize(View view) {
189190
previewConsumerTextureView.setLayoutParams(consumerLayoutParams);
190191
}
191192
}
193+
194+
public void onClickRotateTextureView(View view) {
195+
cameraTextureView.setRotation(cameraTextureView.getRotation() + 90);
196+
}
197+
198+
public void onClickRotateSurface(View view) {
199+
cameraTextureView.rotateSurface(90);
200+
}
192201
}

canvasglsample/src/main/res/layout/activity_texture_canvas.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@
8484
android:onClick="onClickChangeLayoutSize"
8585
/>
8686

87+
<Button
88+
android:layout_width="match_parent"
89+
android:layout_height="40dp"
90+
android:layout_margin="5dp"
91+
android:text="Rotate TextureView"
92+
android:onClick="onClickRotateTextureView"
93+
/>
94+
95+
<Button
96+
android:layout_width="match_parent"
97+
android:layout_height="40dp"
98+
android:layout_margin="5dp"
99+
android:text="Rotate Surface"
100+
android:onClick="onClickRotateSurface"
101+
/>
87102

88103
</LinearLayout>
89104

0 commit comments

Comments
 (0)