Skip to content

Instantly share code, notes, and snippets.

@spiritedRunning
Last active August 18, 2021 05:17
Show Gist options
  • Save spiritedRunning/05d84025fab8de8ff9cde78ae28d99bd to your computer and use it in GitHub Desktop.
Save spiritedRunning/05d84025fab8de8ff9cde78ae28d99bd to your computer and use it in GitHub Desktop.
色值映射
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)];
}
@spiritedRunning
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment