The inserted image in Mysql has different size and it blank when retrieving to android app
<p>I want to insert and retrieve images from android device to Mysql database.</p>

<p>When I insert the image in DB the size is smaller than the actual size, so if I retrieve it to client side it dose not appear.
But when I download the image from my server and re-insert it manually (I mean without using PHP file), the image size is actual size and I re-retrieve it in client side, it appears.</p>

<p>I think my problem in insert part in PHP file Can any one guide me please ?</p>

<p><strong>Here is my code</strong></p>

<p>This is the button to pick the image </p>

<pre><code>B1.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        Intent intentBrowseFiles = new Intent(Intent.ACTION_PICK,       android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);      startActivityForResult(intentBrowseFiles,2);    
    }
});
</code></pre>

<p>This is code to insert the image and then to view it in the imageView</p>

<pre><code>public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (resultCode== Activity.RESULT_OK){

        if (requestCode==2) //result from  Gallery      
        {
            Uri selectedImageUri = data.getData();  //return uri of selected image

            String  ImagePath = getPath(selectedImageUri);

            Bitmap bitmapOrg= BitmapFactory.decodeFile(ImagePath);
            ByteArrayOutputStream bao = new ByteArrayOutputStream();
            bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
            byte [] ba = bao.toByteArray();
            String ba1=Base64a.encodeBytes(ba);
            ArrayList&lt;NameValuePair&gt; postParameters = new ArrayList&lt;NameValuePair&gt;();
            postParameters.add(new BasicNameValuePair("imgPath", ba1));

            JSONObject jsonResponse=null;

            try {
                jsonResponse = CustomHttpClient.executeHttpPost("...PHP file...",postParameters);
                String base64image = jsonResponse.getString("img");
                byte[] rawImage = Base64a.decode(base64image, Base64.DEFAULT);
                Bitmap bmp = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
                i.setImageBitmap(bmp); //i is imageView  
            }catch (Exception e) {
                Toast.makeText(this, "Exception.. "+ e.toString() , Toast.LENGTH_LONG).show();
            }
</code></pre>

<hr>

<p>PHP file is :</p>

<pre><code>$imgPath= $_POST['imgPath'];

$binary=base64_decode($imgPath);

$file = fopen('test.png', 'wb');

fwrite($file, $binary);

fclose($file);

$query = mysql_query("INSERT INTO Photo  (img)  VALUES  ('test.png')");

if ($query) 
{
    $ImageId=mysql_insert_id();

    $query = mysql_query("SELECT img FROM  Photo WHERE photo_id='$ImageId'");
    $row = mysql_fetch_assoc($query) ; 
    $row=$row['img'];
    $s = base64_encode($row);

    echo json_encode(array('img'=&gt; $s) );
}
</code></pre>
