Android webview 中的 insampleSize 和 compress 有什么区别?
What is differece between insampleSize and compress in Android webview?
当我在 Google 中搜索此主题时,
1.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inSampleSize = 3;
if (bitmap == null) {
bitmap = BitmapFactory.decodeFile(filePath, options);
}
表示文件像素从1000*1000缩小到300*300。
和
2.
bitmap.compress(CompressFormat.JPEG, 80, bos);
这意味着大小(文件体积)减少了 1000kb -> 800kb。
对吗?
因为……我上传一些图片的时候,如果文件很大,我就上传失败了。 (我检查了文件体积是通过第二种方式减少的,而不是第一种方式)
所以我尝试了第一种方法,但也失败了。但是当我尝试第二种方式时,我成功了!!
所以这就是我问这个问题的原因。
C.f>
如果我裁剪位图,位图会改变吗???
Bitmap croppedBitmap = null;
if (i!=cnt) {
if ((croppedStart + pageHeight) > webview.getMeasuredHeight()) {
int lastHeight = webview.getMeasuredHeight() - croppedStart;
croppedBitmap = Bitmap.createBitmap(bitmap, 0, croppedStart, webview.getMeasuredWidth(),lastHeight-1);
} else {
try{
croppedBitmap = Bitmap.createBitmap(bitmap, 0, croppedStart, webview.getMeasuredWidth(), pageHeight);
}catch(Exception e){
e.printStackTrace();
}
}
croppedStart += pageHeight;
rtn.add(croppedBitmap);
}
执行此操作后,我的位图(原始)将 fullBtimap 更改为 Last croppedBitmap。
也谢谢!
质量仅适用于像 jpeg 这样的有损格式并影响 quality of the image。 inSampleSize
请求对原始图像进行子采样。它同时影响宽度和高度,这意味着最终图像将 1/inSampleSize
更小,原始图像的宽度和高度
当我在 Google 中搜索此主题时, 1.
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inSampleSize = 3;
if (bitmap == null) {
bitmap = BitmapFactory.decodeFile(filePath, options);
}
表示文件像素从1000*1000缩小到300*300。 和
2.
bitmap.compress(CompressFormat.JPEG, 80, bos);
这意味着大小(文件体积)减少了 1000kb -> 800kb。
对吗? 因为……我上传一些图片的时候,如果文件很大,我就上传失败了。 (我检查了文件体积是通过第二种方式减少的,而不是第一种方式)
所以我尝试了第一种方法,但也失败了。但是当我尝试第二种方式时,我成功了!!
所以这就是我问这个问题的原因。
C.f> 如果我裁剪位图,位图会改变吗???
Bitmap croppedBitmap = null;
if (i!=cnt) {
if ((croppedStart + pageHeight) > webview.getMeasuredHeight()) {
int lastHeight = webview.getMeasuredHeight() - croppedStart;
croppedBitmap = Bitmap.createBitmap(bitmap, 0, croppedStart, webview.getMeasuredWidth(),lastHeight-1);
} else {
try{
croppedBitmap = Bitmap.createBitmap(bitmap, 0, croppedStart, webview.getMeasuredWidth(), pageHeight);
}catch(Exception e){
e.printStackTrace();
}
}
croppedStart += pageHeight;
rtn.add(croppedBitmap);
}
执行此操作后,我的位图(原始)将 fullBtimap 更改为 Last croppedBitmap。 也谢谢!
质量仅适用于像 jpeg 这样的有损格式并影响 quality of the image。 inSampleSize
请求对原始图像进行子采样。它同时影响宽度和高度,这意味着最终图像将 1/inSampleSize
更小,原始图像的宽度和高度