我能单独发送图像和文字,但我想发送图片和文字一起 请帮助我的人如何使用网络API
-6
A
回答
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
相关问题
- 1. 如何通过网络API
- 2. 如何在Asp.Net网络API
- 3. 如何使用Node.js使用流式网络API的使用Django
- 4. 剑道serverPaging使用JavaScript和网络API
- 5. 使用模拟拨打网络api
- 6. 使用Google Places API网络服务
- 7. 使用网络源SOAP API的错误
- 8. 404试图使用网络API端点
- 9. 使用POST和urllib2访问网络API
- 10. 如何使用网络音频API设置采样率?
- 11. 如何使用网络音频API反向播放音频?
- 12. 如何从Android使用android API获取wifi网络的名称?
- 13. 如何使用新浪微博API进行网络登录
- 14. 如何使用网络API重定向2 IHttpActionResult
- 15. 如何使用CosmosDB gremlin API设计社交网络?
- 16. 如何添加语音使用网络语音API
- 17. 如何使用Windows API检查网络连接类型?
- 18. 如何提供与网络API
- 19. Docker API - 如何加入网络?
- 20. 如何在网络核心的Web API
- 21. 如何从网络API来访问图形API在SPA应用
- 22. AKKA.NET与Asp.net网络API api
- 23. 网络使用:如何连接到网络共享?
- 24. C#网络API的
- 25. CIL如何使用网络/ http请求?
- 26. 如何使用网络套接字
- 27. 如何通过网络使休息API呼叫iOS
- 28. 网络使用Java
- 29. 如何获得可用的网络运营商? (使用RIL和非API方法)
- 30. 如何使用网络API调用在Swift中实现MVC模式?
在这里张贴问题 –