如何发送图像中的ImageView的一个PHP服务器? [英] how to send the image in an ImageView to a php server?
问题描述
有一次,我在ImageView的有一个形象,我怎样才能将图像发送到Web服务器的最简单的方法可能吗?
once i have an image in an ImageView, how can i send the image to a web server in the simplest way possible??
我用这让从画廊的图片:
I got the image from the gallery using this :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK)
try {
// We need to recyle unused bitmaps
if (bitmap != null) {
bitmap.recycle();
}
InputStream stream = getContentResolver().openInputStream(
data.getData());
bitmap = BitmapFactory.decodeStream(stream);
stream.close();
imageView.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
super.onActivityResult(requestCode, resultCode, data);
}
和我有图像设置为我的ImageView。我这样做是为了显示图像的preVIEW给上传者。现在怎么上传图片到Web服务器(可能是最好的ñ最简单的方法)三江源
and i have set that image to my imageView. I am doing this to show a preview of the image to the uploading person. now how to upload that image to a web server (best n easiest way possible) thankyou
推荐答案
我没有用PHP做到了这一点,但使用.NET期运用的base64字符串发送的图像。
i haven't done this with PHP but sent the image with .NET useing base64 string.
图像转换成你的base64和你的服务器上发送此字符串。您的服务器将在此的base64转换为原始图像
convert you image into base64 and send this string on your server. your server will convert this base64 to original image
到图像转换成字节[]尝试以下code
to convert image into byte[] try following code
private void setPhoto(Bitmap bitmapm) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmapm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] byteArrayImage = baos.toByteArray();
String imagebase64string = Base64.encodeToString(byteArrayImage,Base64.DEFAULT);
} catch (Exception e) {
e.printStackTrace();
}
}
这篇关于如何发送图像中的ImageView的一个PHP服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!