简体   繁体   中英

How to crop image from camera preview (surface view) and save it instead of actual image captured bt camera like instagram app?

这是Instagram应用程序 I have an activity with surface view (match parent-match parent), half of which is hidden by button. Is it possible to save only visible part of captured picture? I've tried to make the surface view smaller, but preview is either rotated in this case or stretched. I'm using android.hardware.camera1 btw

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_camera" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="uz.pages.yangiuz10.activity.CameraActivity"> <SurfaceView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/surface_camera"/> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <View android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/colorBackgroundText"> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button_shot" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:src="@drawable/shot_btn" android:background="@null" android:onClick="onPictureCapture"/> </RelativeLayout> </LinearLayout> </RelativeLayout> 

只需要保存图像的可见部分

Below Link is Same as your Requirement's.

Please Check :

https://kylewbanks.com/blog/tutorial-square-camera-with-preview-on-android

Hope this will solve your problem...(:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM