我需要帮助。
我已经通过 web-services 从服务器获取了一张图片,但是我不想分享这张图片。
我附上了我的代码,请帮我找出错误。
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bitmap bitmap = viewToBitmap(iv, iv.getWidth(), iv.getHeight());
Intent shareintent = new Intent(Intent.ACTION_SEND);
shareintent.setType("image/jpeg");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
File file = new File(Environment.getExternalStorageDirectory() +
File.separator + "Imagedemo.jpg");
try {
file.createNewFile();
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(byteArrayOutputStream.toByteArray());
}
catch (IOException e) {
e.printStackTrace();
}
shareintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/Imagedemo.jpg"));
startActivity(Intent.createChooser(shareintent,"share image"));
}
});
public static Bitmap viewToBitmap(View view, int width, int height){
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
view.draw(canvas);
return bitmap;
}