上传的ImageView服务器 [英] Upload imageview to server
本文介绍了上传的ImageView服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
公共类上传延伸活动{
私有静态最终诠释CAMERA_REQUEST = 1888;
私人ImageView的ImageView的;
串selectedPath =;
TextView的textTargetUri;
ImageView的targetImage;
InputStream为;
@覆盖
公共无效的onCreate(捆绑冰柱){
super.onCreate(冰柱);
的setContentView(R.layout.main); this.imageView =(ImageView的)this.findViewById(R.id.targetimage);
按钮photoButton =(按钮)this.findViewById(R.id.takeimage);
photoButton.setOnClickListener(新View.OnClickListener(){ @覆盖
公共无效的onClick(视图v){
意图cameraIntent =新意图(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,CAMERA_REQUEST);
}
}); 按钮buttonLoadImage =(按钮)findViewById(R.id.loadimage);
textTargetUri =(的TextView)findViewById(R.id.targeturi);
targetImage =(ImageView的)findViewById(R.id.targetimage); //结果。图片ditampilkan buttonLoadImage.setOnClickListener(新Button.OnClickListener(){
@覆盖
公共无效的onClick(查看为arg0){
意向意图=新意图(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(意向,0);
}});
} @覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
super.onActivityResult(要求code,结果code,数据); 如果(要求code == CAMERA_REQUEST){
。位图的照片=(位图)data.getExtras()获得(数据);
imageView.setImageBitmap(照片);
} 如果(结果code == RESULT_OK){
乌里targetUri = data.getData();
textTargetUri.setText(targetUri.toString());
位图位图;
尝试{
位= BitmapFactory.de codeStream(getContentResolver()openInputStream(targetUri));
targetImage.setImageBitmap(位图);
}赶上(FileNotFoundException异常五){
e.printStackTrace();
}
}
}
}
我已经设法显示来自摄像机图像和文件浏览搜索
但我不能整合上传功能结果
我看过其他的答案,但它只是让更多的错误..结果
我用POST PHP的东西混淆也结果
任何人都可以帮忙吗?由于结果之前
这是XML结果
<按钮
机器人:ID =@ + ID /的LoadImage
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=打开图片库
/>
<按钮
机器人:ID =@ + ID / takeimage
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=拍照
/>
<的TextView
机器人:ID =@ + ID / targeturi
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
/>< ImageView的
机器人:ID =@ + ID / targetimage
机器人:layout_width =FILL_PARENT
机器人:layout_height =323sp/><按钮
机器人:ID =@ + ID / uploadimage
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=上传图片/>
解决方案
@VenkataKrishna看来你的code是困扰我很多XD。我一直在寻找,发现一个新的解决方案
=响应httpclient.execute(postRequest);
它替换为
=响应httpclient.execute(新HttpPost(我的网址在这里));
在try-catch之前添加此
的HttpParams P =新BasicHttpParams();
p.setParameter(参数,p)的;
HttpClient的HttpClient的=新DefaultHttpClient(P);
反正,感谢帮助我:D
public class upload extends Activity {
private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
String selectedPath = "";
TextView textTargetUri;
ImageView targetImage;
InputStream is;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
this.imageView = (ImageView)this.findViewById(R.id.targetimage);
Button photoButton = (Button) this.findViewById(R.id.takeimage);
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
Button buttonLoadImage = (Button)findViewById(R.id.loadimage);
textTargetUri = (TextView)findViewById(R.id.targeturi);
targetImage = (ImageView)findViewById(R.id.targetimage); // result gambar ditampilkan
buttonLoadImage.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 0);
}});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
if (resultCode == RESULT_OK){
Uri targetUri = data.getData();
textTargetUri.setText(targetUri.toString());
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
targetImage.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
I already manage to display picture from camera and browse from file
but I can't integrate the Upload function
I have read other answers, but it just get more errors..
I confused with the POST PHP things also
anyone can help? Thanks before
these are the XML
<Button
android:id="@+id/loadimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Open Picture Gallery"
/>
<Button
android:id="@+id/takeimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Take Picture"
/>
<TextView
android:id="@+id/targeturi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/targetimage"
android:layout_width="fill_parent"
android:layout_height="323sp" />
<Button
android:id="@+id/uploadimage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Upload Picture" />
解决方案
@VenkataKrishna seems your code is troubling me a lot XD. I keep searching and found a new solution
response = httpclient.execute(postRequest);
replace it with
response=httpclient.execute(new HttpPost("my url here"));
add this before the try-catch
HttpParams p=new BasicHttpParams();
p.setParameter("parameter", p);
HttpClient httpclient = new DefaultHttpClient(p);
anyways, thanks for helping me :D
这篇关于上传的ImageView服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文