【问题标题】:Rotating Camera Capture for Android in Web View在 Web 视图中为 Android 旋转摄像头捕获
【发布时间】:2013-07-22 13:45:47
【问题描述】:

我正在捕获图像,将数据(字节数组)存储在二维字节数组中(用户最多可以为该任务拍摄五张图像)。每次捕获后,我都会在 Web 视图中显示它。即使我以纵向模式拍摄照片,它也会以横向模式加载到 Web 视图中,是否有办法改变它或防止它发生?

我已经包含了 android:orientation..etc

        //Setting Zoom Controls on Web View
         WebPreview.getSettings().setBuiltInZoomControls(true);
         WebPreview.getSettings().setDisplayZoomControls(false);
         WebPreview.getSettings().setLoadWithOverviewMode(true);
         WebPreview.getSettings().setUseWideViewPort(true);
         WebPreview.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
         imageData = PhotoHandler.ImageByteArray[pHandler.counter];
         openJpeg(WebPreview, imageData);

private static void openJpeg(WebView web, byte[] image)
{
    String b64Image = Base64.encodeToString(image, Base64.DEFAULT);
    String html = String.format(HTML_FORMAT, b64Image);
    web.loadData(html, "text/html", "utf-8");
}

我真的不确定该怎么做,而且我似乎找不到任何关于旋转 webview 内容的信息..

感谢任何指导。

谢谢

【问题讨论】:

    标签: android webview android-camera android-orientation


    【解决方案1】:

    对于可能遇到相同问题的任何人,我已经解决了轮换问题

    我将字节数组转换为位图,旋转然后转换回字节数组...

            Bitmap test = BitmapFactory.decodeByteArray(IMdata, 0, IMdata.length);
    
            //Getting Width and Height of Bitmap
            int width = test.getWidth();
            int height = test.getHeight();
    
            Matrix rotMatrix = new Matrix();
    
            //Rotating Bitmap * 90 deg
            rotMatrix.postRotate(90);
    
            //Recreating new Bitmap After Rotation
            Bitmap testRot = Bitmap.createBitmap(receipt, 0,0,width, height, rotMatrix, true);
    

    然后我把它转换回来

             testRot.compress(Bitmap.CompressFormat.JPEG, 60, stream);
             byte [] testArray = stream.toByteArray();
    

    编辑 关于相机的问题我会单独贴出来

    【讨论】:

      猜你喜欢
      • 2012-10-17
      • 1970-01-01
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多