【问题标题】:Set Pixel of Bitmap caught by intent picker设置意图选择器捕获的位图像素
【发布时间】:2018-09-21 17:44:48
【问题描述】:

当我尝试设置 由 photopicker 意图加载的位图 的像素时,我的小应用程序导致崩溃,我不知道为什么。我的意图是this code

所以这是我当前代码的重要部分:

public class MainActivity extends AppCompatActivity {

  private Bitmap selectedImage;

  ...

  private void changebitmap() {

        ImageView imageView = findViewById(R.id.imageView);

        for(int x = 0; x < selectedImage.getWidth(); x++) {
            for(int y = 0; y < selectedImage.getHeight(); y++) {
                selectedImage.setPixel(x, y, Color.argb(255, 128, 128 ,128));
            }
        }

        imageView.setImageBitmap(selectedImage);

  }
}

我不知道为什么它不起作用。

问候

【问题讨论】:

    标签: android bitmap pixel editing


    【解决方案1】:

    好的,我自己弄的。

    问题是意图中的位图没有正确的配置。

    在 API 级别 19 上,它说您可以设置它

    selectedImage.setConfig(Bitmap.Config.ARGB_4444);
    

    在较低级别(如我),您可以将其以像素方式复制到具有正确配置的另一个位图。

    selectedImage = Bitmap.createBitmap(copy.getWidth(), copy.getHeight(), Bitmap.Config.ARGB_4444);
    
    for(int x=0; x < copy.getWidth(); x++) {
      for(int y=0; y < copy.getHeight(); y++) {
    
        selectedImage.setPixel(x, y, copy.getPixel(x, y));
    
      }
    }
    

    问候

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多