我想让手机中的图库之类的多个图像感到羞耻。
例如,当我单击一张图像时,所有图像将水平显示,在底部,可以选择在whatsapp,Facebook等类似图库中共享多个图像。
我该怎么做?
请帮助我知道答案的人。
请参见github上的示例代码,包含图像库并与其他应用程序共享图像:https://github.com/ptrvsky/android-image-gallery
为了共享图像,您可以使用此方法(请参见上面链接中的ImageFullViewFragment.java
类:]
// Method that open share intent with image given in argument
public void shareImage(File image) {
Intent intent3 = new Intent(Intent.ACTION_SEND);
intent3.setType("image/jpg");
intent3.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(image));
startActivity(Intent.createChooser(intent3, "Share image"));
}
用于加载图像表格URL地址,请使用Picasso:
public void shareImage(String url) {
Picasso.with(getApplicationContext()).load(url).into(new Target() {
@Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/*");
i.putExtra(Intent.EXTRA_STREAM, getLocalBitmapUri(bitmap));
startActivity(Intent.createChooser(i, "Share Image"));
}
@Override public void onBitmapFailed(Drawable errorDrawable) { }
@Override public void onPrepareLoad(Drawable placeHolderDrawable) { }
});
}
将位图转换为uri:
public Uri getLocalBitmapUri(Bitmap bmp) {
Uri bmpUri = null;
try {
File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "share_image_" + System.currentTimeMillis() + ".png");
FileOutputStream out = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
bmpUri = Uri.fromFile(file);
} catch (IOException e) {
e.printStackTrace();
}
return bmpUri;
}