java - 在 Android 中保存位图

标签 java android bitmap bit-manipulation steganography

我正在尝试为 Android 实现隐写术项目。我已经操纵了像素值并创建了一个新的位图。现在,当我使用

将位图存储到手机内存或存储卡中时
//fo denotes File output Stream
Bitmap.compress(Bitmap.CompressFormat.JPEG,100,fo);
//OR
Bitmap.compress(Bitmap.CompressFormat.PNG,100,fo);   

并尝试使用 getPixels() 访问像素;

值被还原为原始位图,即而不是被操纵的位图。 谁能知道这是为什么?

最佳答案

File myDir=new File("/sdcard/saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-"+ n +".jpg";
File file = new File (myDir, fname);
if (file.exists ()) file.delete (); 
try {
       FileOutputStream out = new FileOutputStream(file);
       finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
       out.flush();
       out.close();

} catch (Exception e) {
       e.printStackTrace();
}

看这个答案https://stackoverflow.com/a/7887114/964741

关于java - 在 Android 中保存位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8283635/

相关文章:

方法调用后 Java 类变为无效

java.lang.ClassNotFoundException : org. apache.james.mime4j.message.Message

android - 是否可以直接在 android 上录制 MJPEG?

c - 位图文件的填充

android - 如何从位图中获取 Uri 对象

java - 使用户无法访问网页

java - 可 ScrollView 与其他 subview (例如 Google 街景 View )交互

android - 默认值/strings.xml 的语言

c# - 将位图设置为 MP3 的封面

java - 如何将 log4j 日志记录从 catalina.out 重定向到单独的文件?