English 中文(简体)
Android 图像代表
原标题:Android Image Representation

I m trying to access the raw pixel data of an image in Android.
The code looks something like this:

   Bitmap bitmap =  BitmapFactory.decodeFile("image.png"); 
   // assert valid input
   if ((bitmap.getConfig() == null) || bitmap.getConfig() == Config.ARGB_8888)
      throw new Exception("bad config");

  ByteBuffer buffer = ByteBuffer.allocate(4 * bitmap.getWidth() * bitmap.getHeight());
  bitmap.copyPixelsToBuffer(buffer);        
  return buffer.array();

如何储存1D条线的颜料?

  1. First element is top-left pixel or bottom-left pixel (or something else)?
  2. Row-major (row after row) or column-major (column after column)?
  3. Channel order ARGB or BGRA?
  4. Row-major or column-major for each channel separately?
  5. Something else
最佳回答

具体pixel x,y<> 采用这一公式:

offsetForPixel = (y * width + x) * bytesPerPixel

换言之,阵列中的第一个要素是头盔,以下要素是row。 p的所有数据都储存在邻近的tes中,没有根据渠道传播。 这是对上述1、2和4的答复。 现在让我讨论第3条,这就是事情变得复杂的地方。

What you get with Bitmap.copyPixelsToBuffer() is the raw bitmap data representation used by Android s low-level drawing library skia. This has three significant consequences:

  • The channel order depends on endianness
  • The channels are premultiplied with alpha
  • How channels are packed into containing data types is configurable

最后一点是,使用<条码>得 a。 比图.copyPixels ToBuffer()完全是如果你想要检查个别的餐厅,因为你可以知道如何将天空配置到包装渠道。 作为试验,尝试这一法典:

int inputPixel = 0x336699cc;
int[] pixels = new int[] { inputPixel };
Bitmap bm = Bitmap.createBitmap(pixels, 1, 1, Config.ARGB_8888);
ByteBuffer bb = ByteBuffer.allocate(4);
bm.copyPixelsToBuffer(bb);
Log.i("TAG", "inputPixel = 0x" + Integer.toHexString(inputPixel));
for (int i = 0; i < 4; i++) {
    String byteString = "0x" + Integer.toHexString(bb.array()[i] & 0xff);
    Log.i("TAG", "outputPixel byte " + i + " = " + byteString);
}

在我执政时,我取得了这一成果:

I/TAG ( 1995): inputPixel = 0x336699cc
I/TAG ( 1995): outputPixel byte 0 = 0x14
I/TAG ( 1995): outputPixel byte 1 = 0x1f
I/TAG ( 1995): outputPixel byte 2 = 0x29
I/TAG ( 1995): outputPixel byte 3 = 0x33

我们可以看到,我们正与大端人打交道,中间派代表先是多面派代表,而且各种渠道已经从大不列颠及北爱尔兰联合党重新安排到欧洲复兴开发银行(根据斯基纳源法,这一代言与开放式代表相同)。

如果你读到六分的数据,我建议你使用

问题回答

暂无回答




相关问题
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 ...

热门标签