2015-01-24 1 views
1

카메라가 작동 중일 때 사용자가 화면 내에서 가로 목록을 통해 모든 필터를 선택할 수 있도록했습니다.GPUImageToneCurveFilter는 여러 카메라 캡처 후 검은 색 이미지를 반환합니다.

private void initializeVariables() { 
    mGPUImage = new GPUImage(this); 

    mGPUImage.setGLSurfaceView(glSurfaceView); 

    mCameraLoader = new CameraLoader(this, mGPUImage); 

    GPUImageFilterTools.showFilters(this, new GPUImageFilterTools.OnGpuImageFilterChosenListener() { 
     @Override 
     public void onGpuImageFilterChosenListener(GPUImageFilter filter) { 
      if (mFilter == null || (filter != null)) { 
       mFilter = filter; 
       mGPUImage.setFilter(mFilter); 
      } 
     } 
    }, hsv_camera_filters); 
} 

이 내 초기 설정입니다 hsv_camera_filters 표시 할 수있는 선택을 할 수 있습니다 org.lucasr.twowayview.TwoWayView의 인스턴스입니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#34393c" 
    android:orientation="vertical"> 

    <android.opengl.GLSurfaceView 
     android:id="@+id/camera" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="20dp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:weightSum="100"> 

     <RelativeLayout 
      android:id="@+id/camera_top_height" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="46" 
      android:background="#34393c" 
      android:gravity="center"> 

     </RelativeLayout> 

     <LinearLayout 
      android:id="@+id/camera_preview_size" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="22" 
      android:orientation="vertical"></LinearLayout> 

     <LinearLayout 
      android:id="@+id/camera_bot_height" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="bottom" 
      android:layout_weight="32" 
      android:background="#34393c" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:weightSum="100"> 

      <org.lucasr.twowayview.TwoWayView xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:id="@+id/hsv_gallery_filters" 
       style="@style/TwoWayView" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_weight="45" 
       android:drawSelectorOnTop="true" 
       tools:context=".ActivityCamera" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_weight="55" 
       android:gravity="center"> 

       <Button 
        android:id="@+id/camera_img_capture" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:onClick="onCapture" 
        android:text="capture"/> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 

</RelativeLayout> 

내가 이렇게 내 카메라 캡처를 시작 :

@OnClick(R.id.camera_img_capture) 
public void onCapture() { 
    mCameraLoader.getCamera().autoFocus(new Camera.AutoFocusCallback() { 
     @Override 
     public void onAutoFocus(boolean success, Camera camera) { 
      takePicture(); 
     } 
    }); 
} 

은 사용자가 필터

private static GPUImageFilter createFilterForType(final Context context, final FilterType type) { 
    GPUImageToneCurveFilter toneCurveFilter = null; 
    switch (type) { 
    case NONE: 
     return new GPUImageFilter(); 
    case CONTRAST: 
     return new GPUImageContrastFilter(1.5f); 
    case CROSSPROCESS: 
     toneCurveFilter = new GPUImageToneCurveFilter(); 
     toneCurveFilter.setFromCurveFileInputStream(context.getResources().openRawResource(
       R.raw.crossprocess)); 
     return toneCurveFilter; 
    case TWO: 
     toneCurveFilter = new GPUImageToneCurveFilter(); 
     toneCurveFilter.setFromCurveFileInputStream(context.getResources().openRawResource(
       R.raw.two)); 
     return toneCurveFilter; 
    default: 
     throw new IllegalStateException("No filter of that type!"); 
    } 
} 

이에 대한 XML을 선택할 때 내가 곡선 파일을 호출하는 방법입니다

private void takePicture() { 
    Camera.Parameters paramss = mCameraLoader.getCamera().getParameters(); 
    List<Camera.Size> pictureSizes = paramss.getSupportedPictureSizes(); 

    /** 
    * Note : do not allow flash mode when using front-camera. Flash mode is 
    * off by default..Change default to auto 
    */ 
    if (mCameraLoader.getCameraId() == 0) { 
     switch (flashMode) { 
      case 1:// 0 = no flash, 1 = auto flash, 2 = flash on 
       paramss.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); 
       break; 
      case 2: 
       paramss.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH); 
       break; 
      default: 
       paramss.setFlashMode(Camera.Parameters.FLASH_MODE_OFF); 
       break; 
     } 
    } 

    for (int i = 0; i < pictureSizes.size(); i++) { 
     if ((pictureSizes.get(i).height <= DEF_HEIGHT) 
       && (pictureSizes.get(i).width <= DEF_WIDTH)) { 
      mCameraSize = pictureSizes.get(i); 
      paramss.setPictureSize(mCameraSize.width, mCameraSize.height); 
      paramss.setPreviewSize(mCameraSize.width, mCameraSize.height); 
      break; 
     } 
    } 

    mCameraLoader.getCamera().setParameters(paramss); 
    mCameraLoader.getCamera().takePicture(null, null, new Camera.PictureCallback() { 

     @Override 
     public void onPictureTaken(byte[] data, final Camera camera) { 
      mCameraLoader.onPause(); 

      final File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE); 
      if (pictureFile == null) { 
       Log.d(TAG, "Error creating media file, check storage permissions"); 
       return; 
      } 

      Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); 

      /** 
      * Note : detects camera angle and rearranges bytes to a desired 
      * angle 
      */ 
      Matrix matrix = new Matrix(); 
      if (mCameraLoader.getCameraId() == 0) { 
       if (mOrientationRounded == 2) { 
        matrix.postRotate(90); 
       } else if (mOrientationRounded == 4) { 
        matrix.postRotate(-90); 
       } 
      } else { 
       if (mOrientationRounded == 2) { 
        matrix.postRotate(-90); 
       } else if (mOrientationRounded == 4) { 
        matrix.postRotate(90); 
       } 
      } 

      // Saves the image to the phone 
      saveImage(mGPUImage.getBitmapWithFilterApplied(bitmap)); 
     } 
    }); 
} 

그래서 1 : 4, 1 : 3 또는 1 : 2 이미지 캡처를 수행 한 후에는 1:10 또는 1:12 이미지 캡처의 비율로 문제가 발생하지만 문제가 발생합니다. 어떻게 든 패턴과 비슷하지만, 정확하지는 않습니다. 나는 단지 하나의 곡선 파일로이 실험을 시도했다.

어떻게 작동합니까? 이것은 도서관의 오산입니까? 아니면 그냥 변수 조작 오류입니까? 또는 아마도 설치?

답변

0

검은 색 이미지에도 문제가 발생했습니다. 내 코드 :

GPUImage gpuImage = new GPUImage(context); 
gpuImage.setImage(sourceBitmap); 
gpuImage.setFilter(filter); 
Bitmap bitmap = gpuImage.getBitmapWithFilterApplied(); 

내 경우 동기화 방법이 코드를 넣어 문제를 해결했다. getBitmapWithFilterApplied은 스레드로부터 안전하지 않거나 라이브러리에 경쟁 조건이있는 것 같습니다.

+0

감사합니다. 시험해보고 테스트 해 보겠습니다. – lombee

관련 문제