1坯墨、先獲取到項(xiàng)目中的圖片并保存到SD卡里面芥喇。
private voidGetandSaveCurrentImage() {
// 1.構(gòu)建Bitmap
Bitmap Bmp = BitmapFactory.decodeResource(getResources(), R.drawable.shouuye) ;
// 2.獲取屏幕
String SavePath = getSDCardPath();
// 3.保存Bitmap
try{
File path =newFile(SavePath);
// 文件
String filepath = SavePath +"/Screen.png";
Log.i("FilePath",""+filepath);
File file =newFile(filepath);
if(!path.exists()) {
path.mkdirs();
}
if(!file.exists()) {
file.createNewFile();
}
FileOutputStream fos =null;
fos =newFileOutputStream(file);
if(null!= fos) {
Bmp.compress(Bitmap.CompressFormat.PNG,90, fos);
fos.flush();
fos.close();
}
}catch(Exception e) {
e.printStackTrace();
}
}
/**
* 獲取SDCard的目錄路徑功能
*/
privateString getSDCardPath() {
File sdcardDir =null;
// 判斷SDCard是否存在
booleansdcardExist = Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED);
if(sdcardExist) {
sdcardDir = Environment.getExternalStorageDirectory();
}
returnsdcardDir.toString();
}
2使套、然后再shareSDK中的showshare方法中添加
String SavePath = getSDCardPath();
// 3.保存Bitmap
File path =newFile(SavePath);
// 文件
String filepath = SavePath +"/Screen.png";
GetandSaveCurrentImage();
3罐呼、oks.imagepath改成
oks.setImagePath(filepath);