0

bytearray に格納された 3 バイトを取得しました。これは ARGB にデコードされます。bytearray を int ARGB にデコードするためのコードがあるため、問題はありません。問題は、int ARGB を 3 サイズの bytearray に (RGB 値を格納するだけでなく、同じエンコード方法で) 再エンコードする方法です。私はこのために2週間働いてきましたが、本当に助けが必要だと思います.

byte[] encodedBytes = new byte[]{(byte)0x4D, (byte)0x86, (byte)0x18};
int argb = decode(encodedBytes); // 0x4D616161 // 1298227553

// byte[] encodedBytes2 = new byte[]{(byte)0x6F, (byte)0x30, (byte)0x65};
// int argb = decode(encodedBytes2); // 0x6DCF0C14 // 1842285588

この関数を使用して ARGB にデコードされます。

public static int decode(byte[] bytes)
{
     // alpha
     // bytes[0] = (byte) 0x4D; // 77
     int temp = bytes[0] & 0xFC;
     int alpha = temp | temp >> 6;
     // re-encode with alpha ^ alpha >> 6;

     // red
     // bytes[1] = (byte) 0x86; // -122
     temp = (bytes[0] << 6) & 0xF0;
     int red = temp | 0x3C & (bytes[1] >> 2);
     red = red | red >> 6;
     // re-encode with ?

     // green
     // bytes[2] = (byte) 0x18; // 24
     temp = 0xF0 & bytes[1] << 4;
     int green = temp | 0xC & bytes[2] >> 4;
     green = green | green >> 6;
     // re-encode with ?

     // blue
     // blue and green uses same byte,
     // bytes[2] but will not result in same color
     temp = (0x3F & bytes[2]) << 2;
     int blue = temp | temp >> 6;
     // re-encode with ?

     // Result:
     // alpha = 77
     // red = 97
     // green = 97
     // blue = 97
     // argb = 0x4D616161 // 1298227553
     int argb = (alpha << 24 ) + (red << 16) + (green << 8) + blue;
     return argb;
}

これは、int ARGB を bytearray にエンコードするための未完成のコードです。

public static byte[] encode(int argb)
{
     byte[] bytes = new byte[3];

     int alpha = (argb >> 24) & 0xFF;
     int red = (argb >> 16) & 0xFF;
     int green = (argb >> 8) & 0xFF;
     int blue = argb & 0xFF;

     bytes[0] = alpha ^ alpha >> 6;
     // results to 76 instead of 77

     red = red & red >> 6;
     int temp = (bytes[0] << 6) & 0xF0;
     bytes[1] = (temp ^ red) << 2;

     // ... missing code goes here

     return bytes;
}

byte[]{0,0,0} から byte[]{(byte)0xFF,(byte)0xFF,(byte)0xFF} までのテーブルを作成してARGBを比較しようと思ったのですが、もったいないと思います。繰り返しますが、質問を繰り返しますが、int ARGB を 3 サイズの bytearray に (RGB 値を格納するだけでなく、同じエンコード方法で) 再エンコードするにはどうすればよいですか? どんな助けでも大歓迎です。ありがとうございました。

4

1 に答える 1

0
alpha = (argb >> 24) & 0xfc;
red = (argb >> 16) & 0xfc;
green = (argb >> 8) & 0xfc;
blue = argb & 0xfc;
bytes[0] = alpha | (red >> 6);
bytes[1] = (red << 2) | (green >> 4);
bytes[2] = (green << 4) | (blue >> 2);
于 2014-06-18T06:29:41.037 に答える