我能單獨發送圖像和文字,但我想發送圖片和文字一起 請幫助我的人如何使用網絡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 REST API
- 2. 如何使用SonarQube網絡API?
- 3. 如何使用網絡音頻api
- 4. 如何在Asp.Net網絡API
- 5. 如何通過網絡API
- 6. 如何使用Node.js使用流式網絡API的使用Django
- 7. 使用Facebook Graph API,我如何獲得用戶的網絡?
- 8. 如何使用以太網網絡
- 9. 404試圖使用網絡API端點
- 10. 使用Google Places API網絡服務
- 11. 使用網絡源SOAP API的錯誤
- 12. 使用POST和urllib2訪問網絡API
- 13. 劍道serverPaging使用JavaScript和網絡API
- 14. 使用模擬撥打網絡api
- 15. 使用API的網絡請求
- 16. 使用SSML與網絡語音API
- 17. 播放使用網絡音頻API
- 18. 如何使用網絡音頻API反向播放音頻?
- 19. 如何使用角度,內存,網絡API中Angular2?
- 20. 如何使用Windows API檢查網絡連接類型?
- 21. 如何使用網絡音頻API/JavaScript操作DOM?
- 22. 如何從Android使用android API獲取wifi網絡的名稱?
- 23. 如何使用新浪微博API進行網絡登錄
- 24. 如何添加語音使用網絡語音API
- 25. 如何使用網絡API重定向2 IHttpActionResult
- 26. 如何使用CosmosDB gremlin API設計社交網絡?
- 27. 調用WCF從網絡API
- 28. AJAX網絡API調用
- 29. 如何提供與網絡API
- 30. 如何在網絡核心的Web API
在這裏張貼問題 –