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

Delphi Discussion :

programmer un jeu de tarot


Sujet :

Delphi

  1. #21
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2017
    Messages
    344
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 344
    Par défaut
    j'ai écrit ce code mais les propriétés width et height d'un TPNGImage sont en lecture seule, il faut passer par un TBitmap ?!

    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
    39
    40
    41
    42
    43
    44
    procedure TForm1.Button2Click(Sender: TObject);
    var w,h,ww,hh,i,j,k:integer;
    pimg:tpngimage;
    begin
      ww:=img.width;
      hh:=img.Height;
      if (ww>0) and (hh>0) then
      begin
      w:=trunc(ww/spinedit1.Value);
      h:=trunc(hh/spinedit2.Value);
      {
      ww : largeur de la grande image
      hh : hauteur de la grande image
      w : largeur des petites images
      h : hauteurs des petites images
      img : grande image
      pimg: petite image
      }
      if not directoryexists('RESULTAT') then
        createdir('RESULTAT');
      k:=0;
      for I := 0 to trunc(ww/w) do
      begin
        for j := 0 to trunc(hh/h) do
        begin
     
          try
             inc(k);
              pimg:=tpngimage.Create;
              pimg.Width:=w;
              pimg.Height:=h;
              pimg.canvas.copymode:=cmSrcCopy;
              pimg.Canvas.CopyRect(rect(0,0,w-1,h-1),img.canvas,rect(i*w,j*h,(i+1)*w-1,(j+1)*h-1));
              pimg.SaveToFile('RESULTAT\'+inttostr(k)+'.png');
          finally
              pimg.Free;
          end;
     
        end;
      end;
      end
      else
      showmessage('Erreur ! Image vide !');
    end;

  2. #22
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2017
    Messages
    344
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 344
    Par défaut
    bon grâce à chatGPT j'ai trouvé la fonction setSize(width,height) de TPNGImage mais ça me renvoie un
    ---------------------------
    Notification des exceptions du débogueur
    ---------------------------
    Le projet Project1.exe a déclenché la classe d'exception EPNGInvalidNewSize avec le message 'La nouvelle taille fournie pour le redimensionnement de l'image est incorrecte.'.
    ---------------------------
    Arrêter Continuer Aide
    --------------------------

    avec un w=336 et h=644

    voici mon nouveau code :

    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
    39
    40
    41
    42
    43
    44
     
    procedure TForm1.Button2Click(Sender: TObject);
    var w,h,ww,hh,i,j,k:integer;
    pimg:tpngimage;
    begin
      ww:=img.width;
      hh:=img.Height;
      if (ww>0) and (hh>0) then
      begin
      w:=trunc(ww/spinedit1.Value);
      h:=trunc(hh/spinedit2.Value);
      {
      ww : largeur de la grande image
      hh : hauteur de la grande image
      w : largeur des petites images
      h : hauteurs des petites images
      img : grande image
      pimg: petite image
      }
      if not directoryexists('RESULTAT') then
        createdir('RESULTAT');
      k:=0;
      for I := 0 to trunc(ww/w) do
      begin
        for j := 0 to trunc(hh/h) do
        begin
     
          try
             inc(k);
              pimg:=tpngimage.Create;
              pimg.setsize(w,h);
              pimg.canvas.copymode:=cmSrcCopy;
              pimg.Canvas.CopyRect(rect(0,0,w-1,h-1),img.canvas,rect(i*w,j*h,(i+1)*w-1,(j+1)*h-1));
              pimg.SaveToFile('RESULTAT\'+inttostr(k)+'.png');
          finally
              pimg.Free;
          end;
     
        end;
      end;
      end
      else
      showmessage('Erreur ! Image vide !');
    end;
    EDIT : chatGPT m'a corrigé son code il faut faire : pimg:=tpngimage.CreateBlank(COLOR_RGBALPHA, 16, w, h);

  3. #23
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2017
    Messages
    344
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 344
    Par défaut
    voici mon code désormais mais ça me crée des images entièrement noires !

    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    procedure TForm1.Button2Click(Sender: TObject);
    var w,h,ww,hh,i,j,k:integer;
    pimg:tpngimage;
    n:string;
    begin
      button2.hide;
      ww:=img.width;
      hh:=img.Height;
      if (ww>0) and (hh>0) then
      begin
      w:=trunc(ww/spinedit1.Value);
      h:=trunc(hh/spinedit2.Value);
      {
      ww : largeur de la grande image
      hh : hauteur de la grande image
      w : largeur des petites images
      h : hauteurs des petites images
      img : grande image
      pimg: petite image
      }
      if not directoryexists('RESULTAT') then
        createdir('RESULTAT');
      k:=0;
      n:= '/'+inttostr((trunc(ww/w)+1)* (trunc(hh/h)+1));
      for I := 0 to trunc(ww/w) do
      begin
        for j := 0 to trunc(hh/h) do
        begin
     
          try
             inc(k);
             pimg:=tpngimage.Create;
             pimg.CreateBlank(COLOR_RGBALPHA,16, w, h);
              pimg.Canvas.copyrect(rect(0,0,w-1,h-1),img.canvas, rect(i*w,j*h,(i+1)*w-1,(j+1)*h-1) );
              pimg.SaveToFile('RESULTAT\'+inttostr(k)+'.png');
              label5.Caption:=inttostr(k)+n;
              application.processmessages;
          finally
              pimg.Free;
          end;
     
        end;
      end;
      showmessage('Terminé !');
      end
      else
      showmessage('Erreur ! Image vide !');
      button2.Show;
    end;

  4. #24
    Expert confirmé
    Avatar de anapurna
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2002
    Messages
    3 479
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 479
    Par défaut
    salut

    voici le tableaux correspondant a tes cartes de tarot
    [000][101][102][103][104][105][106][107][108][109]
    [112][113][114][110][111][201][202][203][204][205]
    [206][214][210][211][999][301][302][303][304][305]
    [207][306][313][402][403][404][405][406][407][408]
    [208][307][314][409][410][903][904][905][906][907]
    [209][308][310][412][411][908][911][914][915][916]
    [212][309][311][413][901][909][912][917][919][921]
    [213][312][401][414][902][910][913][918][920][000]

    tu l'auras compris la centaine correspond à une couleur ou un atout
    les deux dernier nombre étant la valeurs des cartes

  5. #25
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2017
    Messages
    344
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 344
    Par défaut
    oui mais j'aimerais bien arriver à découper par un programme les cartes au format PNG personne n'a d'idée pourquoi copyrect copie tout en noir ?

  6. #26
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2017
    Messages
    344
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 344
    Par défaut
    j'ai réussi en m'inspirant de ce site : https://stackoverflow.com/questions/...different-size

    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
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    procedure TForm1.Button2Click(Sender: TObject);
    var w,h,ww,hh,i,j,k:integer;
    pimg:tpngimage;
    n:string;
    srcrect,destrect:trect;
      srcAlphaArray: pByteArray;
      destAlphaArray: pByteArray;
      x,y:integer;
    begin
      button2.hide;
      ww:=img.width;
      hh:=img.Height;
      if (ww>0) and (hh>0) then
      begin
      w:=trunc(ww/spinedit1.Value);
      h:=trunc(hh/spinedit2.Value);
      {
      ww : largeur de la grande image
      hh : hauteur de la grande image
      w : largeur des petites images
      h : hauteurs des petites images
      img : grande image
      pimg: petite image
      }
      if not directoryexists('RESULTAT') then
        createdir('RESULTAT');
      k:=0;
      n:= '/'+inttostr((trunc(ww/w))* (trunc(hh/h)));
      for I := 0 to trunc(ww/w)-1 do
      begin
        for j := 0 to trunc(hh/h)-1 do
        begin
     
          try
             inc(k);
             pimg:=tpngimage.Create;
             pimg.CreateBlank(img.Header.colortype,img.Header.bitdepth, w, h);
             pimg.CreateAlpha;
            // Remplissez le canal alpha de l'image de destination avec 0
              pimg.Canvas.CopyMode := cmSrccopy;
               // Spécifiez la région source et la région de destination
              SrcRect := Rect(i * w, j * h, (i + 1) * w, (j + 1) * h);
              DestRect := Rect(0, 0, w, h);
              pimg.Canvas.copyrect(DestRect,img.canvas, SrcRect );
              if img.TransparencyMode = ptmPartial then
              begin
                // Update destination png with tranparency data from original
                for Y := 0 to h-1 do
                begin
                  srcAlphaArray := img.AlphaScanline[Y+h*j];
                  destAlphaArray := pimg.AlphaScanline[Y];
                  for X := 0 to w-1 do
                  begin
                    destAlphaArray^[X] := srcAlphaArray^[X+w*i];
                  end;
                end;
              end;
              pimg.SaveToFile('RESULTAT\'+inttostr(k)+'.png');
              label5.Caption:=inttostr(k)+n;
              application.processmessages;
          finally
              pimg.Free;
          end;
     
        end;
      end;
      showmessage('Terminé !');
      end
      else
      showmessage('Erreur ! Image vide !');
      button2.Show;
    end;

  7. #27
    Expert confirmé
    Avatar de anapurna
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2002
    Messages
    3 479
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Mai 2002
    Messages : 3 479
    Par défaut
    salut

    Normalement tu devrais trouver un truc du genre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
      LARGIMG := ? ;
       HAUTIMG := ? ;
       FOR col := 0 To 9 do     //col
         FOR lig= 0 To 7 do // Ligne
         BEGIN 
             dest :=tpngimage.Create;
             dest.Canvas.CopyMode:=cmSrcCopy;
             dest.CreateBlank(COLOR_RGBALPHA,16, LARGIMG, HAUTIMG);
             dest.Canvas.CopyRect( Rect(0,0,LARGIMG,HAUTIMG), SRC.Canvas,Rect(col*LARGIMG,lig*HAUTIMG,(col+1)*LARGIMG,(lig+1)*HAUTIMG));
             dest.SaveToFile('RESULTAT\'+inttostr(col*9+lig+1)+'.png');
             dest.Free;  
         END;
    attention la première et la dernière image est blanche

  8. #28
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2017
    Messages
    344
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 344
    Par défaut
    non ça ne marche pas, ça ne copie pas le canal alpha donc images noires d'où mon post précédent, je peux poster mon source quelque part ?

  9. #29
    Membre très actif
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juillet 2017
    Messages
    344
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2017
    Messages : 344
    Par défaut
    la question suivante est comment importer proprement une collection d'images PNG avec transparence dans Delphi et dessiner une de celles-ci dans un TPaintBox en gardant la transparence ?

    EDIT : j'ai trouvé à travers un TImageCollection et pour dessiner :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    procedure dessineCarte(carte:tcarte;x,y:integer;echelle:double);
    begin
      form2.ImageCollection1.Draw(form2.paintbox1.Canvas, TRect.Create(x,y,round(336*echelle)+x,round(644*echelle)+y), 3, TRUE);
    end;
    avec un case géant pour toutes les tcarte à coder mais ça c'est à moi de le faire

    SUJET RESOLU

  10. #30
    Membre émérite Avatar de sergio_is_back
    Homme Profil pro
    Consultant informatique industrielle, développeur tout-terrain
    Inscrit en
    Juin 2004
    Messages
    1 183
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Consultant informatique industrielle, développeur tout-terrain
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Juin 2004
    Messages : 1 183
    Par défaut
    Citation Envoyé par Sylvain255 Voir le message
    oui ce qui serait top c'est que l'un de vous me retaille chaque carte dans un SVG séparé, me zippe le tout et le place sur le site
    Je viens juste de la voir, celle-là...
    A mourir de rire !!!

Discussions similaires

  1. [choix de techno]comment programmer un jeu de carte
    Par roilion dans le forum Général Conception Web
    Réponses: 8
    Dernier message: 16/08/2010, 16h43
  2. Programmer le jeu "OTHELLO" en Visual Basic
    Par mauriiice dans le forum VB.NET
    Réponses: 3
    Dernier message: 18/01/2007, 16h01
  3. Programmation du jeu du Mastermind
    Par Elek7 dans le forum C++
    Réponses: 2
    Dernier message: 13/06/2006, 19h53
  4. Help ! Programmer un jeu vidéo
    Par Jay Bee dans le forum DirectX
    Réponses: 7
    Dernier message: 18/03/2004, 18h38
  5. Help ! Programmer un jeu vidéo...
    Par Jay Bee dans le forum OpenGL
    Réponses: 3
    Dernier message: 05/03/2004, 15h34

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