有人设法使用RoundedBitmapDrawable?如果我错了,请纠正我,但根据我的理解,它会从常规矩形图像中生成圆形图像.
到目前为止我尝试过的是这个
RoundedBitmapDrawable.createRoundedBitmapDrawable(getResources(), BitmapFactory.decodeResource(getResources(), iconResource))
Run Code Online (Sandbox Code Playgroud)
我试图实现的目标:将任何图像转换为圆形图像并使用ImageView显示它.
如果我把事情搞混了,我所说的都是无意义的.是否可以(或更简单)使用任何新框架?(Android L或新的支持库)
我有一张来自网络的图片ImageView.它非常小(一个favicon),我想将它存储在我的SQLite数据库中.我可以得到一个Drawable,mImageView.getDrawable()但后来我不知道该怎么做.我不完全理解DrawableAndroid中的类.
我知道我可以从Bitmap类似的方式获得一个字节数组:
Bitmap defaultIcon = BitmapFactory.decodeStream(in);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bitmapdata = stream.toByteArray();
Run Code Online (Sandbox Code Playgroud)
但是如何从一个字节数组中获取Drawable?
setImageBitmap和之间有什么区别setImageDrawable?
我有一个图像,我想从文件动态设置.我遵循的教程说将我转换Bitmap为a BitmapDrawable然后使用它进行设置setImageDrawable.我注意到Bitmap直接设置setImageBitmap也有效,但我没有发现任何差异.
Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
BitmapDrawable bitmapDrawable = new BitmapDrawable(image);
imageView.setImageDrawable(bitmapDrawable);
Run Code Online (Sandbox Code Playgroud)
要么
Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(image);
Run Code Online (Sandbox Code Playgroud) 我需要从资产中获取位图和声音.我尝试这样做:
BitmapFactory.decodeFile("file:///android_asset/Files/Numbers/l1.png");
Run Code Online (Sandbox Code Playgroud)
像这样:
getBitmapFromAsset("Files/Numbers/l1.png");
private Bitmap getBitmapFromAsset(String strName) {
AssetManager assetManager = getAssets();
InputStream istr = null;
try {
istr = assetManager.open(strName);
} catch (IOException e) {
e.printStackTrace();
}
Bitmap bitmap = BitmapFactory.decodeStream(istr);
return bitmap;
}
Run Code Online (Sandbox Code Playgroud)
但我得到的是自由空间,而不是图像.
这该怎么做?
我一直在做很多搜索,我知道很多其他人都遇到了同样的OOM内存问题BitmapFactory.我的应用程序仅显示可用的4MB内存总量Runtime.getRuntime
().totalMemory().如果限制是16MB,那么为什么总内存不会增长以便为位图腾出空间呢?相反,它会抛出错误.
我也不明白,如果我有1.6MB的可用内存,根据Runtime.getRuntime().freeMemory()为什么我会收到错误说"VM不会让我们分配614400字节"?在我看来,我有足够的可用内存.
我的应用程序是完整的,除了这个问题,当我重新启动手机时,它会消失,以便我的应用程序是唯一运行的东西.我正在使用HTC Hero进行设备测试(Android 1.5).
在这一点上,我认为解决这个问题的唯一方法是以某种方式避免使用BitmapFactory.
任何人对此有任何想法或解释为什么当1.6MB的可用内存时VM不会分配614KB?
有了ImageView,我可以使用以下代码下载带回调的图像
Picasso.with(activity).load(url).into(imageView, new Callback()
{
@Override
public void onSuccess()
{
// do something
}
@Override
public void onError() { }
);
Run Code Online (Sandbox Code Playgroud)
或者只是从中获取Bitmap Picasso.with(activity).load(url).get();.无论如何都要添加回调才能下载图像?如果可能请提供示例代码,干杯!
我会尽量做空 - 所以我正在制作这个应用程序,将图像上传到自定义Webview,绘制画布并保存.现在我成功地执行了所有操作,直至保存它.我尝试了很多不同的方法,但都没有.
我保存未经编辑的图像Url:
public void DownloadFromUrl(String fileName) { //this is the downloader method
try {
URL url = new URL(wv2.getUrl()); //you can write here any link
File file = new File(fileName);
Canvas canvas = new Canvas();
wv2.draw(canvas );
long startTime = System.currentTimeMillis();
Log.d("ImageManager", "download begining");
Log.d("ImageManager", "download url:" + url);
Log.d("ImageManager", "downloaded file name:" + fileName);
URLConnection ucon = url.openConnection();
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int …Run Code Online (Sandbox Code Playgroud) 我有一个返回位图(“包含”二维码)的函数,我想在Image(可组合函数)中显示该位图,但我没有找到任何方法将位图转换为 aImageBitmap或仅显示该位图。
我想获得ImageView中的图像的高度和宽度,或者在android模拟器中获取背景图片.请帮助我,任何帮助都会被appriciated.
我正在制作一个应用程序,允许用户使用android意图共享图像,但如何获取该URI
一个位图,无需将其保存到SD卡
我使用这个代码工作正常,但我不需要将此位图保存到SD卡
private Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(inContext.getContentResolver(), inImage, "title", null);
return Uri.parse(path);
}
Run Code Online (Sandbox Code Playgroud)
我需要获取该URI而不将该位图保存到SD卡