Comments (3)
let me tell you ,
long totalPixels = width * height / inSampleSize;
final long totalReqPixelsCap = reqWidth * reqHeight * 2;
while (totalPixels > totalReqPixelsCap) {
inSampleSize *= 2;
totalPixels /= 2;
}
This code is to deal with a large picture of the length or width of the case.It is OR,not AND.So I chose the code —— long totalPixels = width * height / inSampleSize;
Do you understand?
from androidstudycode.
i wrote a compare
public static int calculateInSampleSize(int rawW, int rawH, int reqWidth, int reqHeight) {
final int height = rawH;
final int width = rawW;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
long totalPixels = width * height / inSampleSize;
final long totalReqPixelsCap = reqWidth * reqHeight * 2;
while (totalPixels > totalReqPixelsCap) {
inSampleSize *= 2;
totalPixels /= 2;
}
}
return inSampleSize;
}
public static int calculateInSampleSize2(int rawW, int rawH, int reqWidth, int reqHeight) {
final int height = rawH;
final int width = rawW;
int inSampleSize = 1;
while ((height / inSampleSize) > reqHeight || (width / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
return inSampleSize;
}
public static int calculateInSampleSize3(int rawW, int rawH, int reqWidth, int reqHeight) {
final int height = rawH;
final int width = rawW;
int inSampleSize = 1;
long totalPixels = width * height / (inSampleSize* inSampleSize);
final long totalReqPixelsCap = reqWidth * reqHeight;
while (totalPixels > totalReqPixelsCap) {
inSampleSize *= 2;
totalPixels = width * height / (inSampleSize* inSampleSize);
}
return inSampleSize;
}
public static void main(String[] args) {
System.err.println(calculateInSampleSize(20, 1000, 100, 100));
System.err.println(calculateInSampleSize2(20, 1000, 100, 100));
System.err.println(calculateInSampleSize3(20, 1000, 100, 100));
System.err.println("-----------");
System.err.println(calculateInSampleSize(1000, 1000, 100, 100));
System.err.println(calculateInSampleSize2(1000, 1000, 100, 100));
System.err.println(calculateInSampleSize3(1000, 1000, 100, 100));
System.err.println("-----------");
System.err.println(calculateInSampleSize(1000, 10, 100, 100));
System.err.println(calculateInSampleSize2(1000, 10, 100, 100));
System.err.println(calculateInSampleSize3(1000, 10, 100, 100));
System.err.println("-----------");
System.err.println(calculateInSampleSize(10000, 10000, 100, 100));
System.err.println(calculateInSampleSize2(10000, 10000, 100, 100));
System.err.println(calculateInSampleSize3(10000, 10000, 100, 100));
}
and the output:
1
16
2
-----------
64
16
16
-----------
1
16
1
-----------
8192
128
128
from androidstudycode.
@hotstu hi,friend!You need to use real photo data!
from androidstudycode.
Related Issues (13)
- nexus 5x 版本6.0.1
- BitmapUtils.JPG_SUFFIX HOT 1
- 如果一个activity有很多fragment,封装的思路是怎么样的? HOT 1
- 开启“不保留活动”,还是会报异常
- 关于夜间模式有个小问题 :-) HOT 1
- diycode 访问好慢 HOT 7
- build error HOT 5
- BItmapUtils这个工具类里面没有啊 HOT 4
- 未指定存储目录 HOT 6
- 楼主能否加上取图和裁剪方面的功能,貌似那里的坑也比较多。 HOT 4
- 深入理解Android中的Matrix.md中图的标注有误 HOT 6
- some problems HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from androidstudycode.