Android ImageView以及实现截图

实现效果

截图前

在这里插入图片描述

截图后

在这里插入图片描述

代码

package cn.jj.huaweiad;import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;import androidx.appcompat.app.AppCompatActivity;import cn.jj.sdkcomtools.utils.LogUtils;public class ImageViewActivity extends AppCompatActivity {private static final String TAG = "JJWorld.ImageViewActivity";private ImageView imageViewTest;private Button fitXYBtn;private Button fitStartBtn;private Button fitCenterBtn;private Button fitEndBtn;private Button centerBtn;private Button centerCropBtn;private Button centerInsideBtn;private Button mfitXYBtn;private Button layout;private ViewGroup rootView;private ViewGroup rootView1;private LinearLayout mRootLayout;private ImageView captureImageView;private Button captureBtn;private Handler mHandler;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_image_view);rootView = (ViewGroup) findViewById(android.R.id.content);initView();imageViewTest.setImageResource(R.drawable.tk_huawei_ad_splash_slogan_portait);printAllViewsInLayout((ViewGroup) findViewById(android.R.id.content), 0);mHandler = new Handler();rootView.setDrawingCacheEnabled(true);}@SuppressLint("LongLogTag")private void printAllViewsInLayout(ViewGroup layout, int level) {int childCount = layout.getChildCount();for (int i = 0; i < childCount; i++) {View childView = layout.getChildAt(i);Log.d(TAG, "View level:" + level + ", index " + i + ": " + childView.getClass().getSimpleName());// 如果子视图是ViewGroup,则递归地打印其子视图if (childView instanceof ViewGroup) {printAllViewsInLayout((ViewGroup) childView, level + 1);}}}private void initView() {imageViewTest = (ImageView) findViewById(R.id.image_view_test);fitXYBtn = (Button) findViewById(R.id.fitXY_btn);fitXYBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {imageViewTest.setScaleType(ImageView.ScaleType.FIT_XY);}});fitStartBtn = (Button) findViewById(R.id.fitStart_btn);fitStartBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {imageViewTest.setScaleType(ImageView.ScaleType.FIT_START);}});fitCenterBtn = (Button) findViewById(R.id.fitCenter_btn);fitCenterBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {imageViewTest.setScaleType(ImageView.ScaleType.FIT_CENTER);}});fitEndBtn = (Button) findViewById(R.id.fitEnd_btn);fitEndBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {imageViewTest.setScaleType(ImageView.ScaleType.FIT_END);}});centerBtn = (Button) findViewById(R.id.center_btn);centerBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {imageViewTest.setScaleType(ImageView.ScaleType.CENTER);}});centerCropBtn = (Button) findViewById(R.id.centerCrop_btn);centerCropBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {imageViewTest.setScaleType(ImageView.ScaleType.CENTER_CROP);}});centerInsideBtn = (Button) findViewById(R.id.centerInside_btn);centerInsideBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {imageViewTest.setScaleType(ImageView.ScaleType.CENTER_INSIDE);}});layout = (Button) findViewById(R.id.layout);layout.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {rootView.removeAllViews();LogUtils.logI(TAG,"---------------------------");FrameLayout newRootView = new FrameLayout(ImageViewActivity.this);setContentView(newRootView);printAllViewsInLayout((ViewGroup) findViewById(android.R.id.content), 0);}});mRootLayout = (LinearLayout) findViewById(R.id.m_root_layout);captureImageView = (ImageView) findViewById(R.id.capture_image_view);captureBtn = (Button) findViewById(R.id.capture_btn);captureBtn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Bitmap bitmap = rootView.getDrawingCache();captureImageView.setImageBitmap(bitmap);mHandler.postDelayed(mRunnable,200);}});}private Runnable mRunnable = new Runnable(){@Overridepublic void run() {rootView.setDrawingCacheEnabled(false);rootView.setDrawingCacheEnabled(true);}};
}

xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/m_root_layout"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><ImageViewandroid:id="@+id/image_view_test"android:layout_width="match_parent"android:layout_height="300dp" /><ImageViewandroid:id="@+id/capture_image_view"android:layout_width="match_parent"android:layout_height="200dp" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/fitXY_btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="fitXY" /><Buttonandroid:id="@+id/fitStart_btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="fitStart" /><Buttonandroid:id="@+id/fitCenter_btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="fitCenter" /><Buttonandroid:id="@+id/fitEnd_btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="fitEnd" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/center_btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="center" /><Buttonandroid:id="@+id/centerCrop_btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="centerCrop" /><Buttonandroid:id="@+id/centerInside_btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="centerInside" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/layout"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="layout" /><Buttonandroid:id="@+id/capture_btn"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="截图" /></LinearLayout>
</LinearLayout>

日志

应用启动,点击layout日志如下:

2024-03-28 20:54:08.051  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:0, index 0: LinearLayout
2024-03-28 20:54:08.051  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:1, index 0: AppCompatImageView
2024-03-28 20:54:08.051  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:1, index 1: AppCompatImageView
2024-03-28 20:54:08.051  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:1, index 2: LinearLayout
2024-03-28 20:54:08.051  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:2, index 0: MaterialButton
2024-03-28 20:54:08.051  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:2, index 1: MaterialButton
2024-03-28 20:54:08.051  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:2, index 2: MaterialButton
2024-03-28 20:54:08.051  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:2, index 3: MaterialButton
2024-03-28 20:54:08.052  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:1, index 3: LinearLayout
2024-03-28 20:54:08.052  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:2, index 0: MaterialButton
2024-03-28 20:54:08.052  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:2, index 1: MaterialButton
2024-03-28 20:54:08.052  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:2, index 2: MaterialButton
2024-03-28 20:54:08.052  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:1, index 4: LinearLayout
2024-03-28 20:54:08.052  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:2, index 0: MaterialButton
2024-03-28 20:54:08.052  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:2, index 1: MaterialButton
2024-03-28 20:54:14.092  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       I  ---------------------------
2024-03-28 20:54:14.093  3772-3772  JJWorld.Im...ewActivity cn.jj.huaweiad                       D  View level:0, index 0: FrameLayout

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/2904879.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

如何在Apache Arrow中定位与解决问题

如何在apache Arrow定位与解决问题 最近在执行sql时做了一些batch变更&#xff0c;出现了一个 crash问题&#xff0c;底层使用了apache arrow来实现。本节将会从0开始讲解如何调试STL源码crash问题&#xff0c;在这篇文章中以实际工作中resize导致crash为例&#xff0c;引出如何…

微信小程序更换头像的功能

微信小程序开发&#xff0c;个人中心中更换头像的更能使用频率很高&#xff0c;这里记录下实现方式&#xff1a; <view class"setting-list avatar-container"><text>头像</text><view class"avatar"><button hover-class"…

【零基础C语言】编译和链接

1.翻译环境和运行环境 翻译环境&#xff1a;将源代码转化为可执行的机器指令 运行环境&#xff1a;用于执行机器指令 1.1 翻译环境 翻译环境由编译和链接两大过程构建&#xff0c;编译又可以分为三大过程&#xff1a; 【1】预处理(预编译) 【2】编译 【3】汇编 不同的.c文件经…

Django安装及第一个项目

1、安装python C:\Users\leell>py --version Python 3.10.6 可以看出我的环境python的版本3.10.6&#xff0c;比较新 2、 Python 虚拟环境创建 2.1 官网教程 目前&#xff0c;有两种常用工具可用于创建 Python 虚拟环境&#xff1a; venv 在 Python 3.3 及更高版本中默…

IP种子是什么?理解和应用

在网络世界中&#xff0c;IP种子是一个广泛应用于文件共享和网络下载领域的概念。它是一种特殊的标识符&#xff0c;用于识别和连接到基于对等网络&#xff08;P2P&#xff09;协议的文件共享网络中的用户或节点。本文将深入探讨IP种子的含义、作用以及其在网络中的应用。 IP地…

Vivado使用(1)——综合的约束与策略

目录 一、概述 二、约束与策略 2.1 约束 2.1.1 物理约束 2.1.2 时序约束 2.2 综合策略 2.2.1 flatten_hierarchy 2.2.2 gated_clock_conversion 2.2.3 bufg 2.2.4 fanout_limit 2.2.5 directive 2.2.6 retiming 2.2.7 fsm_extraction 2.2.8 keep_equivalent_regi…

Stable Diffusion WebUI 图生图(img2img):图生图/涂鸦绘制/局部重绘/有色蒙版/上传蒙版/批量处理/反推提示词

本文收录于《AI绘画从入门到精通》专栏&#xff0c;专栏总目录&#xff1a;点这里&#xff0c;订阅后可阅读专栏内所有文章。 大家好&#xff0c;我是水滴~~ 本篇文章我们介绍 Stable Diffusion WebUI 的图生图功能&#xff0c;主要包括&#xff1a;图生图、图生图&#xff08…

戴尔电脑Dell SupportAssist占用内存高,卸载Dell SupportAssist

咨询戴尔客服了解到&#xff0c;SupportAssist是机器出厂自带的一款应用&#xff0c;主要的功能是可以检查驱动更新以及做一些硬件方面的健康检测&#xff0c;有时候后台运行可能会导致进程占用内存比较大&#xff0c;导致访问被的应用崩溃。 咨询卸载不影响之后&#xff0c;然…

有效的数独-java

题目描述: 请你判断一个 9 x 9 的数独是否有效。只需要 根据以下规则 &#xff0c;验证已经填入的数字是否有效即可。 数字 1-9 在每一行只能出现一次。数字 1-9 在每一列只能出现一次。数字 1-9 在每一个以粗实线分隔的 3x3 宫内只能出现一次。&#xff08;请参考示例图&#…

JMM Java内存模型

JMM本身是一个抽象的概念,不是真实存在的,它仅仅是一种规定或者说是规范 1.用来实现线程和主内存直接的抽象关系 2.屏蔽各个硬件平台和操作系统的内存访问差异,使得java程序在各种平台都能达到一致的内存访问效果 JMM的三大特性 可见性 多线程环境下,某个线程修改了变量…

腾讯云4核8G服务器多少钱?12M带宽646元15个月,买1年送3月

2024年腾讯云4核8G服务器租用优惠价格&#xff1a;轻量应用服务器4核8G12M带宽646元15个月&#xff0c;CVM云服务器S5实例优惠价格1437.24元买一年送3个月&#xff0c;腾讯云4核8G服务器活动页面 txybk.com/go/txy 活动链接打开如下图&#xff1a; 腾讯云4核8G服务器优惠价格 轻…

基于SpringCloud+Hadoop+Vue实现的企业级网盘系统实现

编程语言&#xff1a;Java、Mybatis、Spring、SpringBoot、SpringCloud、Node、Vue 开发环境&#xff1a;Windows 10 Mysql 开发工具&#xff1a;WebStorm、IDEA编译器、Git、Maven 应用部署服务器&#xff1a;SpringBoot内置Tomcat插件 Node服务器&#xff1a;Node v10.1…

深度学习论文: Attention is All You Need及其PyTorch实现

深度学习论文: Attention is All You Need及其PyTorch实现 Attention is All You Need PDF:https://arxiv.org/abs/1706.03762.pdf PyTorch: https://github.com/shanglianlm0525/PyTorch-Networks 大多数先进的神经序列转换模型采用编码器-解码器结构&#xff0c;其中编码器将…

Codeforces Round 937 (Div. 4) A - F 题解

A. Stair, Peak, or Neither? 题解&#xff1a;直接比较输出即可。 代码&#xff1a; #include<bits/stdc.h> using namespace std ; typedef long long ll ; const int maxn 2e5 7 ; const int mod 1e9 7 ; inline ll read() {ll x 0, f 1 ;char c getchar()…

地方美食分享网站的设计与实现|Springboot+Vue.js+ Mysql+Java+ B/S结构(可运行源码+数据库+设计文档)

本项目包含可运行源码数据库LW&#xff0c;文末可获取本项目的所有资料。 推荐阅读100套最新项目持续更新中..... 2024年计算机毕业论文&#xff08;设计&#xff09;学生选题参考合集推荐收藏&#xff08;包含Springboot、jsp、ssmvue等技术项目合集&#xff09; 目录 1. …

Redis、Mysql双写情况下,如何保证数据一致

Redis、Mysql双写情况下&#xff0c;如何保证数据一致 场景谈谈数据一致性三个经典的缓存模式Cache-Aside Pattern读流程写流程 Read-Through/Write-Through&#xff08;读写穿透&#xff09;Write behind &#xff08;异步缓存写入&#xff09; 操作缓存的时候&#xff0c;删除…

MySQL count(*/column)查询优化

count()是SQL中一个常用的聚合函数&#xff0c;其被用来统计记录的总数&#xff0c;下面通过几个示例来说明此类查询的注意事项及应用技巧。 文章目录 一、count()的含义二、count()的应用技巧2.1 同时统计多列2.2 利用执行计划 一、count()的含义 count()用于统计符合条件的记…

Unity TMP 使用教程

文章目录 1 导入资源包2 字体制作3 表情包制作4 TMP 控件4.1 属性4.2 富文本标签 1 导入资源包 “Window -> TextMeshPro -> Import TMP Essential Resources”&#xff0c;导入完成后会创建一个名为"TextMehs Pro"的文件夹&#xff0c;这里面包含所需要的资源…

使用pytorch构建一个初级的无监督的GAN网络模型

在这个系列中将系统的构建GAN及其相关的一些变种模型&#xff0c;来了解GAN的基本原理。本片为此系列的第一篇&#xff0c;实现起来很简单&#xff0c;所以不要期待有很好的效果出来。 第一篇我们搭建一个无监督的可以生成数字 (0-9) 手写图像的 GAN&#xff0c;使用MINIST数据…

就业班 第二阶段 2401--3.27 day8 shell之循环控制

七、shell编程-循环结构 shell循环-for语句 for i in {取值范围} # for 关键字 i 变量名 in 关键字 取值范围格式 1 2 3 4 5 do # do 循环体的开始循环体 done # done 循环体的结束 #!/usr/bin/env bash # # Author: # Date: 2019/…