我正在创建音频播放器,我想向播放器显示歌曲封面,它使用小图像,但如果mp3文件有大图像,那么它就会超出布局视图.我正在使用以下代码将图像重新调整为300x300:
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDensity = 300;
opt.inTargetDensity = 300;
songCoverView.setImageBitmap(BitmapFactory.decodeByteArray(songCover, 0, songCover.length, opt));
Run Code Online (Sandbox Code Playgroud)
但它仍然显示更大并且没有布局.
这段代码有什么问题?
我需要获得输入流中找到的图像的高度和宽度.这是我做的:
private Boolean testSize(InputStream inputStream){
BitmapFactory.Options Bitmp_Options = new BitmapFactory.Options();
Bitmp_Options.inJustDecodeBounds = true;
BitmapFactory.decodeResourceStream(getResources(), new TypedValue(), inputStream, new Rect(), Bitmp_Options);
int currentImageHeight = Bitmp_Options.outHeight;
int currentImageWidth = Bitmp_Options.outWidth;
Bitmp_Options.inJustDecodeBounds = false;
if(currentImageHeight < 200 || currentImageWidth < 200){
Object obj = map.remove(pageCounter);
Log.i("Page recycled", obj.toString());
return true;
}
return false;}
Run Code Online (Sandbox Code Playgroud)
跳到问题点:
即使我在下面的第二个方法计算后强制它为false,它也会更改BitmapFactory.Options.
private Bitmap getBitmap(InputStream InpStream){
Bitmap originalBitmap = BitmapFactory.decodeStream(InpStream);//Null.
return originalBitmap;
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是有另一种方法从输入流获取图像的大小和宽度?我真的需要帮助,非常感谢任何帮助.
ZipInputStream zip = null;
zip = new ZipInputStream(new FileInputStream(getFileLocation()));
for(ZipEntry zip_e = zip.getNextEntry(); zip_e != null …Run Code Online (Sandbox Code Playgroud) 我正在使用inBitmap在android3 +上加载位图.但我总是得到java.lang.IllegalArgumentException: Problem decoding into existing bitmap.
在LruCache的entryMoved()功能中:我reusableBitmaps.add(new SoftReference<Bitmap>(oldValue.getBitmap()));用来保持位图.
并且下次加载位图:我在reusableBitmaps上使用iterator找到我可以用于inBitmap的那个,我使用iterator找到哪一个,就像在官方开发者网站上管理内存一样.
但不幸的是,总是失败,logcat显示 java.lang.IllegalArgumentException: Problem decoding into existing bitmap.
任何人都可以给我一个示例或教程?
有人解释在Android中配置位图的情况下设置inDither = true时真正发生了什么吗?
在Developer.Android中,可以读到静态变量
Config.RGB_565
Run Code Online (Sandbox Code Playgroud)
此配置可能会产生轻微的视觉瑕疵,具体取决于源的配置.例如,没有抖动,结果可能会显示绿色.为了获得更好的结果,应该应用抖动
我有这个问题,直到我遵循这个建议,即:
options.inPreferredConfig = Config.RGB_565;
options.inDither = true;
Run Code Online (Sandbox Code Playgroud)
所以我的问题是:如何在Android中理解这一点.知道何时使用语法是另一回事......另一个是完全理解它.
提前致谢!
我的目录中有一个120x120px的图像/res/drawable/.这是所有设备所需的大小.
要加载此Bitmap,我使用以下内容:
Bitmap tmpBmp = BitmapFactory.decodeResource(getResources(), R.drawable.myimage);
Run Code Online (Sandbox Code Playgroud)
问题是,当我测量时tmpBmp,大小是360x360px.我知道如何将其缩小到我需要的120x120,但这是浪费处理时间,尽管很少.
我假设这与屏幕密度有关,因为我的资源位于无密度目录中.
decodeResource缩放图像的原因是什么?我怎么阻止它这样做?
我正在尝试将图像对象转换为位图,但它返回 null。
image = reader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
Bitmap myBitmap = BitmapFactory.decodeByteArray(bytes,0,bytes.length,null);
Run Code Online (Sandbox Code Playgroud)
图像本身是jpeg图像,我可以将其保存到磁盘中,我想转换为位图的原因是因为我想在将其保存到磁盘之前进行最终旋转。挖掘类 BitmapFactory 我看到这一行。
bm = nativeDecodeByteArray(data, offset, length, opts);
Run Code Online (Sandbox Code Playgroud)
此行返回空值。使用调试器进一步挖掘
private static native Bitmap nativeDecodeByteArray(byte[] data, int offset,
int length, Options opts);
Run Code Online (Sandbox Code Playgroud)
这假设返回 Bitmap 对象,但它返回 null。
任何技巧..或想法?
谢谢
每次它都会给我“无法解码流 java.io.FileNotFoundException: /: open Faild EISDIR (Is a Directory)”
我如何才能摆脱这个错误..这个类在我完成的许多任务中运行良好!
这是我用来获取位图的类
private class ImageLoaderTask extends AsyncTask<HashMap<String, Object>, Void, HashMap<String, Object>>{
@Override
protected HashMap<String, Object> doInBackground(HashMap<String, Object>... hm) {
InputStream iStream=null;
String imgUrl = (String) hm[0].get("image");
int position = (Integer) hm[0].get("position");
URL url;
try {
url = new URL(imgUrl);
// Creating an http connection to communicate with url
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
// Connecting to url
urlConnection.connect();
// Reading data from url
iStream = urlConnection.getInputStream();
// Getting Caching directory
File …Run Code Online (Sandbox Code Playgroud) decodeFile当参数指向资产文件夹内的文件时,我不知道为什么不起作用。
// Load images from the file path
String[] dir = null;
try {
dir = GenericMainContext.sharedContext.getAssets().list("drawable");
// dir Log => [ic.png, ic_info_dark.png, ic_launcher_default.png]
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (String uri : dir){
// do your stuff here
if (uri!=null) {
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeFile("file:///android_asset/drawable/"+uri); } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
有什么解释吗?
我正在尝试使用 ARCore 从 ARSession 的当前帧获取位图。但它始终等于 null。我已经在网上搜索了一段时间,但无法弄清楚我做错了什么。
try {
capturedImage = mFrame.acquireCameraImage();
ByteBuffer buffer = capturedImage.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length,null);
if (bitmap == null)
Log.e(TAG,"Bitmap was NOT initialized!");
} catch(Exception e){
}
Run Code Online (Sandbox Code Playgroud)
我正在mFrame从onDrawFrame我GLSurfaceView用来显示相机图像的地方获取信息。一切工作正常,除了我的位图等于空。
我使用的是按钮,因此只使用了一个框架,如下所示:
scanButton = (Button) findViewById(R.id.scanButton);
scanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
checkbox = false;
if (capturedImage!=null) capturedImage.close();
BitmapMethod();
}
});
Run Code Online (Sandbox Code Playgroud)
capturedImage,buffer并且bytes全部不等于 null。
可能有什么问题吗mFrame.acquireCameraImage()?
多谢
bitmapfactory ×10
android ×9
bitmap ×5
arcore ×1
c++ ×1
drawable ×1
inputstream ×1
java ×1
msdn ×1