In my app I am capturing images and on button press just apply some filter (function). SOLVED:
So the problem is when I convert bitmap to byteArray I will get RGBA byte format, so access to the RED is every first position of 4th byte. Thats simple, but what I dont understand is: why black is 0 not -128 and white is -1 not 127 //4 bytes: R G B A //4 bytes: 0 1 2 3 //byte => -128 to 127 //black -> grey -> greyer -> white // 0 -> 127 -> -128 -> -1
SO any ideas how to get number from 0 to 255 or -128 to 127? equils to black to white transition.
WAS SOLVED by adding value=value & 0xFF
this.actualPosition = 1; //Green
    for(int j=0; j < bmpHeight ; j++) {
        for(int i=0 ; i < bmpBytesPerPixel/4 ;i++) {
            byte midColor =  (byte) ( (byteArray[actualPosition-1]& 0xFF) * 0.30 + (byteArray[actualPosition]& 0xFF) * 0.59 + (byteArray[actualPosition+1]& 0xFF) * 0.11 );
            byteArray[actualPosition]=midColor;
            byteArray[actualPosition+1]=midColor;
            byteArray[actualPosition+-1]=midColor;
            //byteArray[actualPosition+1]=byteArray[actualPosition];
            //byteArray[actualPosition+-1]=byteArray[actualPosition];
            actualPosition += 4;
        }
    }
Trying to make the fastest algorithm. This one is about ~2.7s when working with HD image / bitmap, so the bytearray lenght is 4 * 1080 * 720 = 3 110 400 bytes. Accesing 3/4.
there is how I am converting bitmap to byteArray and contrariwise.
private void getArrayFromBitmap() {
        // Převod Bitmap -> biteArray
        int size = this.bmpBytesPerPixel * this.bmpHeight;
        ByteBuffer byteBuffer = ByteBuffer.allocate(size);
        this.bmp.copyPixelsToBuffer(byteBuffer);
        this.byteArray = byteBuffer.array();
    }
    private void getBitmapFromArray() {
        // Převod biteArray -> bitmap
        Bitmap.Config configBmp = Bitmap.Config.valueOf(this.bmp.getConfig().name());
        this.bmp = Bitmap.createBitmap(this.bmpWidth, this.bmpHeight, configBmp);
        ByteBuffer buffer = ByteBuffer.wrap(this.byteArray);
        this.bmp.copyPixelsFromBuffer(buffer);
        System.out.println("\n DONE "+ configBmp);
    }