如何将Android中的高质量位图图像插入到Gallery中 [英] How to insert high quality Bitmap image in android into Gallery

查看:85
本文介绍了如何将Android中的高质量位图图像插入到Gallery中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道插入方法

  MediaStore.Images.Media.insertImage(..............)

插入原始位图图像的缩略图,我需要一种无需压缩即可保存位图的方法,以使其像素保持原样(隐写术),我需要将图像存储在内部存储库中.

Insert a thumbnail instaed of the original Bitmap image,I need a way to save Bitmap with no compress to keep its pixels as they are (steganography), I need the image to be stored on gallery in internal storage.

推荐答案

Gallery可以包含适用于Android的应用程序的文件夹,要获取高分辨率文件,需要将其存储在Gallery之外,并向Gallery告知您的文件和应用程序文件夹并将您的文件显示为缩略图,因此我实现了此方法,可以执行所需的操作,希望对其他人有所帮助

The Gallery can contains folders for application on android, to get high resolution file there is need to store them outside the gallery and tell gallery about your file and your application folder and show your files as thumbnails,so I implement this method which perform what I need and I hope help others

  private void SaveImage(Bitmap segg) {

    OutputStream fOut = null;
    Random generator = new Random();
    int n = 10000;
    n = generator.nextInt(n);
    String fileName = "Image-"+ n +".png";
    final String appDirectoryName = "TBStego";
    final File imageRoot = new File(Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_PICTURES), appDirectoryName);

    imageRoot.mkdirs();
    final File file = new File(imageRoot, fileName);
    try {
        fOut = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    segg.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    try {
        Toast.makeText(ExtractActivity.this,
                file.getAbsolutePath(),
                Toast.LENGTH_LONG).show();
        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    ContentValues values = new ContentValues();
    values.put(MediaStore.Images.Media.TITLE,"stego");
    values.put(MediaStore.Images.Media.DESCRIPTION, "stego description");
    values.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis());
    values.put(MediaStore.Images.ImageColumns.BUCKET_ID, file.toString().toLowerCase(Locale.US).hashCode());
    values.put(MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, file.getName().toLowerCase(Locale.US));
    values.put("_data", file.getAbsolutePath());
    Toast.makeText(ExtractActivity.this,
            file.getAbsolutePath(),
            Toast.LENGTH_LONG).show();
    ContentResolver cr = getContentResolver();
    cr.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
    Toast.makeText(ExtractActivity.this, "The Image thumbnail created in Gallery ", Toast.LENGTH_LONG).show();
}

这篇关于如何将Android中的高质量位图图像插入到Gallery中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆