Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.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
Java 无法在服务器上查看上载的映像_Java_Android - Fatal编程技术网

Java 无法在服务器上查看上载的映像

Java 无法在服务器上查看上载的映像,java,android,Java,Android,当我尝试在服务器上上载图像时,我的设备上会显示“图像上载成功”,但我无法在服务器上看到图像。 我甚至试图通过将图像转换成Base64来上传它 这是我的密码 try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); httppost.setEntity

当我尝试在服务器上上载图像时,我的设备上会显示“图像上载成功”,但我无法在服务器上看到图像。
我甚至试图通过将图像转换成Base64来上传它

这是我的密码

            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(url);
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                String responseStr = EntityUtils.toString(response.getEntity());
                Log.i(TAG, "doFileUpload Response : " + responseStr);
                handler.sendEmptyMessage(1);
            } catch (Exception e) {
                System.out.println("Error in http connection " + e.toString());
                handler.sendEmptyMessage(0);
            }
        }
    });
    t.start();

}

public String convertBitmapToString(Bitmap bmp){
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.JPEG, 90, stream); //compress to which format you want.
    byte[] byte_arr = stream.toByteArray();
    String imageStr = Base64.encodeToString(byte_arr, Base64.DEFAULT);
    return imageStr;
}
但在运行时,它显示了一个错误:

E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f9e668360
请尝试此代码将图像上载到服务器。。。。! 我希望这对你有帮助

尝试使用下面的代码从URL加载图像

String url = myUrls.get(position);

  GlideApp
    .with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .into(myImageView);

您正在将图像从服务器上载到手机或从手机上载到服务器?为什么您要将图像作为
字符串而不是
字节[]
?感谢您的回复。我正在将图像从手机上载到服务器。。。。Orkun Koçyiğit你能告诉我密码吗……提前谢谢。Sammiljani这个问题是为了将图像上传到服务器,而不是为了在应用程序中显示图像。这个答案不正确。@DrumilJani请先仔细阅读这个问题。。。“无法查看…”如问题“我无法看到服务器上的图像”中所述。
String url = myUrls.get(position);

  GlideApp
    .with(myFragment)
    .load(url)
    .centerCrop()
    .placeholder(R.drawable.loading_spinner)
    .into(myImageView);