So I am new to java and am using someone's open source code for android development. I want to use the variable color in this program in another activity. I tried changing void to int and then returning color at the end of the code but that does not make a difference and the code does not work. I am confused why as void doesn't return anything but an int returns an integer. My question is how can I get the value of the variable color from this code and either store it in another variable or make the variable color itself so that I can use it in other activities of my android app. Here is my code:
public void onPreviewFrame(byte[] data, Camera camera) {
try {
Camera.Size previewSize = camera.getParameters().getPreviewSize();
int height = previewSize.height;
int width = previewSize.width;
ColorModelConverter converter = new ColorModelConverter(height, width);
int[] pixels = converter.convert(data, this.colorFormat);
int color = pickColor(pixels, height, width);
updateColorData(color);
Log.i("FRAME PREVIEW", "Color updated");
} catch (RuntimeException oops) {
// Do nothing, exception is thrown because onPreviewFrame is called after camera is released
Log.i("FRAME PREVIEW", "RuntimeException thrown into onPreviewFrame");
}
}
Also here is the github link to the full project if that makes a difference: https://github.com/adlebzelaznog/colometer