Graphics.DrawImage, méthode (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr) (System.Drawing)

Bibliothèque de classes .NET Framework 
Graphics.DrawImage, méthode (Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics.DrawImageAbort, IntPtr) 

Dessine la partie mentionnée du Image spécifié à l'emplacement indiqué avec la taille précisée.

Espace de noms : System.Drawing
Assembly : System.Drawing (dans system.drawing.dll)

SyntaxeSyntaxe


Visual Basic (Déclaration)
Public Sub DrawImage ( _
    image As Image, _
    destRect As Rectangle, _
    srcX As Single, _
    srcY As Single, _
    srcWidth As Single, _
    srcHeight As Single, _
    srcUnit As GraphicsUnit, _
    imageAttrs As ImageAttributes, _
    callback As DrawImageAbort, _
    callbackData As IntPtr _
)


Visual Basic (Utilisation)
Dim instance As Graphics
Dim image As Image
Dim destRect As Rectangle
Dim srcX As Single
Dim srcY As Single
Dim srcWidth As Single
Dim srcHeight As Single
Dim srcUnit As GraphicsUnit
Dim imageAttrs As ImageAttributes
Dim callback As DrawImageAbort
Dim callbackData As IntPtr

instance.DrawImage(image, destRect, srcX, srcY, srcWidth, srcHeight, srcUnit, imageAttrs, callback, callbackData)


C#
public void DrawImage (
    Image image,
    Rectangle destRect,
    float srcX,
    float srcY,
    float srcWidth,
    float srcHeight,
    GraphicsUnit srcUnit,
    ImageAttributes imageAttrs,
    DrawImageAbort callback,
    IntPtr callbackData
)


C++
public:
void DrawImage (
    Image^ image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes^ imageAttrs, 
    DrawImageAbort^ callback, 
    IntPtr callbackData
)


J#
public void DrawImage (
    Image image, 
    Rectangle destRect, 
    float srcX, 
    float srcY, 
    float srcWidth, 
    float srcHeight, 
    GraphicsUnit srcUnit, 
    ImageAttributes imageAttrs, 
    DrawImageAbort callback, 
    IntPtr callbackData
)


JScript
public function DrawImage (
    image : Image, 
    destRect : Rectangle, 
    srcX : float, 
    srcY : float, 
    srcWidth : float, 
    srcHeight : float, 
    srcUnit : GraphicsUnit, 
    imageAttrs : ImageAttributes, 
    callback : DrawImageAbort, 
    callbackData : IntPtr
)

Paramètres

image

Image à dessiner.

destRect

Structure Rectangle qui spécifie l'emplacement et la taille de l'image dessinée. L'image est ajustée de manière à tenir à l'intérieur du rectangle.

srcX

Coordonnée x de l'angle supérieur gauche de la partie de l'image source à dessiner.

srcY

Coordonnée y de l'angle supérieur gauche de la partie de l'image source à dessiner.

srcWidth

Largeur de la partie de l'image source à dessiner.

srcHeight

Hauteur de la partie de l'image source à dessiner.

srcUnit

Membre de l'énumération GraphicsUnit qui spécifie les unités de mesure permettant de déterminer le rectangle source.

imageAttrs

ImageAttributes qui spécifie des informations de recoloriage et de gamma pour l'objet image.

callback

Délégué Graphics.DrawImageAbort qui spécifie une méthode à appeler lors du dessin de l'image. Cette méthode est fréquemment appelée pour vérifier si l'exécution de la méthode DrawImage doit être arrêtée selon des critères déterminés par l'application.

callbackData

Valeur spécifiant d'autres données pour le délégué Graphics.DrawImageAbort à utiliser pour vérifier si l'exécution de la méthode DrawImage doit être arrêtée.

ExceptionsExceptions
Type d'exceptionCondition

ArgumentNullException

image a la valeur référence Null (Nothing en Visual Basic).

NotesNotes

Les paramètres srcX, srcY, srcWidth et srcHeight spécifient une partie rectangulaire de l'objet image à dessiner. Le rectangle est fonction de l'angle supérieur gauche de l'image source. Cette partie est ajustée de manière à tenir à l'intérieur du rectangle spécifié par le paramètre destRect.

Cette surcharge avec les paramètres callback et callbackData permet d'arrêter le dessin d'une image qui a commencé selon des critères et des données déterminés par l'application. Si, par exemple, une application commence à dessiner une image grand format et si l'utilisateur fait défiler l'image en dehors de l'écran, l'application arrête alors le dessin.

ExempleExemple

L'exemple de code suivant est destiné à être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du gestionnaire d'événements Paint. Le code commence par définir une méthode de rappel pour le délégué Graphics.DrawImageAbort ; la définition est simpliste et se contente de vérifier si la méthode DrawImage l'appelle avec un paramètre callBackData null. Le corps de l'exemple permet d'effectuer les opérations suivantes :

  • Crée une instance de la méthode de rappel Graphics.DrawImageAbort.

  • Crée une image à partir d'un fichier JPEG, SampImag.jpg, dans le dossier de l'exemple.

  • Crée des points qui définissent un rectangle de destination dans lequel dessiner l'image.

  • Crée un rectangle source pour sélectionner la partie de l'image à dessiner.

  • Définit le pixel comme unité de dessin graphique.

  • Dessine l'image d'origine à l'écran.

  • Crée un autre rectangle de destination dans lequel dessiner une image ajustée.

  • Crée et définit les attributs de l'image ajustée pour obtenir une valeur de gamma supérieure à la normale.

  • Dessine l'image ajustée à l'écran.

Concernant le rectangle de destination non ajusté d'origine, la position situe l'image à l'écran, tandis que la taille du rectangle source et la taille et la forme du rectangle de destination déterminent la mise à l'échelle de l'image dessinée.

Comme cet exemple utilise une surcharge qui passe un paramètre callBackData, le rappel de Graphics.DrawImageAbort retourne false, ce qui provoque la poursuite de la méthode DrawImage, et l'exemple dessine l'image ajustée à l'écran.



Visual Basic
Private Function DrawImageCallback8(ByVal callBackData As IntPtr) As Boolean

    ' Test for call that passes callBackData parameter.
    If callBackData.Equals(IntPtr.Zero) Then

        ' If no callBackData passed, abort DrawImage method.
        Return True
    Else

        ' If callBackData passed, continue DrawImage method.
        Return False
    End If
End Function
Public Sub DrawImageRect4FloatAttribAbortData(ByVal e As PaintEventArgs)

    ' Create callback method.
    Dim imageCallback As New _
    Graphics.DrawImageAbort(AddressOf DrawImageCallback8)
    Dim imageCallbackData As New IntPtr(1)

    ' Create image.
    Dim newImage As Image = Image.FromFile("SampImag.jpg")

    ' Create rectangle for displaying original image.
    Dim destRect1 As New Rectangle(100, 25, 450, 150)

    ' Create coordinates of rectangle for source image.
    Dim x As Single = 50.0F
    Dim y As Single = 50.0F
    Dim width As Single = 150.0F
    Dim height As Single = 150.0F
    Dim units As GraphicsUnit = GraphicsUnit.Pixel

    ' Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, _
    height, units)

    ' Create rectangle for adjusted image.
    Dim destRect2 As New Rectangle(100, 175, 450, 150)

    ' Create image attributes and set large gamma.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetGamma(4.0F)

    ' Draw adjusted image to screen.
    Try

        ' Draw adjusted image to screen.
        e.Graphics.DrawImage(newImage, destRect2, x, y, width, _
        height, units, imageAttr, imageCallback, imageCallbackData)
    Catch ex As Exception
        e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
        Brushes.Black, New PointF(0, 0))
    End Try
End Sub


C#
// Define DrawImageAbort callback method.
private bool DrawImageCallback8(IntPtr callBackData)
{
             
    // Test for call that passes callBackData parameter.
    if(callBackData==IntPtr.Zero)
    {
             
        // If no callBackData passed, abort DrawImage method.
        return true;
    }
    else
    {
             
        // If callBackData passed, continue DrawImage method.
        return false;
    }
}
public void DrawImageRect4FloatAttribAbortData(PaintEventArgs e)
{
             
    // Create callback method.
    Graphics.DrawImageAbort imageCallback
        = new Graphics.DrawImageAbort(DrawImageCallback8);
    IntPtr imageCallbackData = new IntPtr(1);
             
    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");
             
    // Create rectangle for displaying original image.
    Rectangle destRect1 = new Rectangle(100, 25, 450, 150);
             
    // Create coordinates of rectangle for source image.
    float x = 50.0F;
    float y = 50.0F;
    float width = 150.0F;
    float height = 150.0F;
    GraphicsUnit units = GraphicsUnit.Pixel;
             
    // Draw original image to screen.
    e.Graphics.DrawImage(newImage, destRect1, x, y, width, height, units);
             
    // Create rectangle for adjusted image.
    Rectangle destRect2 = new Rectangle(100, 175, 450, 150);
             
    // Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetGamma(4.0F);
             
    // Draw adjusted image to screen.
    try
    {
        checked
        {
             
            // Draw adjusted image to screen.
            e.Graphics.DrawImage(
                newImage,
                destRect2,
                x, y,
                width, height,
                units,
                imageAttr,
                imageCallback,
                imageCallbackData);
        }
    }
    catch (Exception ex)
    {
        e.Graphics.DrawString(
            ex.ToString(),
            new Font("Arial", 8),
            Brushes.Black,
            new PointF(0, 0));
    }
}


C++
   // Define DrawImageAbort callback method.
private:
   bool DrawImageCallback8( IntPtr callBackData )
   {
      // Test for call that passes callBackData parameter.
      if ( callBackData == IntPtr::Zero )
      {
         
         // If no callBackData passed, abort DrawImage method.
         return true;
      }
      else
      {
         
         // If callBackData passed, continue DrawImage method.
         return false;
      }
   }

public:
   void DrawImageRect4FloatAttribAbortData( PaintEventArgs^ e )
   {
      // Create callback method.
      Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback8 );
      IntPtr imageCallbackData = IntPtr(1);

      // Create image.
      Image^ newImage = Image::FromFile( "SampImag.jpg" );

      // Create rectangle for displaying original image.
      Rectangle destRect1 = Rectangle(100,25,450,150);

      // Create coordinates of rectangle for source image.
      float x = 50.0F;
      float y = 50.0F;
      float width = 150.0F;
      float height = 150.0F;
      GraphicsUnit units = GraphicsUnit::Pixel;

      // Draw original image to screen.
      e->Graphics->DrawImage( newImage, destRect1, x, y, width, height, units );

      // Create rectangle for adjusted image.
      Rectangle destRect2 = Rectangle(100,175,450,150);

      // Create image attributes and set large gamma.
      ImageAttributes^ imageAttr = gcnew ImageAttributes;
      imageAttr->SetGamma( 4.0F );

      // Draw adjusted image to screen.
      try
      {
         // Draw adjusted image to screen.
         e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback, imageCallbackData );
      }
      catch ( Exception^ ex ) 
      {
         e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
      }
   }


J#
// Define DrawImageAbort callback method.
private boolean DrawImageCallback8(IntPtr callBackData) 
{    
    // Test for call that passes callBackData parameter.
    if (callBackData.Equals( IntPtr.Zero)) { 
        // If no callBackData passed, abort DrawImage method.
        return true ;
    }
    else {
        // If callBackData passed, continue DrawImage method.
        return false ;
    }
} //DrawImageCallback8

public void DrawImageRect4FloatAttribAbortData(PaintEventArgs e) 
{ 
    // Create callback method.
    Graphics.DrawImageAbort imageCallback =  new Graphics.DrawImageAbort(
        DrawImageCallback8);
    IntPtr imageCallbackData =  new IntPtr(1);

    // Create image.
    Image newImage = Image.FromFile("SampImag.jpg");

    // Create rectangle for displaying original image.
    Rectangle destRect1 =  new Rectangle(100, 25, 450, 150);

    // Create coordinates of rectangle for source image.
    float x = 50;
    float y = 50;
    float width = 150;
    float height = 150;
    GraphicsUnit units = GraphicsUnit.Pixel;

    // Draw original image to screen.
    e.get_Graphics().DrawImage(newImage, destRect1, x, y, width, height, 
        units);

    // Create rectangle for adjusted image.
    Rectangle destRect2 =  new Rectangle(100, 175, 450, 150);

    // Create image attributes and set large gamma.
    ImageAttributes imageAttr =  new ImageAttributes();
    imageAttr.SetGamma(4);

    try {
            // Draw adjusted image to screen.
        e.get_Graphics().DrawImage(newImage, destRect2, x, y, width,
            height, units, imageAttr, imageCallback, imageCallbackData);
    }
    catch(System.Exception  ex) {    
        e.get_Graphics().DrawString(ex.ToString(), new Font("Arial", 8), 
            Brushes.get_Black(), new PointF(0, 0));
    }
} //DrawImageRect4FloatAttribAbortData
Plates-formesPlates-formes

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

Informations de versionInformations de version

.NET Framework

Prise en charge dans : 2.0, 1.1, 1.0
Voir aussiVoir aussi

Ces informations proviennent du site de http://msdn2.microsoft.com
Source de cette page : http://msdn2.microsoft.com/fr-fr/library/6e89s0wc.aspx

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

15 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-6981
Document créé le 08/11/06 00:20, dernière modification le Vendredi 17 Juin 2011, 12:11
Source du document imprimé : http://www.gaudry.be/dotnet-rf-6e89s0wc.html Document affiché 5 fois ce mois de Mai.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,77 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Quand on tape Chuck Norris sur Google, le bouton "j'ai de la chance" disparaît...

Anonyme [Chuck Norris fact]
 
l'infobrol
Nous sommes le Jeudi 31 Mai 2012, 00:44, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)