Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Don';I don’我不知道我收到的bytearray是否可以被BitmapFactory理解_Android_Bitmap - Fatal编程技术网

Android Don';I don’我不知道我收到的bytearray是否可以被BitmapFactory理解

Android Don';I don’我不知道我收到的bytearray是否可以被BitmapFactory理解,android,bitmap,Android,Bitmap,我有一个应用程序,在其中我必须接收一个字节数组形式的图像。该映像以前已通过以下方式发送到服务器: image = image.createScaledBitmap((Bitmap) extras.get("data"), 380, 400, true); ByteArrayOutputStream stream = new ByteArrayOutputStream(); imagen.compress(Bitmap.CompressForm

我有一个应用程序,在其中我必须接收一个字节数组形式的图像。该映像以前已通过以下方式发送到服务器:

 image = image.createScaledBitmap((Bitmap) extras.get("data"), 380, 400, true);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        imagen.compress(Bitmap.CompressFormat.PNG, 100, stream);
        byte[] byteArray = stream.toByteArray();
图像被正常发送到服务器。应用程序的另一部分调用服务器以获取包含图像的JSON。我将其存储在字符串中,然后使用
String.getBytes()
获取字节数组,类似于:

byte[] array=stringimage.getbytes();
该数组类似于:119,80,78,71,13,10

我现在想“好的,我现在使用BitmapFactory,decodeByteArray并获取我的位图”,但它返回null。我开始用谷歌搜索并查看Stack Overflow,我看到了解决这个问题的各种方法。其中之一:

image = Bitmap.createBitmap(380, 400, Bitmap.Config.RGB_565);
int row = 0, col = 0;
for (int i = 0; i < array.length; i += 3) {
    image.setPixel(col++, row, array[i + 2] & array[i + 1] & array[i]);
    
    if (col == 380) {
        col = 0;
        row++;
        
    }
}
它不起作用

我的问题是:我必须如何要求负责服务器端的伙伴向我发送阵列?哪种格式?他没有以任何方式接触我之前发给他的图像。他需要做什么


或者,我必须如何管理字节数组?我是否不需要“翻译”成decodeByteArray可以理解的另一种格式?

您面临的问题是编码/解码。从图像接收的字节数组是二进制的,不能解释为文本。为了通过基于文本的协议传输它(我假设您会使用HTTP),您必须将其编码为文本格式。从服务器接收对称操作时,需要执行对称操作

当您将其发送到服务器时,以一种格式(比如Base64)进行编码,并使用相同的格式对接收到的字符串进行解码

byte[] array=Base64.decode(fotostring.getBytes(),Base64.DEFAULT);