如何开发Android美颜相机

}

调用美颜相机:

<?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:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“.CameraActivity”>

<com.aglframework.smzh.camera.CameraPreview

android:id=“@+id/camera_preview”

android:layout_width=“match_parent”

android:layout_height=“match_parent” />

在Activity中加入以下代码:

public class CameraActivity extends Activity {

private AGLView aglView;

private AGLCamera1 aglCamera1;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_camea);

aglView = findViewById(R.id.camera_preview);

}

@Override

protected void onResume() {

super.onResume();

if (aglCamera1 == null) {

aglCamera1 = new AGLCamera1(aglView, 1080, 1920);

}

aglCamera1.open();

}

}

@Override

protected void onPause() {

super.onPause();

if (aglCamera1 != null) {

aglCamera1.close();

}

}

}

CameraDemo

====================================================================

将 4x5 矩阵转换成一维数组,然后再将这一维数组设置到ColorMatrix类里去:

//将矩阵设置到图像

private void setImageMatrix() {

Bitmap bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

ColorMatrix colorMatrix = new ColorMatrix();

colorMatrix.set(mColorMatrix);//将一维数组设置到ColorMatrix

Canvas canvas = new Canvas(bmp);

Paint paint = new Paint();

paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));

canvas.drawBitmap(bitmap, 0, 0, paint);

iv_photo.setImageBitmap(bmp);

}

xml布局:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android=“http://schemas.android.com/apk/res/android”

xmlns:tools=“http://schemas.android.com/tools”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

tools:context=“com.example.deeson.mycolormatrix.MainActivity”

android:orientation=“vertical”>

<ImageView

android:id=“@+id/iv_photo”

android:layout_width=“300dp”

android:layout_height=“0dp”

android:layout_weight=“3”

android:layout_gravity=“center_horizontal”/>

<GridLayout

android:id=“@+id/matrix_layout”

android:layout_width=“match_parent”

android:layout_height=“0dp”

android:layout_weight=“4”

android:columnCount=“5”

android:rowCount=“4”>

<LinearLayout

android:layout_width=“match_parent”

android:layout_height=“wrap_content”

android:orientation=“horizontal”>

<Button

android:id=“@+id/btn_change”

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:text=“change”/>

<Button

android:id=“@+id/btn_reset”

android:layout_width=“0dp”

android:layout_height=“wrap_content”

android:layout_weight=“1”

android:text=“reset”/>

通过 View 的 post() 方法,在视图创建完毕后获得其宽高值:

matrixLayout.post(new Runnable() {

@Override

public void run() {

mEtWidth = matrixLayout.getWidth() / 5;

mEtHeight = matrixLayout.getHeight() / 4;

addEts();

initMatrix();

}

});

MainActivity代码:

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

Bitmap bitmap;

ImageView iv_photo;

GridLayout matrixLayout;

//每个edittext的宽高

int mEtWidth;

int mEtHeight;

//保存20个edittext

EditText[] mEts = new EditText[20];

//一维数组保存20个矩阵值

float[] mColorMatrix = new float[20];

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.iv_model);

iv_photo = (ImageView) findViewById(R.id.iv_photo);

matrixLayout = (GridLayout) findViewById(R.id.matrix_layout);

Button btn_change = (Button) findViewById(R.id.btn_change);

Button btn_reset = (Button) findViewById(R.id.btn_reset);

btn_change.setOnClickListener(this);

btn_reset.setOnClickListener(this);

iv_photo.setImageBitmap(bitmap);

//我们无法在onCreate()方法中获得视图的宽高值,所以通过View的post()方法,在视图创建完毕后获得其宽高值

matrixLayout.post(new Runnable() {

@Override

public void run() {

mEtWidth = matrixLayout.getWidth() / 5;

mEtHeight = matrixLayout.getHeight() / 4;

addEts();

initMatrix();

}

});

}

//动态添加edittext

private void addEts() {

for (int i = 0; i < 20; i++) {

EditText et = new EditText(this);

et.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

mEts[i] = et;

matrixLayout.addView(et, mEtWidth, mEtHeight);

}

}

//初始化颜色矩阵

private void initMatrix() {

for (int i = 0; i < 20; i++) {

if (i % 6 == 0) {

mEts[i].setText(String.valueOf(1));

} else {

mEts[i].setText(String.valueOf(0));

}

}

}

//获取矩阵值

private void getMatrix() {

for (int i = 0; i < 20; i++) {

String matrix = mEts[i].getText().toString();

boolean isNone = null == matrix || “”.equals(matrix);

mColorMatrix[i] = isNone ? 0.0f : Float.valueOf(matrix);

if (isNone) {

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

写在最后

最后我想说:对于程序员来说,要学习的知识内容、技术有太多太多,要想不被环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!

这里附上上述的技术体系图相关的几十套腾讯、头条、阿里、美团等公司2021年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。

相信它会给大家带来很多收获:

当程序员容易,当一个优秀的程序员是需要不断学习的,从初级程序员到高级程序员,从初级架构师到资深架构师,或者走向管理,从技术经理到技术总监,每个阶段都需要掌握不同的能力。早早确定自己的职业方向,才能在工作和能力提升中甩开同龄人。

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!

环境淘汰就只有不断提升自己,从来都是我们去适应环境,而不是环境来适应我们!

这里附上上述的技术体系图相关的几十套腾讯、头条、阿里、美团等公司2021年的面试题,把技术点整理成了视频和PDF(实际上比预期多花了不少精力),包含知识脉络 + 诸多细节,由于篇幅有限,这里以图片的形式给大家展示一部分。

相信它会给大家带来很多收获:

[外链图片转存中…(img-D2J9KFs7-1712393746320)]

[外链图片转存中…(img-yVsENZKQ-1712393746320)]

当程序员容易,当一个优秀的程序员是需要不断学习的,从初级程序员到高级程序员,从初级架构师到资深架构师,或者走向管理,从技术经理到技术总监,每个阶段都需要掌握不同的能力。早早确定自己的职业方向,才能在工作和能力提升中甩开同龄人。

《Android学习笔记总结+移动架构视频+大厂面试真题+项目实战源码》,点击传送门即可获取!
  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值