zoukankan      html  css  js  c++  java
  • Android图片处理--全景查看效果

    PS:Android对于图片处理这块资源还是挺多的,之前用OpenGL制作图片的全景效果,耗时耗力,而且只能点击进去后看到,但是效果是非常的号,今天所写的是编写好的一个图片控件,只要拿来用就可以了。效果不是那么好,处理的之后就是一张图片截取中间部分放大再显示在屏幕中间,通过摆动手机查看被遮挡部分,如图:一开始图片是这样的

    上面就是效果图了

    1:添加依赖

    //全景图片
        compile 'com.gjiazhe:PanoramaImageView:1.0'

    2:使用控件

    <com.gjiazhe.panoramaimageview.PanoramaImageView
            android:id="@+id/panorama_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/timg"
            app:piv_enablePanoramaMode="true"
            app:piv_show_scrollbar="true"
            app:piv_invertScrollDirection="false" />

    布局的根目录一定要加上

        xmlns:app="http://schemas.android.com/apk/res-auto"

    这里面有三个属性(其中三个)

    一个是app:piv_enablePanoramaMode,使用全景效果模式,app:piv_show_scrollbar滚动条显示,app:piv_invertScrollDirection颠倒滚动方向,不同的值就会呈现不同的效果。

    3:注册GyroscopeObserver

    在使用PanoramaImageView的Activity或Fragment中,您应该在onResume()中注册GyroscopeObserver,并记得在onPause()中注销它。

    public class MyActivity extends AppCompatActivity {
      
        private GyroscopeObserver gyroscopeObserver;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            // Initialize GyroscopeObserver.
            gyroscopeObserver = new GyroscopeObserver();
            // Set the maximum radian the device should rotate to show image's bounds.
            // It should be set between 0 and π/2.
            // The default value is π/9.
              gyroscopeObserver.setMaxRotateRadian(Math.PI/9);
    
            PanoramaImageView panoramaImageView = (PanoramaImageView) findViewById(R.id.panorama_image_view);
            // Set GyroscopeObserver for PanoramaImageView.
            panoramaImageView.setGyroscopeObserver(gyroscopeObserver);
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            // Register GyroscopeObserver.
            gyroscopeObserver.register(this);
        }
    
        @Override
        protected void onPause() {
            super.onPause();
            // Unregister GyroscopeObserver.
            gyroscopeObserver.unregister();
        }
    }

    设置OnPanoramaScrollListener以观察滚动状态 如果要在图像滚动时获得回调,PanoramaImageView需要设置OnPanoramaScrollListener。

    panoramaImageView.setOnPanoramaScrollListener(new PanoramaImageView.OnPanoramaScrollListener() {
        @Override
        public void onScrolled(PanoramaImageView view, float offsetProgress) {
            // Do something here.
            // The offsetProgress range from -1 to 1, indicating the image scrolls
            // from left(top) to right(bottom).
        }
    });
  • 相关阅读:
    数据库 | 建表常用语句
    心得 | 撰写项目申报书
    工具 | 时间转化
    SpringBoot | 启动异常 | 显示bulid success 无 error信息
    120. 三角形最小路径和
    63. 不同路径 II
    SpringBoot | Velocity template
    SpringBoot | quartz | @DisallowConcurrentExecution
    SpringBoot | Hibernate @Transient 注解
    Java | 基础归纳 | 静态方法与实例方法的区别
  • 原文地址:https://www.cnblogs.com/cmusketeer/p/9164365.html
Copyright © 2011-2022 走看看