0

ビットマップが作成されない理由を誰か教えてもらえますか?何か間違っている場合は、他のコードも確認してください。

HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("URL");

    List<NameValuePair> list = new ArrayList<NameValuePair>();
    list.add(new BasicNameValuePair("username",username));
    UrlEncodedFormEntity urlencodedformentity = new UrlEncodedFormEntity(list);

    httppost.setEntity(urlencodedformentity);
    HttpResponse response = httpclient.execute(httppost);
    InputStream is = response.getEntity().getContent();

// following Bitmap is getting null

    Bitmap bm = BitmapFactory.decodeStream(new BufferedInputStream(is));
    if(bm==null)
    {
        Toast.makeText(this,"Bitmap null", Toast.LENGTH_LONG).show();
    }
    else
    {
        img.setImageBitmap(bm);
    }

画像をサーバーに送信するクライアント側

Bitmap b = ((BitmapDrawable) img.getDrawable()).getBitmap();

ByteArrayOutputStream baos = new ByteArrayOutputStream();
b.compress(CompressFormat.JPEG, 100, baos);

byte ar[] = baos.toByteArray();
String s = Base64.encodeToString(ar, 0);

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("URL");

List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("username",username));
list.add(new BasicNameValuePair("image",s));
UrlEncodedFormEntity urlencodedformentity = new UrlEncodedFormEntity(list);

httppost.setEntity(urlencodedformentity);
HttpResponse response = httpclient.execute(httppost);
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

Toast.makeText(this, br.readLine(), Toast.LENGTH_LONG).show();

画像を取得して保存するサーバー側

String username = req.getParameter("username");
resp.getWriter().write(username);

try
{
byte[] image = req.getParameter("image").getBytes();

Blob profilepic = new Blob(image);

Profile profile = new Profile(username,profilepic);

pm = PMF.get().getPersistenceManager();

pm.currentTransaction().begin();

pm.makePersistent(profile);

pm.currentTransaction().commit();

resp.getWriter().write("Data stored successfully");
}

画像を送信するサーバー側

String username = req.getParameter("username");

pm = PMF.get().getPersistenceManager();
pm.currentTransaction().begin();

javax.jdo.Query query = pm.newQuery(Profile.class);
Collection<Profile> result = (Collection<Profile>) query.execute();

for (Profile result1 : result) 
{
    if(result1.getUsername().equalsIgnoreCase(username))
    {
        resp.getWriter().write(result1.getImage().toString());
        pm.currentTransaction().commit();
        break;              
    }

}
4

0 に答える 0