gpt4 book ai didi

android - 从 Android 的内存中读取图像

转载 作者:行者123 更新时间:2023-11-29 15:29:10 26 4
gpt4 key购买 nike

我已经在内存中保存了一张图片。例如我将其保存为 test.jpg。现在我想在 ImageView 中显示它。我试过这个:

ImageView img = (ImageView)findViewById(R.id.imageView1);
try {
img.setImageDrawable(Drawable.createFromPath("test.jpg"));
} catch (Exception e) {
Log.e(e.toString());
}

并在 LogCat 中获取以下消息:

SD卡可读写truetrue

有什么帮助或引用吗?

最佳答案

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);

希望它有用...

关于android - 从 Android 的内存中读取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8738263/

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