/** * @param origPath 源图片文件路径 * @param width 缩略图设定宽度 * @param height 缩略图设定高度 * @return 返回缩略图,失败返回null */ public Bitmap getImageThumbFromMK(String origPath, int width, int height) { // 产生缩略图,并把该文件存到指定目录下,更新数据库中图片信息 Bitmap thumbnail = null; Log.d(TAG, origPath + ":make thumbnail and insert message in database"); ThumbnailCreator mCreator = new ThumbnailCreator(width, height); thumbnail = mCreator.createThumbnail(origPath); if (thumbnail == null) { return null; } String name = null; try { name = origPath.substring(origPath.lastIndexOf("/") + 1, origPath.lastIndexOf(".")); } catch (IndexOutOfBoundsException e) { e.printStackTrace(); return null; } try { File f = new File(imageDB.getAppDir() + "/" + name); FileOutputStream fOut = null; fOut = new FileOutputStream(f); thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, fOut); fOut.flush(); fOut.close(); imageDB.insert(origPath, f.getPath()); } catch (Exception e) { // TODO Auto-generated catch block Log.d(TAG, "create temp file false"); e.printStackTrace(); } return thumbnail; }