把图像从画廊ParseFile机器人 [英] Putting image from gallery in ParseFile android

查看:119
本文介绍了把图像从画廊ParseFile机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作parse.com Android应用程序,其中我把pdefined /默认的图片我的$ P $在ParseFile并将其发送给服务器。不,我想提出一个图像用户选择从画廊。我的code为如下,请帮我从画廊得到的图像并把它放在ParseFile发送。

  //这是我从绘制得到我的默认图片。
位图位图= BitmapFactory.de codeResource(getResources(),R.drawable.usman);ByteArrayOutputStream流=新ByteArrayOutputStream();
bitmap.com preSS(Bitmap.Com pressFormat.PNG,100,流);
字节[] =图像stream.toByteArray();ParseFile文件=新ParseFile(profileImage.png,图像);
//将图像上传到云解析
file.saveInBackground();
//创建一个名为profileImage栏,并插入图片
Constants.user.put(profileImage文件);
Constants.user.saveInBackground(新SaveCallback(){    @覆盖
    公共无效完成(ParseException的E){        // dismissLoadingDialog();
        如果(E == NULL){
            Toast.makeText(getApplicationContext(),用户个人资料已更新!,Toast.LENGTH_SHORT).show();
        }其他{            Logs.e(的getClass()的getName(),e.​​toString());
            Toast.makeText(getApplicationContext(),异常/ N+ E,Toast.LENGTH_SHORT).show();
            // showMessage(e.getMessage());
        }
    }
});


解决方案

试试这个...

 公共无效setImage(位图地图){
    ByteArrayOutputStream流=新ByteArrayOutputStream();
    //的COM preSS的图像质量下降比例为1 - 100
    map.com preSS(Bitmap.Com pressFormat.JPEG,100,流);
    字节[] =图像stream.toByteArray();    //创建ParseFile
    ParseFile文件=新ParseFile(picture_1.jpeg,图像);
     //将图像上传到云解析
    ParseUser用户= ParseUser.getCurrentUser();
    user.put(profilePic文件);user.saveInBackground(新SaveCallback(){
    @覆盖
    公共无效完成(ParseException的E){    }
});}

I am working on parse.com android application, in which i am putting my predefined/default image in ParseFile and sending it to the server. No i want to put an image on user selection from gallery. My code is given below, please help me out to get image from gallery and put it in ParseFile for sending.

//It is my default image which i am getting from drawable.
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.usman);

ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();

ParseFile file = new ParseFile("profileImage.png", image);
// Upload the image into Parse Cloud
file.saveInBackground();
// Create a column named "profileImage" and insert the image
Constants.user.put("profileImage", file);
Constants.user.saveInBackground(new SaveCallback() {

    @Override
    public void done(ParseException e) {

        // dismissLoadingDialog();
        if (e == null) {
            Toast.makeText(getApplicationContext(),"User Profile Has Been Updated!",Toast.LENGTH_SHORT).show();
        } else {

            Logs.e(getClass().getName(), e.toString());
            Toast.makeText(getApplicationContext(), "Exception/n" + e, Toast.LENGTH_SHORT).show();
            // showMessage(e.getMessage());
        }
    }
});

解决方案

Try this...

 public void setImage( Bitmap map){


    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    // Compress image to lower quality scale 1 - 100
    map.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    byte[] image = stream.toByteArray();

    // Create the ParseFile
    ParseFile file  = new ParseFile("picture_1.jpeg", image);
     // Upload the image into Parse Cloud
    ParseUser user = ParseUser.getCurrentUser();
    user.put("profilePic",file);

user.saveInBackground(new SaveCallback() {
    @Override
    public void done(ParseException e) {

    }
});

}

这篇关于把图像从画廊ParseFile机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆