代码之家  ›  专栏  ›  技术社区  ›  wisejoy

ImageView数据到Byte Array Android

  •  0
  • wisejoy  · 技术社区  · 11 年前

    我正在尝试使用parse.com数据库上载文件,语法需要我使用byte[]。我将编写以下语法:

    byte[] data = "Working at Parse is great!".getBytes();
    ParseFile file = new ParseFile("resume.png", data);
    file.saveInBackground();
    ParseObject jobApplication = new ParseObject("JobApplication");
    jobApplication.put("applicantResumeFile", file);
    jobApplication.saveInBackground();
    

    我需要知道如何使用第一条指令获取字节[]中的ImageView数据并将其上传。

    1 回复  |  直到 11 年前
        1
  •  1
  •   geekCode    11 年前

    @wisejoy我有一个实现,但我觉得有点不同。。。希望它能帮助你。。。干杯

                myBitmap = (Bitmap) data.getExtras().get("data");//here I set an image taken by the camera
                imageView.setImageBitmap(myBitmap);//I set it into an image view 
                imageView.buildDrawingCache();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();//and then I convert that image into a byteArray
                myBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                byte[] b = baos.toByteArray();
    
                encondedImage = android.util.Base64.encodeToString(b, Base64.DEFAULT);
                Log.e(TAG, "" + txt);