English 中文(简体)
Android:在将可图象转换成星阵列时存在一些问题
原标题:Android : some problems when converting drawable image to byte array

我想将我的照片转换成一个被编码的“基地64”。 这种形象可能属于诸如jpeg、png等任何类型。

我所做的是,我把这份可以编成比图。 然后,我将这一比图改为拜特阿雷奥特普特帕特帕特特帕特帕特帕特帕特帕特帕特帕特帕特帕特帕特帕特帕特帕特帕塔姆,使用压缩肉,我正在将拜特阿雷拉奥特帕特帕特帕特帕特帕特帕特帕特帕施特帕塔姆改成特阵列。 然后,我用编码编码编码编码编码将其编码到第64号基地。

如果PNG或JPEG的形象是这样,我就能够使用上述方法展示形象。

ByteArrayOutputStream objByteOutput = new ByteArrayOutputStream();
 imgBitmap.compress(CompressFormat.JPEG, 0, objByteOutput);

但是,问题是,如果图象在除PNG或JPEG以外的任何其他类型,我如何展示形象?

或请建议我采取另一种方法,从比特图获得异构体。

感谢......

问题回答

I d

http://developer.android.com/reference/android/graphics/Bitmap.html#copyPixelsToBuffer(java.nio.Buffer)

并且具体指明了一名Buffer,然后,如果实施(一种任择方法)或(如果存在的话)在BoutteBuffer使用.array()。

最新情况:

为了确定缓冲的规模,创造你们,应该使用比特图。 然而,这只出现在第12号表格中,因此,你需要使用比特图。

You can get the same with Bitmap.getHeight() * Bitmap.getRowBytes() - here s some code I used to verify this worked:

            BitmapDrawable bmd = (BitmapDrawable) getResources().getDrawable(R.drawable.icon);
            Bitmap bm = bmd.getBitmap();
            ByteBuffer byteBuff = ByteBuffer.allocate(bm.getWidth() * bm.getHeight() * 4);
            byteBuff.rewind();
            bm.copyPixelsToBuffer(byteBuff);
            byte[] tmp = new byte[bm.getWidth() * bm.getHeight() * 4];
            byteBuff.rewind();
            byteBuff.get(tmp);

It s not nice code, but it gets the byte array out.





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签