我可以单独发送图像和文字,但我想将图像和文本一起发送 请帮助我任何人
答案 0 :(得分:0)
使用multipart。使用multipart,您可以使用文本数据发送图像视频和其他文件。各种库可用于以多部分发送数据。离子就是其中之一
答案 1 :(得分:0)
一种方法是你可以在web api中将图像转换为Base64字符串
First way
$("#txtQuantity").on('click', function () {
alert('testing');
});
Second Way
var recipient = $("#txtQuantity")
$("#<%=recipient.ClientID%>").on('change', function () {
alert('testing');
});
你可以在上面的函数中将位图图像转换为Base64字符串并在api中传递字符串参数并在服务器端解码这些字符串
答案 2 :(得分: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