I have text file that has got datas in "%02x " format. For example my text's content like "AA 00 11 CC...". I want to have bitmap from this text file.
I have tried many solutions about this. Firstly I have converted this datas to byte array like that;
Inputstream is = getResources().openRawResource(R.raw.ep2data);
InputStreamReader inputStreamReader = new InputStreamReader(is);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line;
StringBuilder text = new StringBuilder();
try {
while ((line = bufferedReader.readLine()) != null) {
text.append(line);
text.append('\n');
}
} catch (IOException e) {
e.printStackTrace();
}
String s = text.toString();
//convert string to byte array
String[] tokens = s.split(" ");
Log.d("string array length", "" +tokens.length);
byte[] data = new byte[tokens.length];
for (int i = 0; i < tokens.length - 1; i++) {
data[i] = (byte) ((Character.digit(tokens[i].charAt(0), 16) << 4)
+ Character.digit(tokens[i].charAt(1), 16));
}
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options);
As a result, I'm getting bitmap as null. So I can not create bitmap from this text. How can I create bitmap from text string. I have tried many solution but I couldn't get solution about this subject.