• Bitmap之getPixel和setPixel函数


    package com.loaderman.customviewdemo;
    
    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Bitmap srcBmp = BitmapFactory.decodeResource(getResources(), R.drawable.dog);
            ImageView iv1 = (ImageView) findViewById(R.id.img1);
            iv1.setImageBitmap(srcBmp);
    
            Bitmap desBmp = srcBmp.copy(Bitmap.Config.ARGB_8888, true);
            for (int h = 0; h < srcBmp.getHeight(); h++) {
                for (int w = 0; w < srcBmp.getWidth(); w++) {
                    int originColor = srcBmp.getPixel(w, h);
    
    
                    int red = (Color.red(originColor));
                    int alpha = Color.alpha(originColor);
                    int green = Color.green(originColor);
                    int blue = Color.blue(originColor);
    
                    if (green < 200) {
                        green += 30;
                    }
    
                    desBmp.setPixel(w, h, Color.argb(alpha, red, green, blue));
    
                }
            }
    
            ImageView iv2 = (ImageView) findViewById(R.id.img2);
            iv2.setImageBitmap(desBmp);
        }
    
    
    
    
    }

    效果:

  • 相关阅读:
    React + Webpack搭建环境
    iOS 中block中使用了外部变量的分析
    研究Extension和Category的一个例子
    43. Multiply Strings
    安装cocoapods
    iOS推送流程
    iOS中富文本NSMutableAttributedString的用法
    用杯赛尔曲线(做动画和绘图)
    字符串转换为长整型 strtol
    使用DirectUI
  • 原文地址:https://www.cnblogs.com/loaderman/p/10231726.html
Copyright © 2020-2023  润新知