1
When I upload a photo to the server and I will display it using
Picasso.with(getApplicationContext()).load(Caminhofoto).into(fotoalerta);
If the photo was taken with the mobile phone vertically she is loaded horizontally would have to display it correctly. I have this same problem when loading it from SDCARD but I am using this code to display correctly.
public String getRealPathFromURI(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
@SuppressWarnings("deprecation")
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public static Bitmap rotateBitmap(Bitmap bitmap, int orientation) {
try{
Matrix matrix = new Matrix();
switch (orientation) {
case ExifInterface.ORIENTATION_NORMAL:
return bitmap;
case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
matrix.setScale(-1, 1);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
matrix.setRotate(180);
break;
case ExifInterface.ORIENTATION_FLIP_VERTICAL:
matrix.setRotate(180);
matrix.postScale(-1, 1);
break;
case ExifInterface.ORIENTATION_TRANSPOSE:
matrix.setRotate(90);
matrix.postScale(-1, 1);
break;
case ExifInterface.ORIENTATION_ROTATE_90:
matrix.setRotate(90);
break;
case ExifInterface.ORIENTATION_TRANSVERSE:
matrix.setRotate(-90);
matrix.postScale(-1, 1);
break;
case ExifInterface.ORIENTATION_ROTATE_270:
matrix.setRotate(-90);
break;
default:
return bitmap;
}
try {
Bitmap bmRotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
bitmap.recycle();
return bmRotated;
}
catch (OutOfMemoryError e) {
e.printStackTrace();
return null;
}
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
My image UPLOAD class
public class classe_FTP
{
FTPClient mFtp;
private String TAG = "classeFTP";
public boolean MudarDiretorio(String Diretorio)
{
try
{
mFtp.changeWorkingDirectory(Diretorio);
}
catch(Exception e)
{
Log.e(TAG, "Erro: não foi possível mudar o diretório para " + Diretorio);
}
return false;
}
public boolean Desconectar()
{
try
{
mFtp.disconnect();
mFtp = null;
return true;
}
catch (Exception e)
{
Log.e(TAG, "Erro: ao desconectar. " + e.getMessage());
}
return false;
}
public boolean Conectar(String Host, String Usuario, String Senha, int Porta)
{
try
{
mFtp = new FTPClient();
mFtp.connect(Host, Porta);
if (FTPReply.isPositiveCompletion(mFtp.getReplyCode()))
{
boolean status = mFtp.login(Usuario, Senha);
mFtp.setFileType(FTP.BINARY_FILE_TYPE);
mFtp.enterLocalPassiveMode();
return status;
}
}
catch(Exception e)
{
Log.e(TAG, "Erro: não foi possível conectar" + Host);
}
return false;
}
public boolean Upload(String diretorio, String nomeArquivo)
{
boolean status = false;
try
{
FileInputStream arqEnviar = new FileInputStream(Environment.getExternalStorageDirectory() + diretorio);
mFtp.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
mFtp.setFileType(FTPClient.STREAM_TRANSFER_MODE);
mFtp.storeFile("/patrulhar.com.br/imagens/"+nomeArquivo, arqEnviar);
Desconectar();
System.out.println("Upload win1 . ");
return status;
}
catch (Exception e)
{
Log.e(TAG, "Erro: Falha ao efetuar Upload1. " + e.getMessage());
}
return status;
}
public boolean Upload2(String diretorio, String nomeArquivo)
{
boolean status = false;
try
{
FileInputStream arqEnviar = new FileInputStream(diretorio);
mFtp.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
mFtp.setFileType(FTPClient.STREAM_TRANSFER_MODE);
mFtp.storeFile("/patrulhar.com.br/imagens/"+nomeArquivo, arqEnviar);
Desconectar();
System.out.println("Upload win2 . ");
return status;
}
catch (Exception e)
{
Log.e(TAG, "Erro: Falha ao efetuar Upload2. " + e.getMessage());
}
return status;
}
}
If I understood correctly then the solution is to use the method
rotateBitmap()
in that situation also.– ramaral
More I can use rotateBitmap() using Icasso or how I should do it ?
– Guilherme
Do the Rotate of the image before the upload
– ramaral
I upload the image by her way on mobile as I could using this bitmap with it right?
– Guilherme