我在内存中保存了一幅图像。例如,我将其保存为test.jpg。现在我想把它展示在一个图像视图中。我试过这样做:
ImageView img = (ImageView)findViewById(R.id.imageView1);
try {
img.setImageDrawable(Drawable.createFromPath("test.jpg"));
} catch (Exception e) {
Log.e(e.toString());
}
并在LogCat中获得以下消息:
SD卡可用于读取和写入真实的
有什么帮助或推荐信吗?
发布于 2012-01-05 06:00:53
public class AndroidBitmap extends Activity {
private final String imageInSD = "/sdcard/er.PNG";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD);
ImageView myImageView = (ImageView)findViewById(R.id.imageview);
myImageView.setImageBitmap(bitmap);
}
}
或
final Bitmap bm = BitmapFactory.decodeStream( ..some image.. );
// The openfileOutput() method creates a file on the phone/internal storage in the context of your application
final FileOutputStream fos = openFileOutput("my_new_image.jpg", Context.MODE_PRIVATE); // Use the compress method on the BitMap object to write image to the OutputStream
bm.compress(CompressFormat.JPEG, 90, fos);
希望它能成功..。
发布于 2012-01-05 06:08:24
看看文档..。
您不需要“知道”图像存储在哪里。你只需要抓住你保存下来的东西,然后你就可以再读一遍。
问题是..。你把文件保存在那里了吗?还是将其与已编译到应用程序中的图像混淆?如果是后者,文档还会讨论如何读取这些文件,它们与您已写入设备的文件不同,它们是应用程序包的一部分。
欢迎来到Stack!如果你发现答案是有用的,不要忘了把它们加起来,如果它们解决了你的问题,就把它们标记为“正确”。
干杯。
https://stackoverflow.com/questions/8738263
复制相似问题