我有这段代码:
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFileDir = getDir();
if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {
Toast.makeText(context, "Dir not created. (ERR#GRA1)", Toast.LENGTH_LONG).show();
return;
}
SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss", Locale.US);
String date = dateFormat.format(new Date());
photoFile = acao + android_id + "_" + date + "_" + coordenadas + ".jpg";
String filename = pictureFileDir.getPath() + File.separator + photoFile;
File pictureFile = new File(filename);
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
Toast.makeText(context, "Saved.", Toast.LENGTH_SHORT).show();
Login.totalTiradas++;
} catch (Exception error) {
Toast.makeText(context, "Not saved. (ERR#GRA2)", Toast.LENGTH_LONG).show();
}
camera2.startPreview();
aviso.setVisibility(View.INVISIBLE);
String stringUrl = "111.222.333.444";
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
new conectaFTP().execute(stringUrl);
} else {
Toast.makeText(context, "Fail. Image not sent. (ERR#CON1)", Toast.LENGTH_LONG).show();
}
}
它将照片保存到 SD 卡,调用 AsyncTask 并上传图片。一切正常。
我需要调整图片大小。在保存或上传之前,任何人都对我有好处。
我无法inSampleSize
正常Camera.setParameters
工作(当然是我的错),或者如果这是更好的方法。