如何在android的R.drawable文件夹中将jpg或png类型的图像加载到Bitmap对象中?如何将R.drawable文件夹图像分配给位图对象
Bitmap bmp = (Bitmap) putThisImageIntoBitmap(R.drawable.myimage);
如何在android的R.drawable文件夹中将jpg或png类型的图像加载到Bitmap对象中?如何将R.drawable文件夹图像分配给位图对象
Bitmap bmp = (Bitmap) putThisImageIntoBitmap(R.drawable.myimage);
首先,你必须使用BitmapFactory类,然后解码与绘制的ID和上下文的资源参数资源文件。
样品:
putThisImageIntoBitmap(BitmapFactory.decodeResource(context.getResources(),R.drawable.myimage));
InputStream is = null;
Bitmap bmp = null;
is = context.getResources().openRawResource(R.drawable.myimage);
bmp = BitmapFactory.decodeStream(is);
这对我的作品被拉伸的ID:
Bitmap icon = BitmapFactory.decodeResource(mContext.getResources(),
R.drawable.ic_launcher);
其中mContext
是当前活动的上下文。