IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API graphiques Discussion :

[COCOA][NSBitmapImageRep] Image à l'invers


Sujet :

API graphiques

  1. #1
    Membre éclairé
    Avatar de Happy
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2005
    Messages
    665
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : Autre

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2005
    Messages : 665
    Points : 875
    Points
    875
    Par défaut [COCOA][NSBitmapImageRep] Image à l'invers
    Hello,

    Comme le titre l'indique, mon image se charge mais inversée horizontalement.

    Par exemple, l'image suivante :


    Et une fois chargée, j'ai :


    En gros, dire à NSBitmapImageRep de charger les images dans le bon sens.

    Le code suivant charge l'image :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    LDEuint LDEimage::load( string path )
    {
    	string mypath = path.substr( 0, path.rfind("/") );
    	string name = path.substr( path.rfind("/")+1, path.rfind(".")-(path.rfind("/")+1) );
    	string type = path.substr( path.rfind(".")+1, path.length()-path.rfind(".")+1 );
     
    	NSString* NSS_textureName = [NSString stringWithCString:name.c_str() encoding:NSUTF8StringEncoding];   
    	NSString* NSS_textureType = [NSString stringWithCString:type.c_str() encoding:NSUTF8StringEncoding];
    	NSString* NSS_texturePath = [NSString stringWithCString:mypath.c_str() encoding:NSUTF8StringEncoding];
     
    	NSString* path_objc = [NSBundle pathForResource:NSS_textureName ofType:NSS_textureType inDirectory:NSS_texturePath];
     
    	NSData *raw = [NSData dataWithContentsOfFile:path_objc];
    	NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithData:raw];
     
    	if ( rep != nil )
    	{
    		w = [rep size].width;
    		h = [rep size].height;
    		bpp = [rep samplesPerPixel];
     
    		data = new LDEubyte[w*h*bpp];
     
    		data = [rep bitmapData];
     
    		loaded = 1;
    	}
    	else
    		cout << " ! Error loading image \""<<mypath<<"/"<<name<<"."<<type<<"\"\n";
     
    	return loaded;
    }
    Merci par avance

  2. #2
    Membre éclairé
    Avatar de Happy
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2005
    Messages
    665
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : Autre

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2005
    Messages : 665
    Points : 875
    Points
    875
    Par défaut
    Trouvé la solution

    En gros j'ai copié mon data à l'invers.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    LDEuint LDEimage::load( string path )
    {
    	string mypath = path.substr( 0, path.rfind("/") );
    	string name = path.substr( path.rfind("/")+1, path.rfind(".")-(path.rfind("/")+1) );
    	string type = path.substr( path.rfind(".")+1, path.length()-path.rfind(".")+1 );
     
    	NSString* NSS_textureName = [NSString stringWithCString:name.c_str() encoding:NSUTF8StringEncoding];   
    	NSString* NSS_textureType = [NSString stringWithCString:type.c_str() encoding:NSUTF8StringEncoding];
    	NSString* NSS_texturePath = [NSString stringWithCString:mypath.c_str() encoding:NSUTF8StringEncoding];
     
    	NSString* path_objc = [NSBundle pathForResource:NSS_textureName ofType:NSS_textureType inDirectory:NSS_texturePath];
     
    	NSBitmapImageRep *rep = [NSBitmapImageRep imageRepWithContentsOfFile:path_objc];
     
    	if ( rep != nil )
    	{
    		w = [rep size].width;
    		h = [rep size].height;
    		bpp = [rep samplesPerPixel];
     
    		data = new LDEubyte[w*h*bpp];
     
    		LDEubyte *flipped_data = new LDEubyte[w*h*bpp];
    		flipped_data = [rep bitmapData];
     
    		LDEint bytesPerRow = [rep bytesPerRow];
    		for ( LDEuint i = 0; i < h; ++i )
    		{
    			bcopy((flipped_data + bytesPerRow * i), (data + bytesPerRow * (h - i - 1)), bytesPerRow);
    		}
     
    		loaded = 1;
    	}
    	else
    		cout << " ! Error loading image \""<<mypath<<"/"<<name<<"."<<type<<"\"\n";
     
    	return loaded;
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. script d'images défilantes non inversé
    Par laurentSc dans le forum Général JavaScript
    Réponses: 10
    Dernier message: 09/01/2010, 22h02
  2. Resize d'une image
    Par Anonymous dans le forum C
    Réponses: 6
    Dernier message: 13/07/2008, 22h23
  3. gspca modules, image inversé
    Par ppfromero dans le forum Debian
    Réponses: 1
    Dernier message: 22/04/2008, 11h54
  4. Image Bitmap inversé
    Par DestinyWar45 dans le forum OpenGL
    Réponses: 11
    Dernier message: 13/12/2006, 19h49
  5. lire une image au format RAW
    Par Anonymous dans le forum OpenGL
    Réponses: 5
    Dernier message: 20/05/2002, 00h11

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo