`

How to set Android camera orientation properly?

 
阅读更多

This solution will work forallversions of Android. You can use reflection in Java to make it work for all Android devices:

Basically you should create a reflection wrapper to call the Android 2.2 setDisplayOrientation, instead of calling the specific method.

The method:

  protected void setDisplayOrientation(Camera camera, int angle){
  Method downPolymorphic;
  try
  {
    downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
    if (downPolymorphic != null)
      downPolymorphic.invoke(camera, new Object[] { angle });
  }
  catch (Exception e1)
  {
  }
}

And instead of usingcamera.setDisplayOrientation(x)usesetDisplayOrientation(camera, x):

  if (Integer.parseInt(Build.VERSION.SDK) >= 8)
    setDisplayOrientation(mCamera, 90);
  else
  {
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
    {
      p.set("orientation", "portrait");
      p.set("rotation", 90);
    }
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
      p.set("orientation", "landscape");
      p.set("rotation", 90);
    }
  } 
分享到:
评论

相关推荐

    Mastering Android Application Development(PACKT,2015)

    There are millions of Android apps out there for people to download how do you make sure yours has the edge? It’s not always about innovation and ideas the most successful apps are those that are ...

    Android代码-Photo Effects

    android-image-filter some android image filters in some filter, I use NDK to implement to make ...How to Use it It is dead simple, you can see magic in the following code: Bitmap newBitmap = BitmapFilt

    No suitable java found.In order to properly use the android developer tools...-附件资源

    No suitable java found.In order to properly use the android developer tools...-附件资源

    Android代码-时间选择器,选择特定间隔时间段。

    So you might need to set up Joda-Time properly. With start and end date times specified: val intent = DateTimeRangePickerActivity.newIntent( context, TimeZone.getDefault(), DateTime.now().millis, ...

    android lint performance probe帮助.zip

    for how to set the org.gradle.jvmargs property.) Finally, invoke Lint from Gradle as you normally do. Once Lint finishes, performance statistics for each Lint detector should be printed to the console...

    Android代码-韩国棋盘游戏

    How to download and play on Android Head over to the Google Play Store and download the latest release: https://play.google.com/store/apps/details?id=com.jeffreychan.yunnori How to work with the ...

    Building.Android.UIs.with.Custom.Views

    This book will help you construct a great UI for your apps by teaching you how to create custom Android views. You will start by creating your first Android custom view and go through the design ...

    Notice to users of DB Query Analyzer in Win7_Win8_Windows2010

    Unlike WinXP, VISTA, Windows2000, Windows Nt and Win98, Win7/Win8/... In order to use DB Query Analyzer properly, here I will illustrate how to set ‘-‘ as the default setting of short date in Win7.

    NatCam Pro - WebCam API v1.6f1.unitypackage

    NatCam allows you to set the camera's resolution. There are also resolution presets for ease of use. - Photo capture. NatCam allows you to capture high-resolution insta-worthy photos. You also have ...

    AR# 40779- MIG Spartan-6 MCB - How to properly terminate ODT, CK

    在FPGA设计中,特别是在使用Xilinx的MIG(Memory Interface Generator)Spartan-6 Memory Controller Block(MCB)时,正确地对ODT(On-Die Termination)、CKE(Clock Enable)和RESET管脚进行端接是至关重要的。...

    HANA FAQ (frequently asked question)

    47. How can the content of this and other SAP Notes with broad tables be displayed properly? 48. How can a SAP HANA connection for SAP support be established? 49. How can I provide input about useful ...

    Android 错误解决

    ### Android错误解决:Conversion to Dalvik format failed: Unable to execute dex: Wrapper was not properly loaded first 在Android开发过程中,开发者可能会遇到多种类型的错误提示。其中,“Conversion to ...

    dbws-callout-utility-10131

    The purpose of this article is to provide a step-by-step instruction on how to install the DBWS Callout Utilities on Oracle Database Server 10g and how to verify that it works properly. After ...

    practical-test-driven-development-c#7

    Chapter 2, Setting Up the .NET Test Environment, explains how to set up your IDE and configure the testing framework so that you can easily run your tests in C# and .NET, with more detail and many ...

    Android代码-仿iphone底部TAB标签

    You need to arrange them properly to stick tabs at bottom. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@ id/main_content" android:layout_width="match_...

    crypto++ & 帮助文档chm文件

    This guide does not attempt to teach what cryptography is, or how to use it properly. Learning cryptography takes time, and there are books and resources available that teach this subject very well. ...

Global site tag (gtag.js) - Google Analytics