- public class ImageUtil {
- public static InputStream getRequest(String path) throws Exception {
- URL url = new URL(path);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setRequestMethod("GET");
- conn.setConnectTimeout(5000);
- if (conn.getResponseCode() == 200){
- return conn.getInputStream();
- }
- return null;
- }
- public static byte[] readInputStream(InputStream inStream) throws Exception {
- ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
- byte[] buffer = new byte[4096];
- int len = 0;
- while ((len = inStream.read(buffer)) != -1) {
- outSteam.write(buffer, 0, len);
- }
- outSteam.close();
- inStream.close();
- return outSteam.toByteArray();
- }
- public static Drawable loadImageFromUrl(String url){
- URL m;
- InputStream i = null;
- try {
- m = new URL(url);
- i = (InputStream) m.getContent();
- } catch (MalformedURLException e1) {
- e1.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- Drawable d = Drawable.createFromStream(i, "src");
- return d;
- }
- public static Drawable getDrawableFromUrl(String url) throws Exception{
- return Drawable.createFromStream(getRequest(url),null);
- }
- public static Bitmap getBitmapFromUrl(String url) throws Exception{
- byte[] bytes = getBytesFromUrl(url);
- return byteToBitmap(bytes);
- }
- public static Bitmap getRoundBitmapFromUrl(String url,int pixels) throws Exception{
- byte[] bytes = getBytesFromUrl(url);
- Bitmap bitmap = byteToBitmap(bytes);
- return toRoundCorner(bitmap, pixels);
- }
- public static Drawable geRoundDrawableFromUrl(String url,int pixels) throws Exception{
- byte[] bytes = getBytesFromUrl(url);
- BitmapDrawable bitmapDrawable = (BitmapDrawable)byteToDrawable(bytes);
- return toRoundCorner(bitmapDrawable, pixels);
- }
- public static byte[] getBytesFromUrl(String url) throws Exception{
- return readInputStream(getRequest(url));
- }
- public static Bitmap byteToBitmap(byte[] byteArray){
- if(byteArray.length!=0){
- return BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
- }
- else {
- return null;
- }
- }
- public static Drawable byteToDrawable(byte[] byteArray){
- ByteArrayInputStream ins = new ByteArrayInputStream(byteArray);
- return Drawable.createFromStream(ins, null);
- }
- public static byte[] Bitmap2Bytes(Bitmap bm){
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
- return baos.toByteArray();
- }
- public static Bitmap drawableToBitmap(Drawable drawable) {
- Bitmap bitmap = Bitmap
- .createBitmap(
- drawable.getIntrinsicWidth(),
- drawable.getIntrinsicHeight(),
- drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
- : Bitmap.Config.RGB_565);
- Canvas canvas = new Canvas(bitmap);
- drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
- drawable.getIntrinsicHeight());
- drawable.draw(canvas);
- return bitmap;
- }
- /**
- * 图片去色,返回灰度图片
- * @param bmpOriginal 传入的图片
- * @return 去色后的图片
- */
- public static Bitmap toGrayscale(Bitmap bmpOriginal) {
- int width, height;
- height = bmpOriginal.getHeight();
- width = bmpOriginal.getWidth();
- Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
- Canvas c = new Canvas(bmpGrayscale);
- Paint paint = new Paint();
- ColorMatrix cm = new ColorMatrix();
- cm.setSaturation(0);
- ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
- paint.setColorFilter(f);
- c.drawBitmap(bmpOriginal, 0, 0, paint);
- return bmpGrayscale;
- }
- /**
- * 去色同时加圆角
- * @param bmpOriginal 原图
- * @param pixels 圆角弧度
- * @return 修改后的图片
- */
- public static Bitmap toGrayscale(Bitmap bmpOriginal, int pixels) {
- return toRoundCorner(toGrayscale(bmpOriginal), pixels);
- }
- /**
- * 把图片变成圆角
- * @param bitmap 需要修改的图片
- * @param pixels 圆角的弧度
- * @return 圆角图片
- */
- public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
- Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
- Canvas canvas = new Canvas(output);
- final int color = 0xff424242;
- final Paint paint = new Paint();
- final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
- final RectF rectF = new RectF(rect);
- final float roundPx = pixels;
- paint.setAntiAlias(true);
- canvas.drawARGB(0, 0, 0, 0);
- paint.setColor(color);
- canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
- paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
- canvas.drawBitmap(bitmap, rect, rect, paint);
- return output;
- }
- /**
- * 使圆角功能支持BitampDrawable
- * @param bitmapDrawable
- * @param pixels
- * @return
- */
- public static BitmapDrawable toRoundCorner(BitmapDrawable bitmapDrawable, int pixels) {
- Bitmap bitmap = bitmapDrawable.getBitmap();
- bitmapDrawable = new BitmapDrawable(toRoundCorner(bitmap, pixels));
- return bitmapDrawable;
- }
- }
相关推荐
unity 动态加载image以及button,实现image在屏幕内移动
unity 动态加载image以及button,实现image在屏幕内移动、 using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.UI; public class GUI_Test : MonoBehaviour { ...
Android仿微信UI布局视图(圆角布局的实现)
圆角button。或布局能够在xml文件里实现,但也能够使用图片直接达到所需的效果,曾经版本号的微信就使用了这样的方法。 实现效果图: 不得不说,这样的做法还是比較方便的。 源码: MainActivity(没写不论什么代码。效果全在布局文件里实现): package com.android_settings; import android.app.Acti...
OpenHarmony实战开发-image、image-animator组件的使用。
OpenHarmony提供了常用的图片、图片帧动画播放器组件,开发者可以根据实际场景和开发需求,实现不同的界面交互效果,包括:点击阴影效果、点击切换状态、点击动画效果、点击切换动效。
Qt QSS中 background-image,border-image,以及image属性差别
QSS中 background-image,border-image,以及image属性差别
Unity之Image & Raw Image
推荐阅读: 我的优快云 我的博客园 QQ群:704621321 我的个人博客 前言 正文 1Raw Image
用Diffusion Models实现image-to-image转换
Diffusion Models专栏文章汇总:入门与实战 前言:diffusion models诞生到现在,很多论文热衷于把diffusion models带到自己的领域用于生成,也有不少人醉心于用各种奇技淫巧优化采样过程,以改善diffusion models致命的缺点:生成速度太慢。而Palette的诞生意义不亚于pix2pix GANs、cycleGANs,能够实现图像着色、图像修复、图像剪裁恢复、图像解压缩(超分)等等任务。我们第一次发现,原来diffusion models不仅仅能用于生..
image对象的属性说明
一、image.shape的那些事: 1.image.shape[:2]表示 取彩色图片的高、宽, 2.image.shape[:3] 表示取彩色图片的高、宽、通道 3.image.shape[0], 图片垂直尺寸 4.image.shape[1], 图片水平尺寸 5.image.shape[2], 图片通道数 具体的解释为: 1)输出 height,即获取图像的高度,图像的高度为shape的第一...
docker 删除image 报:image has dependent child images 错误
问题 在 Docker 中删除 image 时有时会遇到类似 Error response from daemon: conflict: unable to delete 6ec9a5a0fc9f (cannot be forced) - image has dependent child images 这样的错误,原因是有另外的 image FROM 了这个 image,可以使用下面的命令列出所有在指定 image 之后创建的 image 的父 image docker ima..
【QT】Qt QSS 中 background-image、image 和 border-image 的区别
需要背景纹理或渐变效果 :使用 background-image需要显示图标或内容图片 :使用 image需要创建可伸缩的UI元素 :使用 border-image。
LabVIEW+数据库应用系列保姆级教程,第一篇数据库连接
目录LabVIEW连接数据库的方法连接MySQL连接Oracle,SQL Server,Access等 LabVIEW连接数据库的方法 1、创建udl(Universal Data Link)是通用数据连接文件。界面操作,简单快捷。 2、编写连接字符串。需要熟悉连接字符串的结构,容易出错。 3、其他… 本教程教你使用第1种方法,也是最简单、最常用的方法。 连接MySQL 1、在MySQL Installer内安装MySQL Connector/ODBC,建议安装32位(X86),如下图: 2、创建ODBC
机器人关节电机发热难题:从工程化角度拆解热管理解决方案(下)
摘要:本文系统分析了机器人关节电机与驱动系统的热管理方案,重点解决局部热点问题。针对不同功率场景提出了热管/均热板散热(适用于中小功率)和液冷散热(适用于高功率)的具体实施方案,详细比较了结构参数、材料选择、安装工艺和散热效果。特别强调了电机-驱动协同热管理的重要性,提出"工况联动+热路径共享"的核心理念,包括一体化散热结构设计和动态控制策略。最后介绍了热仿真与测试验证方法,确保方案的有效落地。通过系统级热管理,可显著降低温升(热点区域降温30-60℃),同时优化体积和能耗。
border-image 的正确用法
border-image 的正解用法border-image 边框图片,顾名思义: 指定边框使用的图片。尽管经常使用 border-image(-webkit-border-image),但我们真的了解它的吗?本文分两部分来介绍 border-image:border-image 简史border-image 用法1. border-image 简史CSS3 border 最开始是做为一个独立模块...
CANoe之UDS诊断自动化测试(四):创建诊断自定义Panel发送诊断(替代Session Control窗口)
通过自定义的Panel界面实现诊断发送的功能,并且还可以根据自己的测试需求添加需要的诊断信息,使用非常灵活。
grafana的image render设置
Grafana supports automatic rendering of panels as PNG images. This allows Grafana to automatically generate images of your panels to include in alert notifications. Note: Image rendering of dashboards is not supported at this time. Grafana支持将面板自动呈现为PNG图像。
芯片详解——AD7606
AD7606详解
Backblaze 2025全年硬盘故障率报告解读
作为长期追踪存储行业动态的科技博主,每年/季度Backblaze的Drive Stats报告都是我重点关注的核心内容——不同于厂商发布的实验室数据,Backblaze以近13年、数十万片企业级硬盘的真实运行数据为基础,其年化故障率(AFR)、寿命趋势等结论,直接反映了硬盘在严苛数据中心环境下的真实表现,无论是企业存储选型还是个人高端存储参考,都具备极高的实用价值。2025年末,Backblaze发布了第13年的年度收官报告,涵盖2025年Q4、全年及终身硬盘可靠性数据。
pygame之image模块
image-用于图像传输的Pygame模块 pygame.image.load—从文件加载新图像 pygame.image.save—将图像保存到磁盘 pygame.image.get_extended—测试是否可以加载扩展图像格式 pygame.image.tostring—将图像传输到字符串缓冲区 pygame.image.from...
thinkphp 微信商户转账到微信用户零钱(v3密钥版)(含SDK和文档)
一种是用v3密钥的接口:微信商户转账到零钱(听说是v2接口的微信商户容易被限制,后来就改成v3了)这几天做项目有一个需求,小程序用户提交记录后,商家后台审核通过自动转账到用户的微信零钱中.今天分享下如何实现自动打款,v3微信商户转账到零钱。接口返回状态查看原因。
【Flutter】Image 组件 ( Image 组件简介 | Image 构造函数 | Image.network 构造函数 | Image.asset 构造函数 )
一、Image 组件简介、 二、Image 构造函数、 二、Image.network 构造函数、、 四、Image.file 构造函数、 五、Image.asset 构造函数、 六、Image.memory 构造函数、
2021年03月 C/C++(五级)真题解析#中国电子学会#全国青少年软件编程等级考试
给定一个十进制正整数n(0 < n < 1000000000),每个数位上数字均不为0。n的位数为m。现在从m位中删除k位(0
13、基于RBF的自适应鲁棒控制与反步控制方法及实现
本文介绍了基于RBF神经网络的自适应鲁棒控制与反步控制方法,详细阐述了控制系统的程序结构、核心算法及实现流程。通过Simulink搭建仿真系统,利用RBF网络逼近系统中的不确定非线性函数,并结合Lyapunov稳定性理论设计控制律,实现了对倒立摆等复杂非线性系统的高精度跟踪控制。文章还提供了完整的MATLAB/Simulink代码示例和仿真结果分析,验证了该方法的有效性与鲁棒性,为实际工程应用提供了可行的技术路径。
小程序组件之——cover-image与image
cover-image与image 没错我们就是从头开始往下撸。有啥就讲啥。外带一些扩展。 聊正题因为是第一个组件,不对,应该说是第一组组件,因为image和cover-image是两个组件,不过因为太像啦,所以就拿出来一起讲。因为是第一组,所以我没讲解一下,wxml的代码都写在后缀为wxml中,css代码都写在wxss中,js在后缀是js的文件中,不需要像pc端那样刻意的去引用,只要写好了,系统自己就很聪明,帮你搞定这些事了,前提是文件名相同。 ok,这个东西时间久了 都会用的。咱们聊正事啦,终于开始讲正
WINCC7.3破解文件
WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!
Image & Raw Image的区别
一、面板参数 1、Image类型: Source Image:图片资源(sprite) Color:颜色 Material:材质 Raycast Target :是否作为射线目标 Sprite 2D:是贴图的原始大小。 2、Raw Image类型: Source Ima...
android 蓝牙通讯demo
android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。
大中型超市收银系统(可直接运行)
光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开
border-image-slice
border-image-slice是用来分解引入进来的背景图片,这个参数相对来说比较复杂和特别,主要表现在以下几点: 1、其取值支持: | 其中number是没有单位的,专指像素px,因为其默认的单位就是像素px,所以在使用number时不需要加上单位,如果加上了单位反而是错误的写法。另外我们除了直接用nuember来设置外,我们还可以使用百分比值来表示,百分比的值是相对于边框背景图片而言
jdk-8u144-linux-x64.tar.gz.
该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包
border-image属性总结
border-image是一个挺“复杂”的属性,主要使用场景有: 元素边框不规则的情况。这时候,就需要用设计图作为边框背景,border-image与background-image相比,好处是更具灵活性,可以用代码控制边框背景的拉伸和重复,因而能够创造出更多样的效果 按钮宽高不确定的情况。用border-image来制作按钮,可以用同一张背景图,制造出各种宽高的按钮。 菜鸟、W3SCH...
QT border-image和background-image引起的边框设置问题
一、border-image 在一个frame中放入一张图片,设置frame的样式表,会发现边框设置没有生效。 border-image:url(:/refresh.png); border:1px solid red; 二、background-image 也在一个frame中放入一张图片,设置frame的样式表,会发现边框确实设置了,但图片没有正确显示。 background-image:...
3465



被折叠的 条评论
为什么被折叠?



