Last active
August 18, 2021 05:17
-
-
Save spiritedRunning/05d84025fab8de8ff9cde78ae28d99bd to your computer and use it in GitHub Desktop.
色值映射
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bitmap image = Bitmap.createBitmap(32, 32, Bitmap.Config.ARGB_8888); | |
int[] list = GetSingleColorList(Color.rgb(0, 0, 255), Color.rgb(255, 0, 0), (int) (maxtemp - mintemp) + 1); | |
//根据温度获取每个点的颜色 | |
for (int i = 0; i < data.length; i++) { | |
int c = GetColor(list, data[i], maxtemp, mintemp); | |
image.setPixel(i % 32, i / 32, c); | |
} | |
BitmapUtil.saveBitmap(this, "tmp.jpg", image); | |
// HTPA32x32 dR2L2_1 / HTPA32x32 dR2L5_0 IR_CAMERA 模块温度转换 | |
private double[] processTemperatureArray(byte[] recByteArray) { | |
double[] recTempArray = new double[1024]; | |
if (recByteArray != null && recByteArray.length >= 2055 && recByteArray[0] == (byte) 0xE1) { | |
for (int i = 0; i < 1024; i++) { | |
int temp = (recByteArray[i * 2 + 1] << 8) + (recByteArray[i * 2 + 2] & 0xFF); | |
recTempArray[i] = (temp - 2731) / 10f; | |
} | |
} | |
return recTempArray; | |
} | |
public int[] GetSingleColorList(int srcColor, int desColor, int count) { | |
int[] colorFactorList = new int[count]; | |
int redSpan = Color.red(desColor) - Color.red(srcColor); | |
int greenSpan = Color.green(desColor) - Color.green(srcColor); | |
int blueSpan = Color.blue(desColor) - Color.blue(srcColor); | |
for (int i = 0; i < count; i++) { | |
int color = Color.rgb(Color.red(srcColor) + (int) ((double) i / count * redSpan), | |
Color.green(srcColor) + (int) ((double) i / count * greenSpan), Color.blue(srcColor) + (int) ((double) i / count * blueSpan)); | |
colorFactorList[i] = color; | |
} | |
return colorFactorList; | |
} | |
public int GetColor(int[] list, double val, double max, double min) { | |
return list[(int) (val - min)]; | |
} |
Author
spiritedRunning
commented
Aug 18, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment