Bonjour visiteur, Merci de vous Inscrire ou de vous connectez pour voir les liens!
c'est un choix aussi effectivement.
Il y a des partisans du pour et du contre.
Personnellement je préfère ta méthode aussi, c'est plus flexible![]()
-
Bonjour tout le monde ! Veillez consulter la Politique de forum pour comprendre nos règles, Merci a vous !Rejeter la notice
AIDE [Résolu] Compresser une image
Discussion dans 'Windev Mobile' créé par ANDRE3000, Août 9, 2018.
Tags:
Bonjour à tous il est vrai que je viens très tard à ce sujet j'utilise toujours ce code
[windev]// Donne la rotation de l'image
import android.media.ExifInterface;
import java.lang.Exception;
import android.graphics.*;
import android.util.Log;
import java.io.FileOutputStream;
public static boolean TraitePhotoJava(String sPhoto, int nTailleMax){
int nRotation = 0;
boolean res = false;
try{
ExifInterface m_exif = new ExifInterface(sPhoto);
nRotation = (int)exifOrientationToDegrees(m_exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL));
// BITMAP
BitmapFactory.Options bounds = new BitmapFactory.Options();
// Réduit la taille
Bitmap sourceBitmap = BitmapFactory.decodeFile(sPhoto,bounds);
if (sourceBitmap == null){
return false;
}
// Rotation
Matrix matrix = new Matrix();
if (nRotation > 0) {
matrix.preRotate(nRotation);
}
// redimensionnement
int width = sourceBitmap.getWidth();
int height = sourceBitmap.getHeight();
int newWidth;
int newHeight;
if (width > height){
newWidth = nTailleMax;
newHeight = (int) nTailleMax * height / width;
}
else{
newHeight = nTailleMax;
newWidth = (int) nTailleMax * width / height;
}
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
matrix.postScale(scaleWidth, scaleHeight);
// Création du nouveau bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, width, height, matrix, true);
sourceBitmap.recycle();
if (resizedBitmap == null){
return false;
}
// Sauvegarde
FileOutputStream out = new FileOutputStream(sPhoto);
res = resizedBitmap.compress(Bitmap.CompressFormat.JPEG , 100, out);
resizedBitmap.recycle();
resizedBitmap = null;
sourceBitmap = null;
return res;
}
catch(Exception e) {
Log.e("MO",e.toString());
return false;
}
}
public static float exifOrientationToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
return 90;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
return 180;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
return 270;
}
return 0;
}[/windev]
après j'appelle la procédure dans le callback
[windev]// Traitement des données exif et redimensionnement
TraitePhotoJava(FEN_Scan.gsPhotoAjout,TAILLE_MAX_PHOTO)
// Chargement du buffer
bufIMG = fChargeBuffer(FEN_Scan.gsPhotoAjout)[/windev]
joker apprécie ceci.
Merci pour ta réponde Man.
Ma question est toute simple.
Sans avoir essayé ta solution, je présume qu'elle est prévue pour Android (import android.media.ExifInterface).
Comment résoudre le même problème pour iOS?
En d'autres termes : pour iOS je vais sans doute avoir le même problème que pour Android : dRedimensionne ne maintien pas l'orientation originale de l'image donc il va me falloir passer par un système android.media.ExifInterface équivalent pour iOS, n'est-ce pas?
Merci pour ton aide!
Bonjour à tous il est vrai que je viens très tard à ce sujet j'utilise toujours ce code
[windev]// Donne la rotation de l'image
import android.media.ExifInterface;
import java.lang.Exception;
import android.graphics.*;
import android.util.Log;
import java.io.FileOutputStream;
public static boolean TraitePhotoJava(String sPhoto, int nTailleMax){
int nRotation = 0;
boolean res = false;
try{
ExifInterface m_exif = new ExifInterface(sPhoto);
nRotation = (int)exifOrientationToDegrees(m_exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL));
// BITMAP
BitmapFactory.Options bounds = new BitmapFactory.Options();
// Réduit la taille
Bitmap sourceBitmap = BitmapFactory.decodeFile(sPhoto,bounds);
if (sourceBitmap == null){
return false;
}
// Rotation
Matrix matrix = new Matrix();
if (nRotation > 0) {
matrix.preRotate(nRotation);
}
// redimensionnement
int width = sourceBitmap.getWidth();
int height = sourceBitmap.getHeight();
int newWidth;
int newHeight;
if (width > height){
newWidth = nTailleMax;
newHeight = (int) nTailleMax * height / width;
}
else{
newHeight = nTailleMax;
newWidth = (int) nTailleMax * width / height;
}
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
matrix.postScale(scaleWidth, scaleHeight);
// Création du nouveau bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, width, height, matrix, true);
sourceBitmap.recycle();
if (resizedBitmap == null){
return false;
}
// Sauvegarde
FileOutputStream out = new FileOutputStream(sPhoto);
res = resizedBitmap.compress(Bitmap.CompressFormat.JPEG , 100, out);
resizedBitmap.recycle();
resizedBitmap = null;
sourceBitmap = null;
return res;
}
catch(Exception e) {
Log.e("MO",e.toString());
return false;
}
}
public static float exifOrientationToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
return 90;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
return 180;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
return 270;
}
return 0;
}[/windev]
après j'appelle la procédure dans le callback
[windev]// Traitement des données exif et redimensionnement
TraitePhotoJava(FEN_Scan.gsPhotoAjout,TAILLE_MAX_PHOTO)
// Chargement du buffer
bufIMG = fChargeBuffer(FEN_Scan.gsPhotoAjout)[/windev]Cliquez pour agrandir...
Bonjour visiteur, Merci de vous Inscrire ou de vous connectez pour voir les liens!
, je crois me souvenir qu'il existe une é l'option 'Orienter selon les données Exif de l'image'
Bonjour visiteur, Merci de vous Inscrire ou de vous connectez pour voir les liens!
a été obligé de faire une fonction java car il est passé par un buffer.
Si tu fais une simple affectation de l'image cela gère l'exif.
Bonjour visiteur, Merci de vous Inscrire ou de vous connectez pour voir les liens!
, je crois me souvenir qu'il existe une é l'option 'Orienter selon les données Exif de l'image'
Bonjour visiteur, Merci de vous Inscrire ou de vous connectez pour voir les liens!
a été obligé de faire une fonction java car il est passé par un buffer.
Si tu fais une simple affectation de l'image cela gère l'exif.Cliquez pour agrandir...
Mon problème est comment faire pour iOS?
J'en profite pour dire que le code de
Bonjour visiteur, Merci de vous Inscrire ou de vous connectez pour voir les liens!
marche a la perfection et sans aucune complication pour mettre en place sa solution.Je pense que l'idéal serai avoir un code équivalant en Objective-C ou Swift à moins que quelqu'un ne connaisse une solution plus simple.
Mon but est d'uploader les photos par webservice plutôt que de les afficher sur le terminal mobile.
Merci pour votre aide.
.
Une piste
Mais je suis nul en iOS
Bonjour visiteur, Merci de vous Inscrire ou de vous connectez pour voir les liens!
Cliquez pour agrandir...
J'ai eu un retour de PCSoft qui me confirme que ceci est la bonne approche.
Je n'ai pas besoin de faire rotation de l'image puisqu'en WLangage ça se fait sans problème. Ce qu'il me faut c'est le code pour iOS pour extraire l'angle de l'image. Mais je vais quand même jeter un coup d'œil sur ton lien pour voir ce que ji trouve.