需要将选定的图像从SD卡发送到ASP.net Web服务器 [英] Need to send the selected image from SDcard to an ASP.net web server
问题描述
我需要将所选图像发送到Web服务器。从SD卡中选择图像的代码如下所示。我在谷歌搜索了很多次。但仍然没有找到适合我的问题的解决方案。任何人都可以建议我如何将选定的图像发送到Web服务器。 Web服务器是ASP.net Web服务器。我发现很多代码将数据发送到互联网上的php web服务器,但没有找到发送到ASP.net Web服务器的代码。请帮帮我。我是android的新手。所以我不知道通过网络服务器发送图像/视频数据的步骤。
//我添加了一个按钮来选择图像
按钮imgbrowse =(按钮)findViewById(R.id.imgbrowse);
imgbrowse.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v){
// TODO自动生成的方法stub
Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i,RESULT_LOAD_IMAGE);
}
});
@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data){
// TODO自动生成的方法stub
super.onActivityResult(requestCode, resultCode,data);
if(requestCode == RESULT_LOAD_IMAGE&& resultCode == RESULT_OK&& null!= data){
Uri selectedImage = data.getData();
String [] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver()。query(selectedImage,
filePathColumn,null,null,null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn [0]);
//图像所在的路径存储在字符串变量
String picturePath = cursor.getString(columnIndex);
cursor.close();
//在图像视图中显示所选图像。
ImageView imageView =(ImageView)findViewById(R.id.imageView1);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
//显示所选图像的路径
TextView tv =(TextView)findViewById(R.id.textView5);
tv.setText(picturePath);
}
}
您可以使用HTTP客户端将图像发送到服务器
I need to send the selected image to a web server. The code for selecting the image from the sdcard is shown below. I have searched many times in google. But still not finding a proper solution to my problem. Can anyone please suggest me how to send the selected image to a web server. The web server is a ASP.net web server. I have found many code to send data to php web server on the internet, but didn't find a code to send to an ASP.net web server. Please help me out. I'm new to android. So I didn't know the steps of sending image/ video data through a web server.
// I have added a button to select the image Button imgbrowse=(Button)findViewById(R.id.imgbrowse); imgbrowse.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent i = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, RESULT_LOAD_IMAGE); } }); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); //the path where the image is located is stored in string variable String picturePath = cursor.getString(columnIndex); cursor.close(); //Displaying the selected image in the image view. ImageView imageView = (ImageView) findViewById(R.id.imageView1); imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); //Displaying the path of the selected image TextView tv=(TextView)findViewById(R.id.textView5); tv.setText(picturePath); } }
You can use HTTP client to send image to server
这篇关于需要将选定的图像从SD卡发送到ASP.net Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!