如何使用BitmapFactory将位图上传到Facebook

时间:2015-06-19 21:27:48

标签: android facebook-sdk-4.0

我正在开展一个项目,我需要将照片从Android应用程序上传到脸谱版。我已经安装了Facebook SDK并完成了所有工作,我甚至设法将状态和可绘制内容上传到Facebook。但是,我在上传到Facebook之前拍摄的图片保存在位图变量中,当我在这行代码中写入时:

"Bitmap image = BitmapFactory.decodeResource(getResources(), bitmap);" 

我收到错误:

  

BitmapFactory类型中的decodeResource(Resources,int)方法是   不适用于参数(参考资料,位图)

有没有解决问题?
这是整个代码"我在一个网站上发现了它":

public class AddRestaurantActivity extends FragmentActivity{


    private CallbackManager callbackManager;
    private LoginManager loginManager;


    private static final int CAMERA_REQUEST = 1888; 


    static String str_Camera_Photo_ImagePath = "";
    private static File f;
    private static int Take_Photo = 2;
    private static String str_randomnumber = "";
    static String str_Camera_Photo_ImageName = "";
    public static String str_SaveFolderName;
    private static File wallpaperDirectory;
    Bitmap bitmap;
    int storeposition = 0;
    public static GridView gridview;
    public static ImageView imageView;
    Bitmap faceView;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_restaurant);
        this.imageView = (ImageView)this.findViewById(R.id.imageView1);
        Button photoButton = (Button) this.findViewById(R.id.button1);

        photoButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) 
            {

                str_SaveFolderName = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/FastFood";
                str_randomnumber = String.valueOf(nextSessionId());
                wallpaperDirectory = new File(str_SaveFolderName);
                if (!wallpaperDirectory.exists())
                    wallpaperDirectory.mkdirs();
                str_Camera_Photo_ImageName = str_randomnumber + ".jpg";

                str_Camera_Photo_ImagePath = str_SaveFolderName + "/" + str_randomnumber + ".jpg";

                System.err.println("str_Camera_Photo_ImagePath  " + str_Camera_Photo_ImagePath);

                f = new File(str_Camera_Photo_ImagePath);
                startActivityForResult(new Intent(
                        MediaStore.ACTION_IMAGE_CAPTURE).putExtra(
                                MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)),
                                Take_Photo);
                System.err.println("f  " + f);
            }
        });
    }

    //Clickable Button
    public void gotoShare(View v)
    {
        Bitmap image = BitmapFactory.decodeResource(getResources(), faceView);
        SharePhoto photo = new SharePhoto.Builder()
        .setBitmap(image)
        .setCaption("Semi Final")
        .build();

        SharePhotoContent content = new SharePhotoContent.Builder()
        .addPhoto(photo)
        .build();

        ShareApi.share(content, null);
    }

    // used to create randon numbers
    public String nextSessionId() {
        SecureRandom random = new SecureRandom();
        return new BigInteger(130, random).toString(32);
    }


    protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        if (requestCode == Take_Photo) {
            String filePath = null;

            filePath = str_Camera_Photo_ImagePath;
            if (filePath != null) {
                faceView = ( new_decode(new File(filePath))); 
                imageView.setImageBitmap(faceView);
            } else {
                bitmap = null;
            }
        }
    } 


    public static Bitmap new_decode(File f) {...}
}

1 个答案:

答案 0 :(得分:0)

gotoShare方法中的新代码修复了它:

public void gotoShare(View v)
{
//Bitmap image = BitmapFactory.decodeResource(getResources(), 
R.drawable.ic_launcher);
Bitmap image = faceView;
SharePhoto photo = new 
SharePhoto.Builder().setBitmap(image).setCaption("Semi Final").build();
SharePhotoContent content = new 
SharePhotoContent.Builder().addPhoto(photo).build();
ShareApi.share(content, null);
}