내가 얻으려고하는 효과를 얻을 수없는 이유는 GLSurfaceView가 항상 전경 뷰의 투명도를 높이는 다른 뷰 뒤에 있기 때문입니다. 따라서 GLSurfaceView는 그려지는 것보다 우선 순위를 갖습니다. 필자가 원하는 효과를 얻으려면 스 와이프 할 때 보이지 않는 부분에 대해 View.setVisibility()를 사용하고 ViewPager가 안정된 후에 다시 보이도록 설정해야합니다. 그것이 제가 다른 연구의 부산물로서 몇 가지 다른 링크를 본 후에 발견 한 현재의 결론입니다.
z-order for GLSurfaceViews
scrolling in GLSurfaceViews
GLSurfaceView 클래스는 정말 원래 기대했던 같은 뷰와 유사한 수행 그것은 비록 보이지 않는다
. 따라서 ViewPager에서 ImageView가 이미지간에 가시적 인 전환을 유지하려면 더 많은 작업을 진행하기 위해 조금 더주의를 기울여야합니다.
viewPager 내에서 다음 코드 행을 따라 뭔가를 달성했습니다. 테스트의 중간 단계 였기 때문에 이것은 여전히 거친 상태이지만, 찾고있는 것을 성취합니다. 우리가 이미지에 정착하기 시작할 때 텍스처가로드되기 시작한 다음 사용자가 이미지를 떠나기 시작하면 텍스처가 그 아래에있는 원래 이미지를 드러내지 않게됩니다. 그리고 이것은 찢어 지거나 깜박 거리지 않고 작동하는 것처럼 보입니다. 나는 그것이 행동하기를 기대할 것입니다.
@Override
public void onPageScrollStateChanged(int state)
{
switch(state)
{
case ViewPager.SCROLL_STATE_DRAGGING:
Log.i("photoViewer:","dragging ViewPager");
if(photoSurfaceView_ != null && photoViewFrameLayout != null)
{
photoSurfaceView_.setAlpha(0);
photoSurfaceView_.invalidate();
}
break;
case ViewPager.SCROLL_STATE_IDLE:
photoSurfaceView_.setVisibility(View.VISIBLE);
photoSurfaceView_.setAlpha(1);
Log.i("photoViewer:","idle ViewPager");
break;
case ViewPager.SCROLL_STATE_SETTLING:
int childCount = photoViewFrameLayout.getChildCount();
if(childCount >= 2)
{
photoViewFrameLayout.removeViews(1, childCount-1);
}
new Thread(new Runnable() {
@Override
public void run()
{
Looper.prepare();
final Bitmap openGlBitmap = BitmapFactoryUtils.resizeAsNecessaryForOpenGLtexture(photoPaths[photoViewPager_.getCurrentItem()], new BitmapFactory.Options());
Rect bounds = BitmapFactoryUtils.calculateBoundsForBitmap(activityContext, openGlBitmap);
int scaledHeight = bounds.height();
int scaledWidth = bounds.width();
photoSurfaceView_ = new PhotoViewSurfaceView(activityContext, openGlBitmap);
photoSurfaceView_.setLayoutParams(new LayoutParams(scaledWidth, scaledHeight, Gravity.CENTER));
photoSurfaceView_.setVisibility(View.VISIBLE);
photoSurfaceView_.setAlpha(0);
runOnUiThread(new Runnable() {
@Override
public void run()
{
photoViewFrameLayout.addView(photoSurfaceView_);
}
});
}
}).start();
Log.i("photoViewer:","settling ViewPager");
break;
}
편집 : I 입력에 대한 Bitmap
를 사용 OpenGL을 SurfaceView
의 텍스처의 크기를 조정하는 방법에 관한 몇 가지 추가 입력을 제공하고 싶었 요청으로.
다음은 현재 비트 맵의 텍스처 크기가 단일 텍스처에 들어 맞는지 여부를 확인하는 과정의 첫 번째 단계에서 사용할 수있는 코드 중 일부입니다. 이미지를 더 크게 유지하기 위해 텍스처를 바둑판 식으로 배열하려면이 작업이 더욱 복잡해지고 이것이 내 해상도에 필요한 것이 아닙니다.
텍스처 크기는 다음 코드로 검색 할 수 있습니다 :
private void assignTextureSize()
{
/* The maximum texture size can be found within the OpenGL context and then shared amongst other applications. */
int[] maxTextureSize = new int[1];
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
maxTextureSize = maxTextureSize[0];
}
하지만 단지 Renderer
클래스 내에서 내가 할당을 수행 할 텍스처의 onDrawFrame 내 때까지 기다렸다 내 경우에 대한; 비트 맵이 할당되기 전에.
그러면 나를 위해로드되는 Bitmap
의 목표는 단순히 메모리가 부족한 상태에서 수행 할 수있는 작업을로드하는 것이 었습니다. 이를 위해 비트 맵 Options
을 수정하여 try catch 블록 내에서로드하려고 시도했습니다. 메모리가 부족하면 다시 시도하지만 크기는 작습니다.
try
{
final int sizeFactors[] = { 1, 2, 4, 8, 16, 32 };
if (new File(bitmapFilePath).exists())
{
BitmapFactory.Options options = new BitmapFactory.Options();
for (int i = 0; i < sizeFactors.length; ++i)
{
try
{
options.inSampleSize = sizeFactors[i];
Bitmap bmp = BitmapFactory.decodeFile(bitmapFilePath, options);
if(bmp.getHeight() > maximumTextureSize ||
bmp.getWidth() > maximumTextureSize)
{
continue;
}
/*
* @category Check against EXIF data if the image needs to be rotated or not for viewing.
*/
Matrix matrix = new Matrix();
ExifInterface exif = new ExifInterface(bitmapFilePath);
int orientation = exif.getAttributeInt (ExifInterface.TAG_ORIENTATION, 1);
switch(orientation)
{
case ExifInterface.ORIENTATION_NORMAL:
break;
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.postRotate (90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.postRotate (180);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.postRotate (270);
break;
default:
}
bmp = Bitmap.createBitmap (bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
return bmp;
} catch (OutOfMemoryError outOfMemory)
{
//Do nothing, it will return when one that doesn't run out of memory is loaded. Or you could do additional checking to bail if needed, etc.
}
}
throw new Exception("Not enough memory for loading image");
}
} catch (Exception exception)
{
Log.e("CustomLogTag", "Exception for loading the image that was selected for extraction.");
}
이 작업을 수행하는 방법에는 여러 가지가 있지만이 걸릴 수있는 한 가지 방법 내가 요청대로로 내 허용 대답에 많은 정보를 포함하지 않았기 때문에이 이전 게시물에 명확성과 정보를 추가하고 싶었 나도 좋아할거야.
문제를 해결 했습니까? 나는 같은 문제가 있지만 그것을 고칠 수 없다 ... –
@alexlodoss 내가 제공 한 위의 코드는 결국 나를 위해 일했다. 나는 SurfaceView 뒤에있는'ImageView'에서 저해상도 사진을 찍었습니다. 그래서,'ViewPager'가 상호 작용할 때, 저해상도'Bitmap'이 보여지고 그것이 정착 할 때'SurfaceView'를 가시성으로 되돌립니다. –
BitmapFactoryUtils 클래스가 생겼을 때 알려주시겠습니까? 나는 처음에 그것을 눈치 채지 못했습니다 ... –