等比例缩放图片
图片 缩放 比例
2023-09-14 08:58:19 时间
/ 缩放图片 br span >public static Bitmap zoomImg(String img, int newWidth ,int newHeight){
// 图片源
Bitmap bm = BitmapFactory.decodeFile(img);
if(null!=bm){
return zoomImg(bm,newWidth,newHeight);
}
return null;
}
public static Bitmap zoomImg(Context context,String img, int newWidth ,int newHeight){
// 图片源
try {
Bitmap bm = BitmapFactory.decodeStream(context.getAssets()
.open(img));
if (null != bm) {
return zoomImg(bm, newWidth, newHeight);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// 缩放图片
public static Bitmap zoomImg(Bitmap bm, int newWidth ,int newHeight){
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
return newbm;
}
// 图片源
Bitmap bm = BitmapFactory.decodeFile(img);
if(null!=bm){
return zoomImg(bm,newWidth,newHeight);
}
return null;
}
public static Bitmap zoomImg(Context context,String img, int newWidth ,int newHeight){
// 图片源
try {
Bitmap bm = BitmapFactory.decodeStream(context.getAssets()
.open(img));
if (null != bm) {
return zoomImg(bm, newWidth, newHeight);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
// 缩放图片
public static Bitmap zoomImg(Bitmap bm, int newWidth ,int newHeight){
// 获得图片的宽高
int width = bm.getWidth();
int height = bm.getHeight();
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
return newbm;
}
相关文章
- 图片旋转,鼠标滚轮缩放,镜像,切换图片js代码
- 全屏显示一张图片,不显示滚动条
- C# 热敏打印机 Socket 网络链接 打印 图片
- C#图片处理示例(裁剪,缩放,清晰度,水印)
- PHP图片裁剪与缩放 / 无损裁剪图片
- 如何制作迅雷7的皮肤,如何获取迅雷7皮肤的图片
- WordPress 去除图片img标签的高度与宽度
- 图片和byte[]数组互转
- chrome: css:transform:scale时部分缩放比例相邻图片间有间隔缝隙(chrome 106.0.5249.119)
- 图片(旋转/缩放/翻转)变换效果(ccs3/滤镜/canvas)
- 图片延迟加载并等比缩放,一个简单的JQuery插件
- Java 缩放图片工具类,创建缩略图、伸缩图片比例
- vue.js3: js下载图片的两种方式:url和canvas(vue@3.2.37)
- LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android
- flutter 图片切成圆形
- Dataset之图片数据增强:设计自动生成汽车车牌图片算法(cv2+PIL)根据指定七个字符自动生成逼真车牌图片数据集(带各种噪声效果)
- Qt开发——图片缩放简述
- 使用卷积神经网络实现图片去摩尔纹
- 如何利用CANN DVPP进行图片的等比例缩放?
- python等比缩放图片
- vue - vant组件库 - card组件 修改 thumb属性的图片 参数后不及时刷新解决
- QT实现图片的操作(缩放、平移、绘图、对比度及亮度调节)
- 【Android 内存优化】Android 工程中使用 libjpeg-turbo 压缩图片 ( JNI 传递 Bitmap | 获取位图信息 | 获取图像数据 | 图像数据过滤 | 释放资源 )
- QT图片查看器封装-鼠标中心缩放、移动、截图、框选、切换播放
- matlab 图片批量读取
- FPGA-基于ROM的静态图片的读取
- 图片上传预览插件制作----URL.createObjectURL()