Invert bitmap colors

前端 未结 4 1273
悲&欢浪女
悲&欢浪女 2021-02-06 11:10

I have the following problem. I have a charting program, and it\'s design is black, but the charts (that I get from the server as images) are light (it actually uses only 5 colo

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 11:50

    Manipulating a bitmap is much faster if you copy the image data into an int array by calling getPixels only once, and don't call any function inside the loop. Just manipulate the array, then call setPixels at the end.

    Something like that:

    int length = bitmap.getWidth()*bitmap.getHeight();
    int[] array = new int[length];
    bitmap.getPixels(array,0,bitmap.getWidth(),0,0,bitmap.getWidth(),bitmap.getHeight());
    for (int i=0;i

提交回复
热议问题