小编Beh*_*ehy的帖子

无法透明位图图像的像素

我正在处理位图图像,其透明部分为洋红色(在某些语言中可以将颜色设置为透明)。我尝试将原始位图图像中洋红色的像素透明。

我从 SD 卡加载位图:

            Bitmap bitmap = BitmapFactory.decodeFile(myImagePath);
Run Code Online (Sandbox Code Playgroud)

将其复制到另一个位图以使其可变:

            Bitmap bitmap2 = bitmap.copy(Bitmap.Config.ARGB_8888,true);
Run Code Online (Sandbox Code Playgroud)

然后逐像素扫描以找到洋红色像素并尝试更改其透明度。

            for(int x=0;x<bitmap2.getWidth();x++){
                for(int y=0;y<bitmap2.getHeight();y++){
                    if(bitmap2.getPixel(x, y)==Color.rgb(0xff, 0x00, 0xff))
                    {
                        int alpha = 0x00;
                        bitmap2.setPixel(x, y , Color.argb(alpha,0xff,0xff,0xff));  // changing the transparency of pixel(x,y)
                    }                           
                }
            }
Run Code Online (Sandbox Code Playgroud)

但是我希望变得透明的那些像素被转换为黑色。通过更改 alpha,我发现最终颜色从提到的颜色argb()(不提及 alpha)变为黑色。例如,Color.argb(0xff,0xff,0xff,0xff)变白、Color.argb(0x80,0xff,0xff,0xff)变灰、Color.argb(0x00,0xff,0xff,0xff)变黑。

我不明白出了什么问题。

有没有可能没有 alpha 通道,我应该首先设置/定义它?如果是,怎么办?

编辑1:

根据 Der Gol...lum 的评论我修改了我的代码:

    Paint mPaint = new Paint();
    mPaint.setAlpha(0);
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
    mPaint.setAntiAlias(true);

        Bitmap bitmap = BitmapFactory.decodeFile(myBackImagePath).copy(Bitmap.Config.ARGB_8888 , true);
        Canvas canvas = new Canvas(bitmap); …
Run Code Online (Sandbox Code Playgroud)

android bitmap alpha-transparency

5
推荐指数
1
解决办法
3900
查看次数

单击弹出菜单时,为什么导航栏出现在全屏应用程序中

我有一个全屏应用程序:

MainActivity.java:

public class MainActivity extends AppCompatActivity {

@TargetApi(Build.VERSION_CODES.KITKAT)
private void removeControlBar(){
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
@Override
public void onResume(){
    super.onResume();
    removeControlBar();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public …
Run Code Online (Sandbox Code Playgroud)

android fullscreen navigationbar android-immersive

5
推荐指数
1
解决办法
3586
查看次数

犀牛安卓版

我正在尝试在我的 android 项目中使用rhino。我黎明加载了 Rhino 并添加js.jarlib.
\n这是我的MainActivity

\n\n
public class MainActivity extends AppCompatActivity {\n\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        ...\n\n        Context rhino = Context.enter();\n//        try{                     // I commented it to catch the error\n            rhino.setLanguageVersion(Context.VERSION_1_2);\n            Scriptable scope = rhino.initStandardObjects();\n            Object result=rhino.evaluateString(scope, \n                           "obj={a:1,b:[\'x\',\'y\']}", "MySource", 1, \n                            null);       // This line cannot be compiled\n\n            Scriptable obj = (Scriptable)scope.get("obj",scope);\n            Log.i("JS","obj " + (obj == result ? "==" : "!=") +" result");\n\n            Log.i("js","obj.a == " + …
Run Code Online (Sandbox Code Playgroud)

android rhino

3
推荐指数
1
解决办法
6264
查看次数

MyLocationOverlay已被弃用,有没有其他选择?

不推荐使用MyLocationOverlay.还有其他选择吗?

MapView mapView;
MyLocationOverlay myLocationoverlay;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    myLocationoverlay = new MyLocationOverlay(this, mapView);
    ...
Run Code Online (Sandbox Code Playgroud)

android mylocationoverlay osmdroid

3
推荐指数
1
解决办法
496
查看次数