Notice the black pixels along the borders. The ones on the top and left borders indicate the places where the image can be stretched, and the ones on the right and bottom borders indicate where the content should be placed.
// Get the source image's dimensions
BitmapFactory.Options options = new BitmapFactory.Options();
// This does not download the actual image, just downloads headers.
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(IMAGE_FILE_URL, options);
// The actual width of the image.
int srcWidth = options.outWidth;
// The actual height of the image.
int srcHeight = options.outHeight;
// Only scale if the source is bigger than the width of the destination view.
if(desiredWidth > srcWidth)
desiredWidth = srcWidth;
// Calculate the correct inSampleSize/scale value. This helps reduce memory use. It should be a power of 2.
int inSampleSize = 1;
while(srcWidth / 2 > desiredWidth){
srcWidth /= 2;
srcHeight /= 2;
inSampleSize *= 2;
}
float desiredScale = (float) desiredWidth / srcWidth;
// Decode with inSampleSize
options.inJustDecodeBounds = false;
options.inDither = false;
options.inSampleSize = inSampleSize;
options.inScaled = false;
// Ensures the image stays as a 32-bit ARGB_8888 image.
// This preserves image quality.
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap sampledSrcBitmap = BitmapFactory.decodeFile(IMAGE_FILE_URL, options);
// Resize
Matrix matrix = new Matrix();
matrix.postScale(desiredScale, desiredScale);
Bitmap scaledBitmap = Bitmap.createBitmap(sampledSrcBitmap, 0, 0,
sampledSrcBitmap.getWidth(), sampledSrcBitmap.getHeight(), matrix, true);
sampledSrcBitmap = null;
// Save
FileOutputStream out = new FileOutputStream(LOCAL_PATH_TO_STORE_IMAGE);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
scaledBitmap = null;
分享到:
相关推荐
根据url和图片左上右下两点坐标裁剪图片并返回base64格式字符串,java工具类,适用于人脸识别
matlab改变GUI和figure左上角图标的方法并生成exe文件-修改Matlab Figure图标的方法.rar 1. GUI左上角图标的更改,假设GUI的Tag为figure1,在其OpeningFcn里添加 h = handles.figure1; %返回其句柄 newIcon = ...
左上到右下遍历元素.cpp
Picasso – Android系统的图片下载和缓存类库 Picasso 是Square开源的一个用于Android系统下载和缓存图片的项目。该项目和其他一些下载图片项目的主要区别之一是:使用4.0+系统上的HTTP缓存来代替磁盘缓存。 ...
给定一个N x N 的数字矩阵, 每个点都有一个正整数(大小为0-9),从左上角出发, 每次只能向右或者向下移动一个单位,直到走到右下角为止。求得一条路线,使得这条路线上的数字和最小。 输入: 第一行输入 N 表示...
左上角点击弹出菜单.rar左上角点击弹出菜单.rar左上角点击弹出菜单.rar左上角点击弹出菜单.rar左上角点击弹出菜单.rar左上角点击弹出菜单.rar
两种方法:Ⅰ. Ctrl+G Ⅱ. 双击状态栏中的行号 3. 怎样创建矩形选区? 两种方法:Ⅰ. 摁住alt键,然后拖动鼠标即可。 Ⅱ. 按住Shift+Alt点击矩形的左上和右下位置即可。 4. 怎样快速隐藏或显示当前代码段? Ctrl+MM
左上角的菜单.rar左上角的菜单.rar左上角的菜单.rar左上角的菜单.rar左上角的菜单.rar左上角的菜单.rar
微信开发的时候,在公众号菜单中打开一个H5页面(如:个人中心),在这个页面上的一些操作,经过多次跳转后,点击左上角的返回按钮,发现会原封不动的返回至上一级页面。 即 公众号菜单->A->B->C,点击返回后,返回了B...
js+css使DIV始终居于屏幕中间 左下 左上 右上 右下的代码集合.docx
用ppt来实现图片缩小到左上角的效果实现图片缩小到左上角的效果
从左上角斜切换出来的图片特效
我使用的版本是1.5,其他版本类似,资源里面有已经去水印的go.js,和去水印的方法,需要的可以使用啊,功能还是很强大,拓扑的最佳选择。
Android实现在图片左上角或右上角显示文字标签,相信这个功能大家以前肯定见到过,只是不知道如何形容这个功能,本实例还可实现调整标签文字的大孝标签与图片边角的距离、修改标签文字和标签背景颜色、标签宽度和...
完整的读取txt文件里的全部坐标,并找到左上、右下两个顶点的坐标并进行裁剪、后送入tesseract中进行识别
设置左上角的单元格.xlsx源码EXCEL VBA宏编程xlsx实例代码下载设置左上角的单元格.xlsx源码EXCEL VBA宏编程xlsx实例代码下载设置左上角的单元格.xlsx源码EXCEL VBA宏编程xlsx实例代码下载设置左上角的单元格.xlsx...
CSS3对角线淡入相册代码,图片会以对角的形式从左上到右下淡入,点击小图可大图预览,支持键盘左右方向键翻页。兼容主流浏览器.rar
1.图片切换效果有以下几种:随机切换 4格纵向百叶窗 16格横向百叶窗 由里至外逐渐放大 中间向左右两边逐渐放大 中间向上下两边逐渐放大 由上至下落幕 由左至右 由左上至右下 由右下至左上 8格纵向百叶窗 8格纵向百叶...
javascr ipt 代码 图片图片固定在页面左上角
C#400-抓取左上角图片,源代码