I am making a custom camera that takes pictures of documents and sends them over the network. The images are then OCRed. For sending them over the network they must be of small size ( less than 100 Kb). I first scale down the image then convert to gray scale and compress to JPG with 100 percent. Still the image size is more that 100Kb. If I reduce the JPG compression percent the quality is really bad. How to solve this issue. Here is the code:
//Image Scaling
public static Bitmap decodeSampledBitmapFromResource(byte[] data,
int reqWidth, int reqHeight) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeByteArray(data, 0, data.length, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
return BitmapFactory.decodeByteArray(data, 0, data.length, options);
}
//Image grayscale. Using renderscript
uchar grayscale = pixelIn.r * 0.299 + pixelIn.g * 0.587 + pixelIn.b * 0.114;
uchar4 pixelOut;
pixelOut.a = pixelIn.a;
pixelOut.r = grayscale;
pixelOut.g = grayscale;
pixelOut.b = grayscale;
return pixelOut;
//JPG compression
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);