Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在androidjava中将位图转换为图像_Java_Image_Bitmap_Bitmapimage - Fatal编程技术网

如何在androidjava中将位图转换为图像

如何在androidjava中将位图转换为图像,java,image,bitmap,bitmapimage,Java,Image,Bitmap,Bitmapimage,我想将我的位图转换为图像,而不是可绘制的,我已经看到了一些例子,他们正在将位图转换为可绘制的,但我需要媒体。图像(图像),然后我用进一步的逻辑处理该图像。帮我解决这个问题 简而言之,我需要将位图转换为它的图像 Bitmap original_with_water_mark= addWatermark(original_image_bitmap,water_mark_bitmap,300); 我需要这个带水印的原始位图转换为要存储的图像。但我不知道如何将位图转换为图像 因为在运行函数中,请在开

我想将我的位图转换为图像,而不是可绘制的,我已经看到了一些例子,他们正在将位图转换为可绘制的,但我需要媒体。图像(图像),然后我用进一步的逻辑处理该图像。帮我解决这个问题 简而言之,我需要将位图转换为它的图像

 Bitmap original_with_water_mark= addWatermark(original_image_bitmap,water_mark_bitmap,300);
我需要这个
带水印的原始位图
转换为要存储的图像。但我不知道如何将位图转换为图像

因为在运行函数中,请在开始时查看,我需要
mImage
,这是我必须存储的图像

 @Override
        public void run() {

            ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
            byte[] bytes = new byte[buffer.remaining()];
            buffer.get(bytes);
            FileOutputStream output = null;
            try {
                output = new FileOutputStream(mFile);
                output.write(bytes);
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                mImage.close();
                if (null != output) {
                    try {
                        output.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
你可以使用:-


您可以将其以任何图像格式保存在本地存储器中

private void storeImage(Bitmap image) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {
    Log.d(TAG,
            "Error while creating media file, Please ask for storage permission");
    return;
} 
try {
    FileOutputStream fos = new FileOutputStream(pictureFile);
    image.compress(Bitmap.CompressFormat.PNG, 90, fos);
    fos.close();
} catch (FileNotFoundException e) {
    Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
    Log.d(TAG, "Error accessing file: " + e.getMessage());
}  
}

}

private void storeImage(Bitmap image) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {
    Log.d(TAG,
            "Error while creating media file, Please ask for storage permission");
    return;
} 
try {
    FileOutputStream fos = new FileOutputStream(pictureFile);
    image.compress(Bitmap.CompressFormat.PNG, 90, fos);
    fos.close();
} catch (FileNotFoundException e) {
    Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
    Log.d(TAG, "Error accessing file: " + e.getMessage());
}  
private  File getOutputMediaFile(){

File mediaStorageDir = new File(Environment.getExternalStorageDirectory()
        + "/Android/data/"
        + getApplicationContext().getPackageName()
        + "/Files"); 


if (! mediaStorageDir.exists()){
    if (! mediaStorageDir.mkdirs()){
        return null;
    }
}  
String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date());
File mediaFile;
    String mImageName="MI_"+ timeStamp +".jpg";
    mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);  
return mediaFile;