ShareSDK,分享项目中的图片

1、先获取到项目中的图片并保存到SD卡里面。

private voidGetandSaveCurrentImage() {

// 1.构建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);

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容