2017-04-27 74 views

回答

0

使用多发送图片和文字从Android应用程序到SQL Server。使用多部分,您可以将图像视频和其他文件与您的文本数据一起发送。各种库可用于以多部分发送数据。离子就是其中之一

0

一种方法是你可以在图像转换为Base64编码字符串中的Web API

public static String imageToString(Bitmap BitmapData) { 

     ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
     BitmapData.compress(Bitmap.CompressFormat.PNG, 100, bos); 
     byte[] byte_arr = bos.toByteArray(); 

     String file = Base64.encodeToString(byte_arr, Base64.DEFAULT); 
     //appendLog(file); 
     return file; 
} 

可以位图图像转换为Base64字符串中的上述功能,并通过字符串参数在您的API和解码的字符串在服务器端

+0

由于Bhupat Bheda我的项目之前,请搜索彻底完成 –

0

感谢你们所有人特别感谢Bhupat Bheda。我完成了我的完整项目。现在我想分享我的研究成果。

private void saveText() { 

    String image= getStringImage(rotatedBMP); 
    ImageCapture imageCapture = new ImageCapture(); 

    imageCapture.Name = prescriptionName.getText().toString(); 
    imageCapture.Remarks = remarks.getText().toString(); 
    imageCapture.ImageURL=mCurrentPhotoPath; 
    imageCapture.PhotoName=photoName; 
    imageCapture.Image=image; 

    imageCapture.Id = _ImageId_Id; 
    if (_ImageId_Id == 0) { 
     restService.getService().InsertPrescription(imageCapture, new Callback<ImageCapture>() { 
      @Override 
      public void success(ImageCapture imageCapture, Response response) { 
       Toast.makeText(Prescription.this, "New Record Inserted.", Toast.LENGTH_LONG).show(); 

       Intent intent=new Intent(getApplicationContext(),Home.class); 
       startActivity(intent); 
      } 

      @Override 
      public void failure(RetrofitError error) { 
       Toast.makeText(Prescription.this, error.getMessage().toString(), Toast.LENGTH_LONG).show(); 

      } 
     }); 
    } 

} 

private void takePhoto() { 
    dispatchTakePictureIntent(); 
} 





@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    // TODO Auto-generated method stub 
    Log.i(TAG, "onActivityResult: " + this); 
    if (requestCode == REQUEST_TAKE_PHOTO && resultCode == Activity.RESULT_OK) { 
     setPic(); 
    } 
} 

String mCurrentPhotoPath; 
String photoName; 

static final int REQUEST_TAKE_PHOTO = 1; 
File photoFile = null; 

private void dispatchTakePictureIntent() { 
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    // Ensure that there's a camera activity to handle the intent 
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) { 
     // Create the File where the photo should go 
     File photoFile = null; 
     try { 
      photoFile = createImageFile(); 
     } catch (IOException ex) { 
      // Error occurred while creating the File 

     } 
     // Continue only if the File was successfully created 
     if (photoFile != null) { 
      takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, 
        Uri.fromFile(photoFile)); 
      startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); 
     } 
    } 
} 



public String getStringImage(Bitmap bmp) { 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
    byte[] imageBytes = baos.toByteArray(); 
    String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT); 
    return encodedImage; 
} 

查看详情【如何使用Web API发送图片和文字从Android应用程序与SQL Server] [1]

https://esoftpanel.blogspot.com/2017/04/how-to-send-image-and-text-from-android.html