Assembly : System.Drawing (dans system.drawing.dll)
SyntaxePublic Sub DrawImage ( _ image As Image, _ destPoints As PointF(), _ srcRect As RectangleF, _ srcUnit As GraphicsUnit, _ imageAttr As ImageAttributes, _ callback As DrawImageAbort _ )
Dim instance As Graphics Dim image As Image Dim destPoints As PointF() Dim srcRect As RectangleF Dim srcUnit As GraphicsUnit Dim imageAttr As ImageAttributes Dim callback As DrawImageAbort instance.DrawImage(image, destPoints, srcRect, srcUnit, imageAttr, callback)
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback )
public: void DrawImage ( Image^ image, array<PointF>^ destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes^ imageAttr, DrawImageAbort^ callback )
public void DrawImage ( Image image, PointF[] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback )
public function DrawImage ( image : Image, destPoints : PointF[], srcRect : RectangleF, srcUnit : GraphicsUnit, imageAttr : ImageAttributes, callback : DrawImageAbort )
Paramètres
- image
Image à dessiner.
- destPoints
Tableau de trois structures PointF qui définissent un parallélogramme.
- srcRect
Structure RectangleF qui spécifie la partie de l'objet image à dessiner.
- srcUnit
Membre de l'énumération GraphicsUnit qui spécifie les unités de mesure utilisées par le paramètre srcRect.
- imageAttr
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.
NotesLe paramètre destPoints spécifie trois points d'un parallélogramme. Les trois structures PointF représentent les angles supérieur gauche, supérieur droit et inférieur gauche du parallélogramme. Le quatrième point est extrapolé à partir des trois premiers pour former un parallélogramme.
Le paramètre srcRect spécifie une partie rectangulaire de l'objet image à dessiner. Cette partie est ajustée et inclinée de manière à tenir à l'intérieur du parallélogramme spécifié par le paramètre destPoints.
Cette surcharge avec le paramètre callback permet d'arrêter le dessin d'une image qui a commencé selon des critères 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.
ExempleL'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 parallélogramme dans lequel dessiner l'image.
-
Crée un rectangle 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 parallélogramme 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 parallélogramme d'origine non ajusté, la position situe l'image à l'écran, tandis que la taille du rectangle et la taille et la forme du parallélogramme déterminent la mise à l'échelle et l'inclinaison de l'image dessinée.
Comme cet exemple utilise une surcharge qui ne passe pas de paramètre callBackData, le rappel de Graphics.DrawImageAbort retourne true, ce qui provoque l'arrêt de la méthode DrawImage, et le code de gestion des exceptions figurant dans l'exemple imprime le texte de l'exception au lieu de dessiner l'image.
Private Function DrawImageCallback3(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 DrawImageParaFRectAttribAbort(ByVal e As PaintEventArgs) ' Create callback method. Dim imageCallback As New _ Graphics.DrawImageAbort(AddressOf DrawImageCallback3) ' Create image. Dim newImage As Image = Image.FromFile("SampImag.jpg") ' Create parallelogram for drawing original image. Dim ulCorner1 As New PointF(100.0F, 100.0F) Dim urCorner1 As New PointF(325.0F, 100.0F) Dim llCorner1 As New PointF(150.0F, 250.0F) Dim destPara1 As PointF() = {ulCorner1, urCorner1, llCorner1} ' Create rectangle for source image. Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F) Dim units As GraphicsUnit = GraphicsUnit.Pixel ' Create parallelogram for drawing adjusted image. Dim ulCorner2 As New PointF(325.0F, 100.0F) Dim urCorner2 As New PointF(550.0F, 100.0F) Dim llCorner2 As New PointF(375.0F, 250.0F) Dim destPara2 As PointF() = {ulCorner2, urCorner2, llCorner2} ' Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units) ' Create image attributes and set large gamma. Dim imageAttr As New ImageAttributes imageAttr.SetGamma(4.0F) Try ' Draw adjusted image to screen. e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _ imageAttr, imageCallback) Catch ex As Exception e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _ Brushes.Black, New PointF(0, 0)) End Try End Sub
// Define DrawImageAbort callback method. private bool DrawImageCallback3(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 DrawImageParaFRectAttribAbort(PaintEventArgs e) { // Create callback method. Graphics.DrawImageAbort imageCallback = new Graphics.DrawImageAbort(DrawImageCallback3); // Create image. Image newImage = Image.FromFile("SampImag.jpg"); // Create parallelogram for drawing original image. PointF ulCorner1 = new PointF(100.0F, 100.0F); PointF urCorner1 = new PointF(325.0F, 100.0F); PointF llCorner1 = new PointF(150.0F, 250.0F); PointF[] destPara1 = {ulCorner1, urCorner1, llCorner1}; // Create rectangle for source image. RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F); GraphicsUnit units = GraphicsUnit.Pixel; // Create parallelogram for drawing adjusted image. PointF ulCorner2 = new PointF(325.0F, 100.0F); PointF urCorner2 = new PointF(550.0F, 100.0F); PointF llCorner2 = new PointF(375.0F, 250.0F); PointF[] destPara2 = {ulCorner2, urCorner2, llCorner2}; // Draw original image to screen. e.Graphics.DrawImage(newImage, destPara1, srcRect, units); // Create image attributes and set large gamma. ImageAttributes imageAttr = new ImageAttributes(); imageAttr.SetGamma(4.0F); try { checked { // Draw adjusted image to screen. e.Graphics.DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback); } } catch (Exception ex) { e.Graphics.DrawString( ex.ToString(), new Font("Arial", 8), Brushes.Black, new PointF(0, 0)); } }
// Define DrawImageAbort callback method. private: bool DrawImageCallback3( 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 DrawImageParaFRectAttribAbort( PaintEventArgs^ e ) { // Create callback method. Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback3 ); // Create image. Image^ newImage = Image::FromFile( "SampImag.jpg" ); // Create parallelogram for drawing original image. PointF ulCorner1 = PointF(100.0F,100.0F); PointF urCorner1 = PointF(325.0F,100.0F); PointF llCorner1 = PointF(150.0F,250.0F); array<PointF>^ destPara1 = {ulCorner1,urCorner1,llCorner1}; // Create rectangle for source image. RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F); GraphicsUnit units = GraphicsUnit::Pixel; // Create parallelogram for drawing adjusted image. PointF ulCorner2 = PointF(325.0F,100.0F); PointF urCorner2 = PointF(550.0F,100.0F); PointF llCorner2 = PointF(375.0F,250.0F); array<PointF>^ destPara2 = {ulCorner2,urCorner2,llCorner2}; // Draw original image to screen. e->Graphics->DrawImage( newImage, destPara1, srcRect, units ); // Create image attributes and set large gamma. ImageAttributes^ imageAttr = gcnew ImageAttributes; imageAttr->SetGamma( 4.0F ); try { // Draw adjusted image to screen. e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback ); } catch ( Exception^ ex ) { e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) ); } }
Plates-formesWindows 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.
Voir aussiRéférence
Graphics, classeMembres Graphics
System.Drawing, espace de noms
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ