android SkImageDecoder :: Factory返回null(位图)

时间:2014-02-21 19:58:53

标签: java android bitmapfactory

我正在向服务器发送图像。在发送5或6张图像后,我随机收到此错误。我不知道为什么位图返回null。由于我是Android的初学者,我对Android编程知之甚少。有人可以帮帮我..

这是我的代码

protected String doInBackground(String... path) {

    String outPut = null;

    for (String sdPath:path) {

        Bitmap bitmapOrg = BitmapFactory.decodeFile(sdPath);
        ByteArrayOutputStream bao = new ByteArrayOutputStream();

        //Resize the image
        double width = bitmapOrg.getWidth();
        double height = bitmapOrg.getHeight();
        double ratio = 400/width;
        int newheight = (int)(ratio*height);


        bitmapOrg = Bitmap.createScaledBitmap(bitmapOrg, 400, newheight, true);

        //Here you can define .PNG as well
        bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 95, bao);
        byte[] ba = bao.toByteArray();
        String ba1 = Base64.encodeToString(ba, 0);

        //System.out.println("uploading image now ——–" + ba1);

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("image", ba1));

        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();                

            // print responce
            outPut = EntityUtils.toString(entity);
            Log.i("GET RESPONSE—-", outPut);

            //is = entity.getContent();
            Log.e("log_tag ******", "good connection");

            bitmapOrg.recycle();

        } catch (Exception e) {
            Log.e("log_tag ******", "Error in http connection " + e.toString());
        }
    }
    return outPut;
}

0 个答案:

没有答案