PhotoView的使用

android 开源photoView的使用

96 
作者  吃不饱的水手 
2016.07.11 13:52*  字数 211  阅读 6223 评论 6

github地址:https://github.com/chrisbanes/PhotoView

简介

PhotoView 是一款扩展自Android ImageView,支持通过单点/多点触摸来进行图片缩放的智能控件。

特性:

支持单点/多点触摸,即时缩放图片;
支持平滑滚动;
在滑动父控件下能够运行良好;(例如:ViewPager)
当用户的触点改变是可以触发通知

第一步:添加maven url

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

第二步:依赖

compile 'com.github.chrisbanes:PhotoView:1.2.6'

第三步:布局

<uk.co.senab.photoview.PhotoView
  android:id="@+id/photoView"
  android:layout_width="180dp"
  android:layout_height="140dp"
  android:background="#333333"
  android:layout_marginLeft="20dp"
  />

第四步: 代码使用

PhotoView mPhotoView;
PhotoViewAttacher mAttacher;

mAttacher = new PhotoViewAttacher(mPhotoView);
mPhotoView.setImageBitmap(mBitmap);
mAttacher.update();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个基于 Android UVC Camera 和 PhotoView 的简单示例: 1.添加依赖项 在 app 的 build.gradle 文件中添加以下依赖项: ``` implementation 'com.github.chrisbanes:PhotoView:2.3.0' implementation 'com.github.saki4510t:UVCCamera:2.3.11' ``` 2.添加权限 在 AndroidManifest.xml 文件中添加以下权限: ``` <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.usb.host" /> <uses-feature android:name="android.hardware.camera" /> ``` 3.添加布局 在 activity 的布局文件中添加一个 PhotoView 和一个 Button,用于拍照: ``` <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.github.chrisbanes.photoview.PhotoView android:id="@+id/photo_view" android:layout_width="match_parent" android:layout_height="match_parent" /> <Button android:id="@+id/button_capture" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Capture" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true"/> </RelativeLayout> ``` 4.初始化 UVCCamera 在 activity 中,初始化 UVCCamera 并将预览输出到 PhotoView: ``` public class MainActivity extends AppCompatActivity implements View.OnClickListener { private PhotoView mPhotoView; private Button mButtonCapture; private UVCCamera mUVCCamera; private UVCCameraTextureView mUVCCameraTextureView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mPhotoView = findViewById(R.id.photo_view); mButtonCapture = findViewById(R.id.button_capture); mButtonCapture.setOnClickListener(this); // 初始化 UVCCamera mUVCCameraTextureView = new UVCCameraTextureView(this); mUVCCamera = new UVCCamera(); mUVCCamera.open(mUVCCameraTextureView); mUVCCamera.setPreviewSize(UVCCamera.DEFAULT_PREVIEW_WIDTH, UVCCamera.DEFAULT_PREVIEW_HEIGHT, UVCCamera.FRAME_FORMAT_YUYV); mUVCCamera.setPreviewDisplay(mUVCCameraTextureView); mUVCCamera.startPreview(); } @Override protected void onDestroy() { super.onDestroy(); // 释放 UVCCamera mUVCCamera.stopPreview(); mUVCCamera.close(); mUVCCameraTextureView = null; } @Override public void onClick(View v) { if (v == mButtonCapture) { // 拍照 mUVCCamera.captureStill(); } } } ``` 5.显示照片 在 UVCCamera.CaptureListener 中,处理拍照结果并将照片显示在 PhotoView 上: ``` mUVCCamera.setCaptureListener(new UVCCamera.CaptureListener() { @Override public void onCaptureResult(String path) { // 显示照片 Bitmap bitmap = BitmapFactory.decodeFile(path); mPhotoView.setImageBitmap(bitmap); } }); ``` 这样,一个简单的基于 Android UVC Camera 和 PhotoView 的示例就完成了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值