編輯:關於Android編程
public static Bitmap getBitmapFromFile(String imgPath, int screenWidth, int screenHeight) {
File imgfile = new File(imgPath);
if (!imgfile.exists()) {
return null;
}
Bitmap bmp = null;
FileInputStream fis = null;
try {
Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(imgPath), null, options);
int sample = 1;
int imgWidth = options.outWidth;
int imgHeight = options.outHeight;
while ((imgWidth / sample > screenWidth * 2) || (imgHeight / sample > screenHeight * 2)) {
sample *= 2;
}
fis = new FileInputStream(imgPath);
if (sample > 1) {
options = new BitmapFactory.Options();
options.inPreferredConfig = Config.ARGB_8888;
options.inSampleSize = sample;
bmp = BitmapFactory.decodeStream(fis, null, options);
} else {
bmp = BitmapFactory.decodeStream(fis);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return bmp;
}
Matrix matrix = new Matrix(); matrix.setRotate(90); Bitmap rotateBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, false);
ExifInterface.TAG_ORIENTATION的值來計算,示例代碼如:
ExifInterface exif = null;
try {
exif = new ExifInterface(filePath);
} catch (IOException e) {
e.printStackTrace();
}
String sOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);
當得到ORIENTATION_ROTATE_90,將圖片旋轉90度
Android開發之基本控件和四種布局方式詳解
Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驅動。給控件添加事件也有接口回調和委托代理的方式。今天這篇博客就總結一下Android中常用的基
Android PreferenceActivity與PreferenceFragment詳解及簡單實例
Android PreferenceActivity與PreferenceFragment前言轉來轉去又回到了Android,閒話少說,這裡是參考Androi
微信怎麼搶紅包 微信紅包怎麼搶
微信紅包是騰訊旗下產品微信於2014年1月27日推出的一款應用,功能上可以實現發紅包、查收發記錄和提現。臨近春節了,新年發紅包是我們的傳統文化,現在微信紅包
android應用Theme(一)
android切換Theme主流三種方式來切換Theme,第一種是通過內置的style來切換,一般用於夜間模式/日間模式切換。第二種是通過apk來實現插件化,第三種是通過