gpt4 book ai didi

java - Android Java中如何将位图转换为图像

转载 作者:行者123 更新时间:2023-12-01 23:23:45 26 4
gpt4 key购买 nike

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

 Bitmap original_with_water_mark= addWatermark(original_image_bitmap,water_mark_bitmap,300);

我需要将此original_with_water_mark 位图转换为要存储的图像。但我不知道如何将该位图转换为图像

因为在运行函数中,我需要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();
}
}
}
}

最佳答案

yu can use:-

    private void save(){ 
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss", Locale.ENGLISH);
filename = sdf.format(new Date());

try {
String path = getApplicationContext().getFilesDir().getPath();
OutputStream fOut = null;
File file = new File(path, "MYFile"//your file name);
if (!file.exists()) {
file.mkdirs();
}

File file2 = new File(file, filename + ".png");
fOut = new FileOutputStream(file2);


//your bitmap
original_with_water_mark.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
}
}

关于java - Android Java中如何将位图转换为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58316452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com