我已经能够使用相机拍摄照片或从画廊中取出并使用此代码在ImageVIEw中显示它.我现在需要做的是使用该图片并将其上传到Parse.我一直在谷歌上搜索,我没有找到正确的方法来做到这一点.有人可以帮我这个吗?是否可以从ImageVIEw上传图像?谢谢.
protected button mFromCamera;protected button mFromgallery;protected ImageVIEw mImageVIEw;private static final int CAMERA_REQUEST = 1888;private static final int SELECT_PHOTO = 100;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentVIEw(R.layout.activity_main);//Initialize ImageVIEwmImageVIEw = (ImageVIEw) findVIEwByID(R.ID.imgPrev);//Initialize CameramFromCamera = (button) findVIEwByID(R.ID.FromCamera);//use cameramFromCamera.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { Intent cameraIntent = new Intent(androID.provIDer.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent,CAMERA_REQUEST); } //use camera end});//initialize buttonmFromgallery = (button) findVIEwByID(R.ID.Fromgallery);//pick a photomFromgallery.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw arg0) { Intent photopickerIntent = new Intent(Intent.ACTION_PICK,androID.provIDer.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); photopickerIntent.setType("image/*"); startActivityForResult(photopickerIntent,SELECT_PHOTO); }});//pick a photo end}//prevIEwing Image@OverrIDeprotected voID onActivityResult(int requestCode,int resultCode,Intent data) {super.onActivityResult(requestCode,resultCode,data);switch (requestCode) { //from the gallery case SELECT_PHOTO: if (requestCode == SELECT_PHOTO && resultCode == RESulT_OK && null!= data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; Cursor cursor = getContentResolver().query(selectedImage,filePathColumn,null,null); cursor.movetoFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); mImageVIEw.setimageBitmap(BitmapFactory.decodefile(picturePath)); } break; //from the camera case CAMERA_REQUEST: if (requestCode == CAMERA_REQUEST && resultCode == RESulT_OK) { Bitmap photo = (Bitmap) data.getExtras().get("data"); mImageVIEw.setimageBitmap(photo); } break;}}//PrevIEw Image End
最佳答案阅读你的答案:I already followed the code that you have before. I was able to upload the image to parse. but I dont kNow how to switch the drawable source to be my image from camera/gallery or imagevIEw. – stanley santoso
至 :
Abhishek Bansal
我明白你的问题不是解析你的形象?
试着回答你的问题:
I dont kNow how to switch the drawable source to be my image from camera/gallery or imagevIEw.
1 – R.drawable.androIDbegin似乎是你的问题但事实是你已经在你的代码中解析了你的位图:
来自画廊 – >
mImageVIEw.setimageBitmap(BitmapFactory.decodefile(picturePath));
来自相机 – >
Bitmap photo = (Bitmap) data.getExtras().get("data");
2 – 所以我建议在代码的开头声明一个Bitmap类型的变量
private Bitmap yourbitmap;
3 – 然后在代码中为库和相机分配位图,并使用它来解析它.
...yourbitmap = BitmapFactory.decodefile(picturePath);...yourbitmap = (Bitmap) data.getExtras().get("data");...
4 – 最后你可以这样使用你的位图:
// Bitmap bitmap = BitmapFactory.decodeResource(getResources(),// R.drawable.androIDbegin); // Convert it to byte ByteArrayOutputStream stream = new ByteArrayOutputStream(); // Compress image to lower quality scale 1 - 100 yourbitmap.compress(Bitmap.CompressFormat.PNG,100,stream); byte[] image = stream.toByteArray(); ...
总结 以上是内存溢出为你收集整理的如何在Android中将图像上传到Parse?全部内容,希望文章能够帮你解决如何在Android中将图像上传到Parse?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)