【问题标题】:Cwac Camera add thumnail imageCwac 相机添加缩略图
【发布时间】:2014-03-05 09:37:08
【问题描述】:

我想使用 cwac 库在相机视图上显示缩略图。

cameraFragment.takePicture();

            Bitmap bitmap = Utility.decodeSampledBitmapFromPath(
                    cameraFragment.cameraHost.getPhotoPath()
                            .getAbsolutePath(), 120, 120);
            image.setImageBitmap(bitmap);

【问题讨论】:

  • 我想像默认相机应用一样显示拍摄照片的缩略图。我该怎么做:))
  • 请注意,这与 CWAC-Camera 库没有太大关系,因为您可能希望从任何地方“显示缩略图”,并且代码不会有明显不同。除了在图片准备好之前尝试阅读图片之外,您的代码有什么具体问题?

标签: android camera commonsware-cwac


【解决方案1】:

我在使用 Cwac 时遇到了同样的问题,我的工作太先进了,无法切换到另一个库,所以我的解决方案就在这里。

修改您的 CameraFragment.onCreate 方法以将您的 DemoCameraHost 设置为默认主机:

public class CameraFragment extends com.commonsware.cwac.camera.CameraFragment {
private DemoCameraHost mDemoCamHost;

@Override
public void onCreate(Bundle state) {
    super.onCreate(state);
    setHasOptionsMenu(true);
    mDemoCamHost = new DemoCameraHost(getActivity());
    this.setHost(mDemoCamHost);
}

在 DemoCameraHost 方法中 useSingleShotMode 必须返回false

/**
* Method indicates if after taking picture bitmap is frozen or next frame shown.
*
* @return Enable showing preview, must be false for this project.
*/
@Override
public boolean useSingleShotMode() {
    return false;
}

现在您必须在 DemoCameraHost 中重写 saveImage 方法,在该方法中您接收到编码为字节数组的图像,只需将其解码回来:

@Override
public void saveImage(PictureTransaction xact, byte[] image) {
    Log.i(TAG, "saveImage");
    Bitmap bm = BitmapFactory.decodeByteArray(image, 0, image.length);
    //drawOnTop.setBitmap(bm); // this is my internal class that operates on the bitmap
    if (bm == null)
        Log.e(TAG, "bitmap is null");
    else
        Log.e(TAG, "bitmap size: " + bm.getWidth() + ":" + bm.getHeight());

    // dont'save image on SD, prevents delay and freezing screen
    //super.saveImage(xact, image);
}

现在,当您从 CameraFragment 调用 takePicture() 时,您将获得:

 04-06 11:47:12.576    3038-3038/net.agilob.ssocv I/CamFrg﹕ useSingleShotMode
 04-06 11:47:12.596    3038-3130/net.agilob.ssocv I/CamFrg﹕ saveImage
 04-06 11:47:12.676    3038-3130/net.agilob.ssocv E/CamFrg﹕ bitmap size: 1280:960

【讨论】:

    【解决方案2】:

    寻找解决方案: 我不使用 cwac 相机库。使用自定义相机布局。 Kut Camera

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      • 2017-05-11
      • 2015-10-25
      • 1970-01-01
      • 2016-09-29
      • 1970-01-01
      相关资源
      最近更新 更多