前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >视频直播系统源码,图片叠加

视频直播系统源码,图片叠加

原创
作者头像
yunbaokeji柯基
修改2020-10-27 17:54:43
1.7K0
修改2020-10-27 17:54:43
举报
文章被收录于专栏:直播知识直播知识
代码语言:javascript
复制

package com.zmlxj.customcompass;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
public class Main2Activity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
ImageView image=findViewById(R.id.iv_image);
      /*  // 防止出现Immutable bitmap passed to Canvas constructor错误
        Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(),
                R.drawable.compass_bottom).copy(Bitmap.Config.ARGB_8888, true);
        Bitmap bitmap2 = ((BitmapDrawable) getResources().getDrawable(
                R.drawable.compass_char)).getBitmap();
        Bitmap newBitmap = null;
        newBitmap = Bitmap.createBitmap(bitmap1);
        Canvas canvas = new Canvas(newBitmap);
        Paint paint = new Paint();
        int w = bitmap1.getWidth();
        int h = bitmap1.getHeight();
        int w_2 = bitmap2.getWidth();
        int h_2 = bitmap2.getHeight();
        paint.setColor(Color.GRAY);
        paint.setAlpha(125);
        canvas.drawRect(0, 0, bitmap1.getWidth(), bitmap1.getHeight(), paint);
        paint = new Paint();
        canvas.drawBitmap(bitmap2, Math.abs(w - w_2) / 2,
                Math.abs(h - h_2) / 2, paint);
        canvas.save();
        // 存储新合成的图片
        canvas.restore();
        image.setImageBitmap(newBitmap);*/
        Bitmap bitmap1 = ((BitmapDrawable) getResources().getDrawable(
                R.drawable.compass_bottom)).getBitmap();
        Bitmap bitmap2 = ((BitmapDrawable) getResources().getDrawable(
                R.drawable.compass_char)).getBitmap();
        Bitmap bitmap3 = ((BitmapDrawable) getResources().getDrawable(
                R.drawable.compass_pointer)).getBitmap();
        Drawable[] array = new Drawable[3];
        array[0] = new BitmapDrawable(bitmap1);
        array[1] = new BitmapDrawable(bitmap2);
        array[2] = new BitmapDrawable(bitmap3);
        LayerDrawable la = new LayerDrawable(array);
        // 其中第一个参数为层的索引号,后面的四个参数分别为left、top、right和bottom
        la.setLayerInset(0, 0, 0, 0, 0);
        la.setLayerInset(1, 20, 20, 20, 20);
      int[] all=  getImageWidthHeight();
        Log.i("获取的值",all[0]+"_"+all[1]);
        la.setLayerInset(2, 40,  (all[1]/8), 40, 40);
        image.setImageDrawable(la);
    }
    public  int[] getImageWidthHeight(){
        BitmapFactory.Options options = new BitmapFactory.Options();
        /**
         * 最关键在此,把options.inJustDecodeBounds = true;
         * 这里再decodeFile(),返回的bitmap为空,但此时调用options.outHeight时,已经包含了图片的高了
         */
        options.inJustDecodeBounds = true;
//        Bitmap bitmap = BitmapFactory.decodeFile(this.getResources()., options); // 此时返回的bitmap为null
        BitmapFactory.decodeResource(getResources(),R.drawable.compass_bottom,options);
        /**
         *options.outHeight为原始图片的高
         */
        return new int[]{options.outWidth,options.outHeight};
    }
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档