I drive an array of int values ​​into a file, which is a photo with the extension * .jpg

File newFile = aFile; FileOutputStream file = new FileOutputStream(newFile); for (int i = 0; i < icon.length; i++) { file.write(icon[i]); // icon[i]- int value } file.close(); 

The problem is that the OS android does not define the created file as a picture and gives it an empty icon (as for an undefined file), while for other files (jpg, png, etc.), a thumbnail of the picture itself is given instead of the icon. Also, this file does not open in the gallery - a standard application on the tablet. At the same time, if you select 'open file as image' in the menu item, it opens in the standard viewing window, the file also opens in a third-party image viewing program.

I can not figure out what I forgot to specify when saving to a file.

  • and why an array of int? Expand jpg is not necessarily a multiple of 4, but you can’t handle the ending. I would store in the byte array. In any case, you can post a picture saved in such a way somewhere, so that it can be viewed from the inside. - KoVadim
  • OutputStream.write(int) writes only the lower 8 bits (1 byte) of the argument to the file, perhaps this is the problem. Try wrapping the file into a DataOutputStream and calling writeInt . This may also not solve the problem, because there may be a wrong writing order (writeInt writes high bytes ahead). How do you get the array to write? - zRrr
  • 1.link to the test file: cloud.mail.ru/public/MXps/uMubXUkYX - Alexey
  • 2-I would also store byte, but the web service is written in C # and returns data in the form "[255.0, 216.0, 255.0, ......., 217.0]"; 3-DataOutputStream - I will try to pick it up if it works out. - Alexey
  • DataOutputStream - the file size has increased 4 times + now the file does not open at all. - Alexey

0