Android:将位图插入到图像中。Media 总是为存储的图像获取黑色背景

标签 android android-imageview android-image android-bitmap

我正在使用 InsertImage 插入图像,但是每次将图像存储到SD卡上时,其背景都会变黑。如何删除黑色背景?

我的代码是:

> Bitmap Img = BitmapFactory.decodeResource(getResources(),
>              R.drawable.ic_launcher); String path =
> Images.Media.insertImage(getContentResolver(), Img, "myImg", "Image");

最佳答案

请在将图像保存到 SD 卡之前使用此格式 ----->>> Bitmap.compressFormat.PNG 如果您使用 Bitmap.compressFormat.JPEG,您的问题将会重复

public class SDCard {

public void setBitmap(Bitmap bitmap, String filename)
        throws FileNotFoundException {

    File folder = new File(Environment.getExternalStorageDirectory()
            .getAbsolutePath() + "/JANU");

    if (!folder.exists()) {
        folder.mkdir();

    }
    File imagefile = new File(folder, filename);
    FileOutputStream fout = new FileOutputStream(imagefile);

    boolean bit = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fout);

}

关于Android:将位图插入到图像中。Media 总是为存储的图像获取黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26056657/

相关文章:

android - 我的 gridview 不工作,因为找不到 id

android - 如何让抽屉导航在android studio上打开一个 Activity

Java SSL 握手失败有时会失败,具体取决于 VM 参数/属性

android - 在 android 中,我可以将 subview 添加到 ImageView 吗?

android - 如何在全 View 中显示图像

android - 显示比设备屏幕大的图像

android - 如何在 Android 中验证(数字)像素完美的开发?

android - 在 Android 上再次打开并保存相同的图像

android - 当我在 android 中单击 ImageView 时如何突出显示 ImageView 的边框

android - 显示大图像但在 android 中共享小图像