English 中文(简体)
用甲型六氯环己烷频道绘制图: 页: 1 (一些解决办法和速度问题)
原标题:Drawing bitmaps with alpha channel: please advise... (some solutions and speed issues)

我有相当数量的小幅标尺(100+,大小约40x40),每个图都有一些不透明之处,需要加以描述。

相应图以ARGB格式,888(rgb)加上256个轨道字母频道,如PNG格式。

唯一(工作)的方法是:

  1. create a bitmap (ARGB_8888)
  2. fill the bitmap with the raw data
  3. extract the alpha layer from the bitmap
  4. create a BitmapShader (RGB_565) based on the original bitmap
  5. 绘制利用所创造的梯子的地图

  6. 然后用“BitmapShader”号特称画面。

初始化法的实施当然只有一次:

void initializeTile( int t ){
// Allocate the bitmap:
Bitmap original_data = Bitmap.createBitmap( tile_w, tile_h, Bitmap.Config.ARGB_8888);
// Fill with raw data (this is actually native C++ code):
populateBitmap( original_data );
// Get the alpha mask:
tile_mask[ t ] = original_data.extractAlpha();
// Create the bitmap shader:
tile_data = original_data.copy( Bitmap.Config.RGB_565, false);
// Create the shader:
BitmapShader shader = new BitmapShader(tile_data, CLAMP, CLAMP);

// Create the paint:
tile_paint[ t ] = new Paint();
tile_paint[ t ].setDither(true);
tile_paint[ t ].setAntiAlias(true);
tile_paint[ t ].setFilterBitmap(true);
tile_paint[ t ].setShader( shader );
}

油漆法是最简单的,它主要指向:

void paintTile(t){
canvas.drawBitmap( tile_mask[ t ],  tile_x[ t], tile_y[ t], tile_paint[ t] );
}

现在,在像Ideos(Android 2.2)这样的电话中,它运行顺利、优质,但在像上台的三星银河SII(Android 2.3)这样的其他电话中,它令人不安和缓慢。 这对我来说没有意义。

因此,你认为这种做法是什么? 是否有更好、更快的方式实现同样的结果?

而且,为什么你们认为它如此缓慢地掌握现代、快速的硬件? 是否有任何改进方法?

最佳回答

Ok,经过一些工作,找到了更好的解决办法。 我无法回答我自己的问题,如果你们比我多知道,请回答。

但是,如果有更多的人需要,那么我的新解决办法就更迅速了,尽管更为复杂。 关键的想法是,在初创阶段,而不是在绘画上,使用光彩法。

为了做到这一点,我制作一个新的轨道图,其中将包含使用沙分法(所有已清除的透明区域)的“被拖延”的比照图,然后画出该比照图,而代法中则没有出现任何线索。

void initializeTile( int t ){
// Allocate the bitmap:
Bitmap original_data = Bitmap.createBitmap( tile_w, tile_h, Bitmap.Config.ARGB_8888);
// Fill with raw data (this is actually native C++ code):
populateBitmap( original_data );

// Now make a new bitmap to be clipped:
Bitmap clipped_data = Bitmap.createBitmap( tile_w, tile_h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(clipped_data);
Paint clip_paint = new Paint();
clip_paint.setDither(true);
clip_paint.setAntiAlias(true);
clip_paint.setFilterBitmap(true);
clip_paint.setShader( new BitmapShader(original_data, CLAMP, CLAMP));
// Paint the clipped bitmap:
canvas.drawBitmap( tile_mask[ t ], 0, 0, clip_paint );
//Use the clipped bitmap as original bitmap:
tile_data[ t ] = clipped_data;
}

并拟订法典:

void paintTile(t){
canvas.drawBitmap( tile_data[ t ],  tile_x[ t], tile_y[ t], null );
}

Overall, this is much faster. Still it s unclear to me WHY Android would not paint my alpha-channelled bitmaps properly without all this mess!

问题回答

暂无回答




相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签