I am interested in saving the image in JPEG format so that I can specify the total number of bits used to encode all the pixels in a compressed form. For example, if I have a 4-channel image with a size of 1024 x 1024, encoding bits without compression will take 4 * 8 * 1024 * 1024 bits. Using compression, a significantly smaller number of bits can be used. I want to specify the number of bits in compressed form.
An iterative solution would be a binary search by JPEG compression quality parameter. I hope for a direct solution in Java or Scala.
source
share