如何通过在Android中选择图片来上传SD卡中的图片
在我的应用程序中,我尝试将图像发送到存储在 SD 卡中的服务器。当我单击按钮时,它会打开 SD 卡并在网格视图中显示图像。从那里我想上传我正在接触的图像。我知道将图像上传到服务器,但我不知道从 SD 卡中选择图像,请帮助我......
以下是我的代码......
public void library()
{
Intent myIntent = new Intent();
myIntent.setType("image/*");
myIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(myIntent,"Select Picture"), 101);
}
public void onActivityResult(int requestCode, int resultCode, Intent myIntent)
{
Intent data = null;
if (requestCode == 101 && data != null)
{
Uri selctedImageUri =data.getData();
}
else
{
Toast toast = Toast.makeText(this, "No Image is selected.", Toast.LENGTH_LONG);
toast.show();
}
}
如何继续请帮助我......
in my app i am trying to send images to a server that are stored in sd card. When i click a button it opens the sd card and shows the image in a grid view. From that the i want to upload the image which i am touching on it. I know to upload an image to a server, but i dont know to select an image from the sd card please help me.....
Following is my code....
public void library()
{
Intent myIntent = new Intent();
myIntent.setType("image/*");
myIntent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(myIntent,"Select Picture"), 101);
}
public void onActivityResult(int requestCode, int resultCode, Intent myIntent)
{
Intent data = null;
if (requestCode == 101 && data != null)
{
Uri selctedImageUri =data.getData();
}
else
{
Toast toast = Toast.makeText(this, "No Image is selected.", Toast.LENGTH_LONG);
toast.show();
}
}
how to proceed please help me.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是获取图库图像的意图:
然后这段代码是在图像视图中设置从图库中选择的图像:
使用 On ActivityResult 来实现:
This Method for Reducing the Size of Image;
在这些方法中,如果您传递包含图像的文件,它将调整图像大小并返回 BITMAP..
This is the Intent for getting Gallery images :
Then this code is to set the image selected from the Gallery in the Image View :
Use On ActivityResult fro this :
This Method for Reducing the Size of Image ;
In these method if you Pass a File that contains image it will Resize the image and returns BITMAP..