android的.jpg和.jpg之间有区别吗?
我想知道图像扩展名android的.jpg和.jpg之间有区别吗?,android,jpeg,Android,Jpeg,我想知道图像扩展名.jpg和.jpg之间是否有什么区别。我遇到一个问题,无法使用以下代码打开.JPG图像: public static Bitmap decodeSampledBitmapFromResource(String path, int reqWidth, int reqHeight) { Log.e("PATH", path); // First decode with inJustDecodeBounds=true to ch
.jpg
和.jpg
之间是否有什么区别。我遇到一个问题,无法使用以下代码打开.JPG图像:
public static Bitmap decodeSampledBitmapFromResource(String path,
int reqWidth, int reqHeight) {
Log.e("PATH", path);
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// Calculate inSampleSizeа
options.inSampleSize = calculateInSampleSize(options, reqWidth,
reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
Bitmap b = BitmapFactory.decodeFile(path, options);
if(b!=null){
Log.d("bitmap","decoded sucsessfully");
}else{
Log.d("bitmap","decoding failed; options: "+options.toString());
}
return b;
}
public static int calculateInSampleSize(BitmapFactory.Options options,
int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
Log.d("bitmap", "original options: height "+ height + " widnth "+width+" inSampleSize "+inSampleSize);
if (height > reqHeight || width > reqWidth) {
// Calculate ratios of height and width to requested height and
// width
final int heightRatio = Math.round((float) height
/ (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
// Choose the smallest ratio as inSampleSize value, this will
// guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
Log.d("bitmap", "options: height "+ height + " widnth "+width+" inSampleSize "+inSampleSize);
}
return inSampleSize;
}
在*.JPG图像上,返回的位图为空。
我想问的是,它们通常是以不同的方式实现的,还是特定于GalaxyS3?(我无法在Galaxy Tab 7.7或HTC手机上重复此操作。)Android在Linux操作系统上运行,该操作系统区分大小写
如果文件的扩展名是小写的,比如:“.jpg”,那么您应该在源代码中引用。如果文件的扩展名为“.JPG”,也应使用代码编写。我的路径和文件扩展名正确。所以你说的是保持,但我得到的位图是空的。尝试通过从路径创建
文件对象来确认这一点,然后使用文件.exists()
方法进行检查。如果返回false
,则路径不正确,如果true
但仍然得到空位图,则。。。我不确定。。。可能文件已损坏,无法解码。
decodeSampledBitmapFromResource(path, 80, 60)