Tôi đã sửa đổi dự án Grishu demo: here's a Screen Recording, sau đó một số giải thích:
(hình ảnh xoay, với ba tác dụng áp dụng - lật ngang, crossprocess, fisheye)
1) Để áp dụng hiệu ứng trên kết quả, đề xuất của bạn hoạt động tốt. Tôi không thực sự hiểu ý bạn là gì, hiệu ứng thay đổi tiến độ ''. Bạn có muốn điều chỉnh các thông số của hiệu ứng không?
2) Để có cử chỉ, bạn nên mở rộng GLSurfaceView
và triển khai GestureDetector.OnGestureListener
và/hoặc ScaleGestureDetector.OnScaleGestureListener
tùy theo nhu cầu của bạn. Xem TouchGLView đây: Source, hoặc đoạn mã dưới đây:
private class TouchGLView extends GLSurfaceView
implements GestureDetector.OnGestureListener,
ScaleGestureDetector.OnScaleGestureListener {
private TextureRenderer mRenderer;
private GestureDetector mTapDetector;
private ScaleGestureDetector mScaleDetector;
private float mLastSpan = 0;
TouchGLView(Context c) {
super(c);
// Use Android's built-in gesture detectors to detect
// which touch event the user is doing.
mTapDetector = new GestureDetector(c, this);
mTapDetector.setIsLongpressEnabled(false);
mScaleDetector = new ScaleGestureDetector(c, this);
// Create an OpenGL ES 2.0 context.
setEGLContextClientVersion(2);
mRenderer = new TextureRenderer(c);
setRenderer(mRenderer);
}
@Override
public boolean onTouchEvent(final MotionEvent e) {
// Forward touch events to the gesture detectors.
mScaleDetector.onTouchEvent(e);
mTapDetector.onTouchEvent(e);
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
final float dx, final float dy) {
// Forward the drag event to the renderer.
queueEvent(new Runnable() {
public void run() {
mRenderer.drag(dx, dy);
}});
return true;
}
@Override
public boolean onScale(ScaleGestureDetector detector) {
// Forward the scale event to the renderer.
final float amount = detector.getCurrentSpan() - mLastSpan;
queueEvent(new Runnable() {
public void run() {
mRenderer.zoom(amount);
}});
mLastSpan = detector.getCurrentSpan();
return true;
}
...
}
3) Bạn có thể xoay hình ảnh bằng cách sửa đổi đỉnh phối và tham viewports vào tài khoản. Ngoài ra, bạn có thể áp dụng các chuyển đổi khác nhau. Bạn có thể xoay (và thu phóng) chế độ xem (tọa độ đỉnh) chính nó (không ảnh hưởng đến bộ đệm kết cấu ban đầu) hoặc bạn có thể xoay pixel trong bộ đệm kết cấu (dễ dàng cho 90 °, 180 °, v.v ...) cập nhật tọa độ đỉnh của bạn để phù hợp với chiều rộng/chiều cao hình ảnh mới.
Dưới đây là một ví dụ cho các thao tác với coords đỉnh:
private void computeOutputVertices() {
if (mPosVertices != null) {
float imgAspectRatio = mTexWidth/(float)mTexHeight;
float viewAspectRatio = mViewWidth/(float)mViewHeight;
float x0, y0, x1, y1;
// Set initial vertex coords based in texture aspect
if (imgAspectRatio > 1.0f) {
x0 = -1.0f ;
y0 = -1.0f/imgAspectRatio;
x1 = 1.0f ;
y1 = 1.0f/imgAspectRatio;
} else {
x0 = -1.0f *imgAspectRatio;
y0 = -1.0f;
x1 = 1.0f *imgAspectRatio;
y1 = 1.0f;
}
float[] coords = new float[] { x0, y0, x1, y0, x0, y1, x1, y1 };
// Scale coordinates with mZoom
for (int i = 0; i < 8; i++) {
coords[i] *= mZoom;
}
// Rotate coordinates with mRot
float cosa = (float)Math.cos(mRot);
float sina = (float)Math.sin(mRot);
float x,y;
for (int i = 0; i < 8; i+=2) {
x = coords[i]; y = coords[i+1];
coords[i] = cosa*x-sina*y;
coords[i+1] = sina*x+cosa*y;
}
// Finally scale again to match screen aspect
if (viewAspectRatio > 1.0f) {
for (int i = 0; i < 8; i+=2) {
coords[i] = coords[i]/viewAspectRatio;
}
} else {
for (int i = 1; i < 8; i+=2) {
coords[i] = coords[i]*viewAspectRatio;
}
}
mPosVertices.put(coords).position(0);
}
}
tôi đề nghị bạn để đi sâu vào ma trận OpenGL và làm tất cả những biến đổi sử dụng chúng.
Tôi đã sửa đổi TextureRenderer
lớp để triển khai GLSurfaceView.Renderer
và thay đổi renderMode thành RENDERMODE_CONTINUOUSLY
.
Cuối cùng, source for the modified demo is here.
Trước hết, xin cảm ơn câu trả lời 1) có thể áp dụng hiệu ứng vào thay đổi tiến trình của thanh tìm kiếm không? vì nó làm việc lần đầu tiên khi tôi áp dụng hiệu ứng từ "mTextures [0]" thành "mTextures [1]" và rander textureId "mTextures [1]". sau khi áp dụng hiệu ứng lần đầu tiên, nếu áp dụng hiệu ứng thứ hai nói "CONTRAST" trên thay đổi tiến trình của thanh tìm kiếm thì hiệu ứng áp dụng từ "mTextures [1]" thành "mTextures [1]" và render textureId "mTextures [1]". bạn sẽ nhận thấy rằng hình ảnh sẽ bị đen. –
Tôi nghĩ rằng nếu tôi tái sử dụng "mTextures [1]" là kết cấu mới. sẽ giải quyết được vấn đề của tôi, nhưng không biết cách sử dụng lại nó. 2) Pinch để phóng to: hoạt động tốt nhưng có vấn đề với hình ảnh cuộn. bất kỳ ý tưởng? 3) Xoay: hoạt động tốt. là nó có thể áp dụng luân phiên bằng cách sử dụng xây dựng trong hiệu ứng roration tại (90,180,270, ...) theo chiều kim đồng hồ. –
Xoay và thu phóng của người hoạt động tốt nhưng Drag không hoạt động ... cách giải quyết. –