Graphics.DrawImage Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Disegna l'oggetto Image specificato nella posizione indicata e con le dimensioni originali.
Overload
DrawImage(Image, Single, Single, RectangleF, GraphicsUnit) |
Disegna una parte di un'immagine nella posizione specifica. |
DrawImage(Image, Effect, RectangleF, Matrix, GraphicsUnit, ImageAttributes) | |
DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Int32, Int32, Int32, Int32) |
Disegna l'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Single, Single, Single, Single) |
Disegna l'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Effect) | |
DrawImage(Image, Point) |
Disegna l'oggetto Image specificato usando le dimensioni originali, nella posizione indicata. |
DrawImage(Image, Point[]) |
Disegna l'oggetto Image specificato nella posizione indicata e con la forma e le dimensioni specificate. |
DrawImage(Image, PointF) |
Disegna l'oggetto Image specificato usando le dimensioni originali, nella posizione indicata. |
DrawImage(Image, PointF[]) |
Disegna l'oggetto Image specificato nella posizione indicata e con la forma e le dimensioni specificate. |
DrawImage(Image, Rectangle) |
Disegna l'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, RectangleF) |
Disegna l'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Int32, Int32, Rectangle, GraphicsUnit) |
Disegna una parte di un'immagine nella posizione specifica. |
DrawImage(Image, Single, Single) |
Disegna l'oggetto Image specificato usando le dimensioni originali, nella posizione indicata. |
DrawImage(Image, Point[], Rectangle, GraphicsUnit) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, PointF[], RectangleF, GraphicsUnit) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Rectangle, Rectangle, GraphicsUnit) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, RectangleF, RectangleF, GraphicsUnit) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate. |
DrawImage(Image, Int32, Int32) |
Disegna l'immagine specificata usando le dimensioni fisiche originali nella posizione indicata da una coppia di coordinate. |
DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes) |
Disegna la parte specificata dell'oggetto Image specificato nella posizione indicata. |
DrawImage(Image, Single, Single, RectangleF, GraphicsUnit)
Disegna una parte di un'immagine nella posizione specifica.
public:
void DrawImage(System::Drawing::Image ^ image, float x, float y, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, float x, float y, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * single * single * System.Drawing.RectangleF * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, x As Single, y As Single, srcRect As RectangleF, srcUnit As GraphicsUnit)
Parametri
- x
- Single
Coordinata X dell'angolo superiore sinistro dell'immagine disegnata.
- y
- Single
Coordinata Y dell'angolo superiore sinistro dell'immagine disegnata.
- srcRect
- RectangleF
Struttura RectangleF che specifica la parte dell'oggetto Image da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea le coordinate in corrispondenza della quale disegnare l'angolo superiore sinistro dell'immagine.
Crea un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine sullo schermo.
Le dimensioni del rettangolo di origine determinano la parte dell'immagine originale non ridimensionata sullo schermo.
public:
void DrawImage2FloatRectF( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create coordinates for upper-left corner of image.
float x = 100.0F;
float y = 100.0F;
// Create rectangle for source image.
RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F);
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw image to screen.
e->Graphics->DrawImage( newImage, x, y, srcRect, units );
}
public void DrawImage2FloatRectF(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create coordinates for upper-left corner of image.
float x = 100.0F;
float y = 100.0F;
// Create rectangle for source image.
RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw image to screen.
e.Graphics.DrawImage(newImage, x, y, srcRect, units);
}
Public Sub DrawImage2FloatRectF(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create coordinates for upper-left corner of image.
Dim x As Single = 100.0F
Dim y As Single = 100.0F
' Create rectangle for source image.
Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw image to screen.
e.Graphics.DrawImage(newImage, x, y, srcRect, units)
End Sub
Commenti
Un Image oggetto archivia un valore per la larghezza dei pixel e un valore per la risoluzione orizzontale (punti per pollice). La larghezza fisica, misurata in pollici, di un'immagine è la larghezza di pixel divisa dalla risoluzione orizzontale. Ad esempio, un'immagine con larghezza pixel di 360 e una risoluzione orizzontale di 72 punti per pollice ha una larghezza fisica di 5 pollici. Le osservazioni simili si applicano all'altezza dei pixel e all'altezza fisica.
Questo metodo disegna una parte di un'immagine usando le dimensioni fisiche, quindi la parte dell'immagine avrà le dimensioni corrette in pollici indipendentemente dalla risoluzione (punti per pollice) del dispositivo di visualizzazione. Si supponga, ad esempio, che una parte dell'immagine abbia una larghezza di pixel pari a 216 e una risoluzione orizzontale di 72 punti per pollice. Se si chiama questo metodo per disegnare tale parte dell'immagine in un dispositivo con una risoluzione di 96 punti per pollice, la larghezza dei pixel della parte dell'immagine di cui è stato eseguito il rendering sarà (216/72)*96 = 288.
Vedi anche
Si applica a
DrawImage(Image, Effect, RectangleF, Matrix, GraphicsUnit, ImageAttributes)
public void DrawImage (System.Drawing.Image image, System.Drawing.Imaging.Effects.Effect effect, System.Drawing.RectangleF srcRect = default, System.Drawing.Drawing2D.Matrix? transform = default, System.Drawing.GraphicsUnit srcUnit = System.Drawing.GraphicsUnit.Pixel, System.Drawing.Imaging.ImageAttributes? imageAttr = default);
member this.DrawImage : System.Drawing.Image * System.Drawing.Imaging.Effects.Effect * System.Drawing.RectangleF * System.Drawing.Drawing2D.Matrix * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
Public Sub DrawImage (image As Image, effect As Effect, Optional srcRect As RectangleF = Nothing, Optional transform As Matrix = Nothing, Optional srcUnit As GraphicsUnit = System.Drawing.GraphicsUnit.Pixel, Optional imageAttr As ImageAttributes = Nothing)
Parametri
- image
- Image
- effect
- Effect
- srcRect
- RectangleF
- transform
- Matrix
- srcUnit
- GraphicsUnit
- imageAttr
- ImageAttributes
Si applica a
DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit
Public Sub DrawImage (image As Image, destPoints As Point(), srcRect As Rectangle, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort)
Parametri
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
- imageAttr
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
- callback
- Graphics.DrawImageAbort
Delegato Graphics.DrawImageAbort che specifica un metodo da chiamare durante il disegno dell'immagine. Questo metodo viene chiamato frequentemente per controllare se sia necessario interrompere l'esecuzione del metodo DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) secondo i criteri determinati dall'applicazione.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice definisce prima un metodo di callback per il Graphics.DrawImageAbort delegato. La definizione è semplicistica e verifica semplicemente se il DrawImage metodo lo chiama con un parametro Null callBackData
. Il corpo principale dell'esempio esegue le azioni seguenti:
Crea un'istanza Graphics.DrawImageAbort del metodo di callback:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma in cui disegnare l'immagine.
Crea un rettangolo per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine originale sullo schermo.
Crea un parallelogramma aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per l'originale, parallelogramma non modificato, la posizione individua l'immagine sullo schermo e le dimensioni del rettangolo e la dimensione e la forma del parallelogramma determina il ridimensionamento e l'shearing dell'immagine disegnata.
Poiché questo esempio usa un overload che non passa un callBackData
parametro, il callback restituisce true
, che causa DrawImage la fine del metodo e il Graphics.DrawImageAbort codice di gestione delle eccezioni incluso nell'esempio stampa il testo dell'eccezione anziché disegnare l'immagine.
// Define DrawImageAbort callback method.
private:
bool DrawImageCallback1( 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;
}
}
private:
void DrawImageParaRectAttribAbort( PaintEventArgs^ e )
{
// Create callback method.
Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback1 );
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create parallelogram for drawing original image.
Point ulCorner = Point(100,100);
Point urCorner = Point(550,100);
Point llCorner = Point(150,250);
array<Point>^ destPara1 = {ulCorner,urCorner,llCorner};
// Create rectangle for source image.
Rectangle srcRect = Rectangle(50,50,150,150);
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw original image to screen.
e->Graphics->DrawImage( newImage, destPara1, srcRect, units );
// Create parallelogram for drawing adjusted image.
Point ulCorner2 = Point(325,100);
Point urCorner2 = Point(550,100);
Point llCorner2 = Point(375,250);
array<Point>^ destPara2 = {ulCorner2,urCorner2,llCorner2};
// Create image attributes and set large gamma.
ImageAttributes^ imageAttr = gcnew ImageAttributes;
imageAttr->SetGamma( 4.0F );
try
{
// Draw 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) );
}
}
// Define DrawImageAbort callback method.
private bool DrawImageCallback1(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;
}
}
private void DrawImageParaRectAttribAbort(PaintEventArgs e)
{
// Create callback method.
Graphics.DrawImageAbort imageCallback
= new Graphics.DrawImageAbort(DrawImageCallback1);
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create parallelogram for drawing original image.
Point ulCorner = new Point(100, 100);
Point urCorner = new Point(550, 100);
Point llCorner = new Point(150, 250);
Point[] destPara1 = {ulCorner, urCorner, llCorner};
// Create rectangle for source image.
Rectangle srcRect = new Rectangle(50, 50, 150, 150);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw original image to screen.
e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
// Create parallelogram for drawing adjusted image.
Point ulCorner2 = new Point(325, 100);
Point urCorner2 = new Point(550, 100);
Point llCorner2 = new Point(375, 250);
Point[] destPara2 = {ulCorner2, urCorner2, llCorner2};
// Create image attributes and set large gamma.
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetGamma(4.0F);
try
{
checked
{
// Draw 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));
}
}
Private Function DrawImageCallback1(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
Private Sub DrawImageParaRectAttribAbort(ByVal e As PaintEventArgs)
' Create callback method.
Dim imageCallback As New _
Graphics.DrawImageAbort(AddressOf DrawImageCallback1)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create parallelogram for drawing original image.
Dim ulCorner As New Point(100, 100)
Dim urCorner As New Point(550, 100)
Dim llCorner As New Point(150, 250)
Dim destPara1 As Point() = {ulCorner, urCorner, llCorner}
' Create rectangle for source image.
Dim srcRect As New Rectangle(50, 50, 150, 150)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw original image to screen.
e.Graphics.DrawImage(newImage, destPara1, srcRect, units)
' Create parallelogram for drawing adjusted image.
Dim ulCorner2 As New Point(325, 100)
Dim urCorner2 As New Point(550, 100)
Dim llCorner2 As New Point(375, 250)
Dim destPara2 As Point() = {ulCorner2, urCorner2, llCorner2}
' Create image attributes and set large gamma.
Dim imageAttr As New ImageAttributes
imageAttr.SetGamma(4.0F)
Try
' Draw 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
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre PointF strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dal primo tre per formare un parallelogramma.
Il srcRect
parametro specifica una parte rettangolare dell'oggetto image
da disegnare. Questa porzione viene ridimensionata e viene ridimensionata per adattarsi all'interno del destPoints
parallelogramma specificato dal parametro.
Questo overload con il callback
parametro fornisce i mezzi per arrestare il disegno di un'immagine dopo l'avvio in base ai criteri determinati dall'applicazione. Ad esempio, un'applicazione potrebbe avviare il disegno di un'immagine di grandi dimensioni e l'utente potrebbe scorrere l'immagine dalla schermata, in questo caso l'applicazione potrebbe arrestare il disegno.
Vedi anche
Si applica a
DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit
Public Sub DrawImage (image As Image, destPoints As PointF(), srcRect As RectangleF, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort)
Parametri
- srcRect
- RectangleF
Struttura RectangleF che specifica la parte dell'oggetto image
da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
- imageAttr
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
- callback
- Graphics.DrawImageAbort
Delegato Graphics.DrawImageAbort che specifica un metodo da chiamare durante il disegno dell'immagine. Questo metodo viene chiamato frequentemente per controllare se sia necessario interrompere l'esecuzione del metodo DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) secondo i criteri determinati dall'applicazione.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice definisce prima un metodo di callback per il Graphics.DrawImageAbort delegato. La definizione è semplicistica e verifica semplicemente se il DrawImage metodo lo chiama con un parametro Null callBackData
. Il corpo principale dell'esempio esegue le azioni seguenti:
Crea un'istanza del Graphics.DrawImageAbort metodo di callback.
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma in cui disegnare l'immagine.
Crea un rettangolo per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine originale sullo schermo.
Crea un parallelogramma aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per l'originale, parallelogramma non modificato, la posizione individua l'immagine sullo schermo e le dimensioni del rettangolo e la dimensione e la forma del parallelogramma determina il ridimensionamento e l'shearing dell'immagine disegnata.
Poiché questo esempio usa un overload che non passa un callBackData
parametro, il callback restituisce true
, che causa DrawImage la fine del metodo e il Graphics.DrawImageAbort codice di gestione delle eccezioni incluso nell'esempio stampa il testo dell'eccezione anziché disegnare l'immagine.
// 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;
}
}
private:
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) );
}
}
// 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;
}
}
private 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));
}
}
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
Private 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
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre PointF strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dal primo tre per formare un parallelogramma.
Il srcRect
parametro specifica una parte rettangolare dell'oggetto image
da disegnare. Questa porzione viene ridimensionata e viene ridimensionata per adattarsi all'interno del destPoints
parallelogramma specificato dal parametro.
Questo overload con il callback
parametro fornisce i mezzi per arrestare il disegno di un'immagine dopo l'avvio in base ai criteri determinati dall'applicazione. Ad esempio, un'applicazione potrebbe avviare il disegno di un'immagine di grandi dimensioni e l'utente potrebbe scorrere l'immagine dalla schermata, in questo caso l'applicazione potrebbe arrestare il disegno.
Vedi anche
Si applica a
DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback, int callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback, int callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback, int callbackData);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort * int -> unit
Public Sub DrawImage (image As Image, destPoints As Point(), srcRect As Rectangle, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort, callbackData As Integer)
Parametri
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
- imageAttr
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
- callback
- Graphics.DrawImageAbort
Delegato Graphics.DrawImageAbort che specifica un metodo da chiamare durante il disegno dell'immagine. Questo metodo viene chiamato frequentemente per controllare se sia necessario interrompere l'esecuzione del metodo DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) secondo i criteri determinati dall'applicazione.
- callbackData
- Int32
Valore che specifica ulteriori dati per il delegato Graphics.DrawImageAbort da usare quando si verifica se interrompere l'esecuzione del metodo DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32).
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice definisce prima un metodo di callback per il Graphics.DrawImageAbort delegato. La definizione è semplicistica e verifica semplicemente se il DrawImage metodo lo chiama con un parametro Null callBackData
. Il corpo principale dell'esempio esegue le azioni seguenti:
Crea un'istanza del Graphics.DrawImageAbort metodo di callback.
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma in cui disegnare l'immagine.
Crea un rettangolo per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine originale sullo schermo.
Crea un parallelogramma aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per l'originale, parallelogramma non modificato, la posizione individua l'immagine sullo schermo e le dimensioni del rettangolo e la dimensione e la forma del parallelogramma determina il ridimensionamento e l'shearing dell'immagine disegnata.
Poiché in questo esempio viene usato un overload che passa un callBackData
parametro, il Graphics.DrawImageAbortDrawImage callback restituisce false
, che causa la continuazione del metodo e l'esempio disegna l'immagine modificata sullo schermo.
// Define DrawImageAbort callback method.
private:
bool DrawImageCallback2( 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;
}
}
private:
void DrawImageParaRectAttribAbortData( PaintEventArgs^ e )
{
// Create callback method.
Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback2 );
int imageCallbackData = 1;
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create parallelogram for drawing original image.
Point ulCorner = Point(100,100);
Point urCorner = Point(550,100);
Point llCorner = Point(150,250);
array<Point>^ destPara1 = {ulCorner,urCorner,llCorner};
// Create rectangle for source image.
Rectangle srcRect = Rectangle(50,50,150,150);
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw original image to screen.
e->Graphics->DrawImage( newImage, destPara1, srcRect, units );
// Create parallelogram for drawing adjusted image.
Point ulCorner2 = Point(325,100);
Point urCorner2 = Point(550,100);
Point llCorner2 = Point(375,250);
array<Point>^ destPara2 = {ulCorner2,urCorner2,llCorner2};
// Create image attributes and set large gamma.
ImageAttributes^ imageAttr = gcnew ImageAttributes;
imageAttr->SetGamma( 4.0F );
try
{
// Draw image to screen.
e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr, imageCallback, imageCallbackData );
}
catch ( Exception^ ex )
{
e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
}
}
// Define DrawImageAbort callback method.
private bool DrawImageCallback2(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;
}
}
private void DrawImageParaRectAttribAbortData(PaintEventArgs e)
{
// Create callback method.
Graphics.DrawImageAbort imageCallback
= new Graphics.DrawImageAbort(DrawImageCallback2);
int imageCallbackData = 1;
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create parallelogram for drawing original image.
Point ulCorner = new Point(100, 100);
Point urCorner = new Point(550, 100);
Point llCorner = new Point(150, 250);
Point[] destPara1 = {ulCorner, urCorner, llCorner};
// Create rectangle for source image.
Rectangle srcRect = new Rectangle(50, 50, 150, 150);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw original image to screen.
e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
// Create parallelogram for drawing adjusted image.
Point ulCorner2 = new Point(325, 100);
Point urCorner2 = new Point(550, 100);
Point llCorner2 = new Point(375, 250);
Point[] destPara2 = {ulCorner2, urCorner2, llCorner2};
// Create image attributes and set large gamma.
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetGamma(4.0F);
try
{
checked
{
// Draw image to screen.
e.Graphics.DrawImage(
newImage,
destPara2,
srcRect,
units,
imageAttr,
imageCallback,
imageCallbackData);
}
}
catch (Exception ex)
{
e.Graphics.DrawString(
ex.ToString(),
new Font("Arial", 8),
Brushes.Black,
new PointF(0, 0));
}
}
Private Function DrawImageCallback2(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
Private Sub DrawImageParaRectAttribAbortData(ByVal e As PaintEventArgs)
' Create callback method.
Dim imageCallback As New _
Graphics.DrawImageAbort(AddressOf DrawImageCallback2)
Dim imageCallbackData As Integer = 1
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create parallelogram for drawing original image.
Dim ulCorner As New Point(100, 100)
Dim urCorner As New Point(550, 100)
Dim llCorner As New Point(150, 250)
Dim destPara1 As Point() = {ulCorner, urCorner, llCorner}
' Create rectangle for source image.
Dim srcRect As New Rectangle(50, 50, 150, 150)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw original image to screen.
e.Graphics.DrawImage(newImage, destPara1, srcRect, units)
' Create parallelogram for drawing adjusted image.
Dim ulCorner2 As New Point(325, 100)
Dim urCorner2 As New Point(550, 100)
Dim llCorner2 As New Point(375, 250)
Dim destPara2 As Point() = {ulCorner2, urCorner2, llCorner2}
' Create image attributes and set large gamma.
Dim imageAttr As New ImageAttributes
imageAttr.SetGamma(4.0F)
Try
' Draw image to screen.
e.Graphics.DrawImage(newImage, destPara2, srcRect, 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
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre PointF strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dal primo tre per formare un parallelogramma.
Il srcRect
parametro specifica una parte rettangolare dell'oggetto image
da disegnare. Questa porzione viene ridimensionata e viene ridimensionata per adattarsi all'interno del destPoints
parallelogramma specificato dal parametro.
Questo overload con i callback
parametri e callbackData
fornisce i mezzi per arrestare il disegno di un'immagine dopo l'avvio in base ai criteri e ai dati determinati dall'applicazione. Ad esempio, un'applicazione potrebbe avviare il disegno di un'immagine di grandi dimensioni e l'utente potrebbe scorrere l'immagine dalla schermata, in questo caso l'applicazione potrebbe arrestare il disegno.
Vedi anche
Si applica a
DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback, int callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback, int callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback, int callbackData);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort * int -> unit
Public Sub DrawImage (image As Image, destPoints As PointF(), srcRect As RectangleF, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort, callbackData As Integer)
Parametri
- srcRect
- RectangleF
Struttura RectangleF che specifica la parte dell'oggetto image
da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
- imageAttr
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
- callback
- Graphics.DrawImageAbort
Delegato Graphics.DrawImageAbort che specifica un metodo da chiamare durante il disegno dell'immagine. Questo metodo viene chiamato frequentemente per controllare se sia necessario interrompere l'esecuzione del metodo DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32) secondo i criteri determinati dall'applicazione.
- callbackData
- Int32
Valore che specifica ulteriori dati per il delegato Graphics.DrawImageAbort da usare quando si verifica se interrompere l'esecuzione del metodo DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, Int32).
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Pa
Paint gestore eventi. Il codice definisce prima un metodo di callback per il Graphics.DrawImageAbort delegato. La definizione è semplicistica e verifica semplicemente se il DrawImage metodo lo chiama con un parametro Null callBackData
. Il corpo principale dell'esempio esegue le azioni seguenti:
Crea un'istanza del Graphics.DrawImageAbort metodo di callback.
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma in cui disegnare l'immagine.
Crea un rettangolo per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine originale sullo schermo.
Crea un parallelogramma aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per l'originale, parallelogramma non modificato, la posizione individua l'immagine sullo schermo e le dimensioni del rettangolo e la dimensione e la forma del parallelogramma determina il ridimensionamento e l'shearing dell'immagine disegnata.
Poiché in questo esempio viene usato un overload che passa un callBackData
parametro, il Graphics.DrawImageAbortDrawImage callback restituisce false
, che causa la continuazione del metodo e l'esempio disegna l'immagine modificata sullo schermo.
// Define DrawImageAbort callback method.
private:
bool DrawImageCallback4( 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;
}
}
private:
void DrawImageParaFRectAttribAbortData( PaintEventArgs^ e )
{
// Create callback method.
Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback4 );
int imageCallbackData = 1;
// 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, imageCallbackData );
}
catch ( Exception^ ex )
{
e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
}
}
// Define DrawImageAbort callback method.
private bool DrawImageCallback4(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;
}
}
private void DrawImageParaFRectAttribAbortData(PaintEventArgs e)
{
// Create callback method.
Graphics.DrawImageAbort imageCallback
= new Graphics.DrawImageAbort(DrawImageCallback4);
int imageCallbackData = 1;
// 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,
imageCallbackData);
}
}
catch (Exception ex)
{
e.Graphics.DrawString(
ex.ToString(),
new Font("Arial", 8),
Brushes.Black,
new PointF(0, 0));
}
}
Private Function DrawImageCallback4(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
Private Sub DrawImageParaFRectAttribAbortData(ByVal e As PaintEventArgs)
' Create callback method.
Dim imageCallback As New _
Graphics.DrawImageAbort(AddressOf DrawImageCallback4)
Dim imageCallbackData As Integer = 1
' 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, imageCallbackData)
Catch ex As Exception
e.Graphics.DrawString(ex.ToString(), New Font("Arial", 8), _
Brushes.Black, New PointF(0, 0))
End Try
End Sub
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre PointF strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dal primo tre per formare un parallelogramma.
Il srcRect
parametro specifica una parte rettangolare dell'oggetto image
da disegnare. Questa porzione viene ridimensionata e viene ridimensionata per adattarsi all'interno del destPoints
parallelogramma specificato dal parametro.
Questo overload con i callback
parametri e callbackData
fornisce i mezzi per arrestare il disegno di un'immagine dopo l'avvio in base ai criteri e ai dati determinati dall'applicazione. Ad esempio, un'applicazione potrebbe avviare il disegno di un'immagine di grandi dimensioni e l'utente potrebbe scorrere l'immagine dalla schermata, in questo caso l'applicazione potrebbe arrestare il disegno.
Vedi anche
Si applica a
DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * int * int * int * int * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Integer, srcY As Integer, srcWidth As Integer, srcHeight As Integer, srcUnit As GraphicsUnit)
Parametri
- destRect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcX
- Int32
Coordinata X dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcY
- Int32
Coordinata Y dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcWidth
- Int32
Larghezza della parte dell'immagine di origine da disegnare.
- srcHeight
- Int32
Altezza della parte dell'immagine di origine da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate per determinare il rettangolo di origine.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea un rettangolo di destinazione in cui disegnare l'immagine.
Crea le coordinate di un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine sullo schermo.
La posizione del rettangolo di destinazione individua l'immagine sullo schermo e le dimensioni dei rettangoli di origine e di destinazione determinano il ridimensionamento dell'immagine disegnata e le dimensioni del rettangolo di origine determinano la parte dell'immagine originale sullo schermo.
void DrawImageRect4Int( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create rectangle for displaying image.
Rectangle destRect = Rectangle(100,100,450,150);
// Create coordinates of rectangle for source image.
int x = 50;
int y = 50;
int width = 150;
int height = 150;
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw image to screen.
e->Graphics->DrawImage( newImage, destRect, x, y, width, height, units );
}
private void DrawImageRect4Int(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create rectangle for displaying image.
Rectangle destRect = new Rectangle(100, 100, 450, 150);
// Create coordinates of rectangle for source image.
int x = 50;
int y = 50;
int width = 150;
int height = 150;
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw image to screen.
e.Graphics.DrawImage(newImage, destRect, x, y, width, height, units);
}
Private Sub DrawImageRect4Int(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create rectangle for displaying image.
Dim destRect As New Rectangle(100, 100, 450, 150)
' Create coordinates of rectangle for source image.
Dim x As Integer = 50
Dim y As Integer = 50
Dim width As Integer = 150
Dim height As Integer = 150
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw image to screen.
e.Graphics.DrawImage(newImage, destRect, x, y, width, height, _
units)
End Sub
Commenti
I srcX
parametri , srcY
, srcWidth
e srcHeight
specificano una parte rettangolare dell'oggetto image
da disegnare. Il rettangolo è relativo all'angolo superiore sinistro dell'immagine di origine. Questa parte viene ridimensionata per adattarsi al rettangolo specificato dal destRect
parametro.
Vedi anche
Si applica a
DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * int * int * int * int * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Integer, srcY As Integer, srcWidth As Integer, srcHeight As Integer, srcUnit As GraphicsUnit, imageAttr As ImageAttributes)
Parametri
- destRect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcX
- Int32
Coordinata X dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcY
- Int32
Coordinata Y dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcWidth
- Int32
Larghezza della parte dell'immagine di origine da disegnare.
- srcHeight
- Int32
Altezza della parte dell'immagine di origine da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate per determinare il rettangolo di origine.
- imageAttr
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea un rettangolo di destinazione in cui disegnare l'immagine.
Crea le coordinate di un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine originale sullo schermo.
Crea un rettangolo aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per il rettangolo di destinazione originale, non modificato, la posizione individua l'immagine sullo schermo e le dimensioni dei rettangoli di origine e di destinazione determinano il ridimensionamento dell'immagine disegnata e le dimensioni del rettangolo di origine determinano la parte dell'immagine originale sullo schermo.
void DrawImageRect4IntAtrrib( PaintEventArgs^ e )
{
// 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.
int x = 50;
int y = 50;
int width = 150;
int height = 150;
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.
e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr );
}
private void DrawImageRect4IntAtrrib(PaintEventArgs e)
{
// 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.
int x = 50;
int y = 50;
int width = 150;
int height = 150;
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.
e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, units, imageAttr);
}
Private Sub DrawImageRect4IntAtrrib(ByVal e As PaintEventArgs)
' 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 Integer = 50
Dim y As Integer = 50
Dim width As Integer = 150
Dim height As Integer = 150
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.
e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, _
units, imageAttr)
End Sub
Commenti
I srcX
parametri , srcY
, srcWidth
e srcHeight
specificano una parte rettangolare dell'oggetto image
da disegnare. Il rettangolo è relativo all'angolo superiore sinistro dell'immagine di origine. Questa parte viene ridimensionata per adattarsi al rettangolo specificato dal destRect
parametro.
Vedi anche
Si applica a
DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttrs);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * single * single * single * single * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
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)
Parametri
- destRect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcX
- Single
Coordinata X dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcY
- Single
Coordinata Y dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcWidth
- Single
Larghezza della parte dell'immagine di origine da disegnare.
- srcHeight
- Single
Altezza della parte dell'immagine di origine da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate per determinare il rettangolo di origine.
- imageAttrs
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea un rettangolo di destinazione in cui disegnare l'immagine.
Crea le coordinate di un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine originale sullo schermo.
Crea un rettangolo aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per il rettangolo di destinazione originale, non modificato, la posizione individua l'immagine sullo schermo e le dimensioni dei rettangoli di origine e di destinazione determinano il ridimensionamento dell'immagine disegnata e le dimensioni del rettangolo di origine determinano la parte dell'immagine originale sullo schermo.
private:
void DrawImageRect4FloatAttrib( PaintEventArgs^ e )
{
// 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.
e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr );
}
private void DrawImageRect4FloatAttrib(PaintEventArgs e)
{
// 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.
e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, units, imageAttr);
}
Private Sub DrawImageRect4FloatAttrib(ByVal e As PaintEventArgs)
' 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.
e.Graphics.DrawImage(newImage, destRect2, x, y, width, height, _
units, imageAttr)
End Sub
Commenti
I srcX
parametri , srcY
, srcWidth
e srcHeight
specificano una parte rettangolare dell'oggetto image
da disegnare. Il rettangolo è relativo all'angolo superiore sinistro dell'immagine di origine. Questa parte viene ridimensionata per adattarsi al rettangolo specificato dal destRect
parametro.
Vedi anche
Si applica a
DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr, System::Drawing::Graphics::DrawImageAbort ^ callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr, System.Drawing.Graphics.DrawImageAbort callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr, System.Drawing.Graphics.DrawImageAbort? callback);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * int * int * int * int * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Integer, srcY As Integer, srcWidth As Integer, srcHeight As Integer, srcUnit As GraphicsUnit, imageAttr As ImageAttributes, callback As Graphics.DrawImageAbort)
Parametri
- destRect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcX
- Int32
Coordinata X dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcY
- Int32
Coordinata Y dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcWidth
- Int32
Larghezza della parte dell'immagine di origine da disegnare.
- srcHeight
- Int32
Altezza della parte dell'immagine di origine da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate per determinare il rettangolo di origine.
- imageAttr
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per image
.
- callback
- Graphics.DrawImageAbort
Delegato Graphics.DrawImageAbort che specifica un metodo da chiamare durante il disegno dell'immagine. Questo metodo viene chiamato frequentemente per controllare se sia necessario interrompere l'esecuzione del metodo DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) secondo i criteri determinati dall'applicazione.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice definisce prima un metodo di callback per il Graphics.DrawImageAbort delegato. La definizione è semplicistica e verifica semplicemente se il DrawImage metodo lo chiama con un parametro Null callBackData
. Il corpo principale dell'esempio esegue le azioni seguenti:
Crea un'istanza del Graphics.DrawImageAbort metodo di callback.
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un rettangolo di destinazione in cui disegnare l'immagine.
Crea un rettangolo di origine per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine originale sullo schermo.
Crea un rettangolo di destinazione aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per il rettangolo di destinazione originale, non modificato, la posizione individua l'immagine sullo schermo e le dimensioni del rettangolo di origine e la dimensione e la forma del rettangolo di destinazione determina il ridimensionamento dell'immagine disegnata.
Poiché questo esempio usa un overload che non passa un callBackData
parametro, il callback restituisce true
, che causa DrawImage la fine del metodo e il Graphics.DrawImageAbort codice di gestione delle eccezioni incluso nell'esempio stampa il testo dell'eccezione anziché disegnare l'immagine.
// Define DrawImageAbort callback method.
private:
bool DrawImageCallback5( 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;
}
}
private:
void DrawImageRect4IntAtrribAbort( PaintEventArgs^ e )
{
// Create callback method.
Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback5 );
// 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.
int x = 50;
int y = 50;
int width = 150;
int height = 150;
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 );
try
{
// Draw adjusted image to screen.
e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback );
}
catch ( Exception^ ex )
{
e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
}
}
// Define DrawImageAbort callback method.
private bool DrawImageCallback5(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;
}
}
private void DrawImageRect4IntAtrribAbort(PaintEventArgs e)
{
// Create callback method.
Graphics.DrawImageAbort imageCallback
= new Graphics.DrawImageAbort(DrawImageCallback5);
// 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.
int x = 50;
int y = 50;
int width = 150;
int height = 150;
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);
try
{
checked
{
// Draw adjusted image to screen.
e.Graphics.DrawImage(
newImage,
destRect2,
x, y,
width, height,
units,
imageAttr,
imageCallback);
}
}
catch (Exception ex)
{
e.Graphics.DrawString(
ex.ToString(),
new Font("Arial", 8),
Brushes.Black,
new PointF(0, 0));
}
}
Private Function DrawImageCallback5(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
Private Sub DrawImageRect4IntAtrribAbort(ByVal e As PaintEventArgs)
' Create callback method.
Dim imageCallback As New _
Graphics.DrawImageAbort(AddressOf DrawImageCallback5)
' 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 Integer = 50
Dim y As Integer = 50
Dim width As Integer = 150
Dim height As Integer = 150
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)
Try
' Draw adjusted image to screen.
e.Graphics.DrawImage(newImage, destRect2, x, y, width, _
height, 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
Commenti
I srcX
parametri , srcY
, srcWidth
e srcHeight
specificano una parte rettangolare dell'oggetto image
da disegnare. Il rettangolo è relativo all'angolo superiore sinistro dell'immagine di origine. Questa parte viene ridimensionata per adattarsi all'interno del rettangolo specificato dall'oggetto destRect
.
Questo overload con il callback
parametro fornisce i mezzi per arrestare il disegno di un'immagine dopo l'avvio in base ai criteri determinati dall'applicazione. Ad esempio, un'applicazione potrebbe avviare il disegno di un'immagine di grandi dimensioni e l'utente potrebbe scorrere l'immagine dalla schermata, in questo caso l'applicazione potrebbe arrestare il disegno.
Vedi anche
Si applica a
DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttrs, System::Drawing::Graphics::DrawImageAbort ^ callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs, System.Drawing.Graphics.DrawImageAbort callback);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs, System.Drawing.Graphics.DrawImageAbort? callback);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * single * single * single * single * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort -> unit
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 Graphics.DrawImageAbort)
Parametri
- destRect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcX
- Single
Coordinata X dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcY
- Single
Coordinata Y dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcWidth
- Single
Larghezza della parte dell'immagine di origine da disegnare.
- srcHeight
- Single
Altezza della parte dell'immagine di origine da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate per determinare il rettangolo di origine.
- imageAttrs
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
- callback
- Graphics.DrawImageAbort
Delegato Graphics.DrawImageAbort che specifica un metodo da chiamare durante il disegno dell'immagine. Questo metodo viene chiamato frequentemente per controllare se sia necessario interrompere l'esecuzione del metodo DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort) secondo i criteri determinati dall'applicazione.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice definisce prima un metodo di callback per il Graphics.DrawImageAbort delegato. La definizione è semplicistica e verifica semplicemente se il DrawImage metodo lo chiama con un parametro Null callBackData
. Il corpo principale dell'esempio esegue le azioni seguenti:
Crea un'istanza del Graphics.DrawImageAbort metodo di callback.
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un rettangolo di destinazione in cui disegnare l'immagine.
Crea un rettangolo di origine per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine originale sullo schermo.
Crea un rettangolo di destinazione aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per il rettangolo di destinazione originale, non modificato, la posizione individua l'immagine sullo schermo e le dimensioni del rettangolo di origine e la dimensione e la forma del rettangolo di destinazione determina il ridimensionamento dell'immagine disegnata.
Poiché questo esempio usa un overload che non passa un callBackData
parametro, il callback restituisce true
, che causa DrawImage la fine del metodo e il Graphics.DrawImageAbort codice di gestione delle eccezioni incluso nell'esempio stampa il testo dell'eccezione anziché disegnare l'immagine.
// Define DrawImageAbort callback method.
private:
bool DrawImageCallback7( 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;
}
}
private:
void DrawImageRect4FloatAttribAbort( PaintEventArgs^ e )
{
// Create callback method.
Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback7 );
// 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 );
try
{
// Draw adjusted image to screen.
e->Graphics->DrawImage( newImage, destRect2, x, y, width, height, units, imageAttr, imageCallback );
}
catch ( Exception^ ex )
{
e->Graphics->DrawString( ex->ToString(), gcnew System::Drawing::Font( "Arial",8 ), Brushes::Black, PointF(0,0) );
}
}
// Define DrawImageAbort callback method.
private bool DrawImageCallback7(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;
}
}
private void DrawImageRect4FloatAttribAbort(PaintEventArgs e)
{
// Create callback method.
Graphics.DrawImageAbort imageCallback
= new Graphics.DrawImageAbort(DrawImageCallback7);
// 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);
try
{
checked
{
// Draw adjusted image to screen.
e.Graphics.DrawImage(
newImage,
destRect2,
x, y,
width, height,
units,
imageAttr,
imageCallback);
}
}
catch (Exception ex)
{
e.Graphics.DrawString(
ex.ToString(),
new Font("Arial", 8),
Brushes.Black,
new PointF(0, 0));
}
}
Private Function DrawImageCallback7(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
Private Sub DrawImageRect4FloatAttribAbort(ByVal e As PaintEventArgs)
' Create callback method.
Dim imageCallback As New _
Graphics.DrawImageAbort(AddressOf DrawImageCallback7)
' 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)
Try
' Draw adjusted image to screen.
e.Graphics.DrawImage(newImage, destRect2, x, y, width, _
height, 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
Commenti
I srcX
parametri , srcY
, srcWidth
e srcHeight
specificano una parte rettangolare dell'oggetto image
da disegnare. Il rettangolo è relativo all'angolo superiore sinistro dell'immagine di origine. Questa parte viene ridimensionata per adattarsi al rettangolo specificato dal destRect
parametro.
Questo overload con il callback
parametro fornisce i mezzi per arrestare il disegno di un'immagine dopo l'avvio in base ai criteri determinati dall'applicazione. Ad esempio, un'applicazione potrebbe avviare il disegno di un'immagine di grandi dimensioni e l'utente potrebbe scorrere l'immagine dalla schermata, in questo caso l'applicazione potrebbe arrestare il disegno.
Vedi anche
Si applica a
DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttrs, System::Drawing::Graphics::DrawImageAbort ^ callback, IntPtr callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs, System.Drawing.Graphics.DrawImageAbort callback, IntPtr callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs, System.Drawing.Graphics.DrawImageAbort? callback, IntPtr callbackData);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * int * int * int * int * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort * nativeint -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Integer, srcY As Integer, srcWidth As Integer, srcHeight As Integer, srcUnit As GraphicsUnit, imageAttrs As ImageAttributes, callback As Graphics.DrawImageAbort, callbackData As IntPtr)
Parametri
- destRect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcX
- Int32
Coordinata X dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcY
- Int32
Coordinata Y dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcWidth
- Int32
Larghezza della parte dell'immagine di origine da disegnare.
- srcHeight
- Int32
Altezza della parte dell'immagine di origine da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate per determinare il rettangolo di origine.
- imageAttrs
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
- callback
- Graphics.DrawImageAbort
Delegato Graphics.DrawImageAbort che specifica un metodo da chiamare durante il disegno dell'immagine. Questo metodo viene chiamato frequentemente per controllare se sia necessario interrompere l'esecuzione del metodo DrawImage(Image, Rectangle, Int32, Int32, Int32, Int32, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) secondo i criteri determinati dall'applicazione.
- callbackData
-
IntPtr
nativeint
Valore che specifica ulteriori dati per il delegato Graphics.DrawImageAbort da usare quando si verifica se interrompere l'esecuzione del metodo DrawImage
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice definisce prima un metodo di callback per il Graphics.DrawImageAbort delegato. La definizione è semplicistica e verifica semplicemente se il DrawImage metodo lo chiama con un parametro Null callBackData
. Il corpo principale dell'esempio esegue le azioni seguenti:
Crea un'istanza del Graphics.DrawImageAbort metodo di callback.
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un rettangolo di destinazione in cui disegnare l'immagine.
Crea un rettangolo di origine per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine originale sullo schermo.
Crea un rettangolo di destinazione aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per il rettangolo di destinazione originale, non modificato, la posizione individua l'immagine sullo schermo e le dimensioni del rettangolo di origine e la dimensione e la forma del rettangolo di destinazione determina il ridimensionamento dell'immagine disegnata.
Poiché in questo esempio viene usato un overload che passa un callBackData
parametro, il Graphics.DrawImageAbortDrawImage callback restituisce false
, che causa la continuazione del metodo e l'esempio disegna l'immagine modificata sullo schermo.
// Define DrawImageAbort callback method.
private:
bool DrawImageCallback6( 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;
}
}
private:
void DrawImageRect4IntAtrribAbortData( PaintEventArgs^ e )
{
// Create callback method.
Graphics::DrawImageAbort^ imageCallback = gcnew Graphics::DrawImageAbort( this, &Form1::DrawImageCallback6 );
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.
int x = 50;
int y = 50;
int width = 150;
int height = 150;
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 );
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) );
}
}
// Define DrawImageAbort callback method.
private bool DrawImageCallback6(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;
}
}
private void DrawImageRect4IntAtrribAbortData(PaintEventArgs e)
{
// Create callback method.
Graphics.DrawImageAbort imageCallback
= new Graphics.DrawImageAbort(DrawImageCallback6);
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.
int x = 50;
int y = 50;
int width = 150;
int height = 150;
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);
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));
}
}
Private Function DrawImageCallback6(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
Private Sub DrawImageRect4IntAtrribAbortData(ByVal e As PaintEventArgs)
' Create callback method.
Dim imageCallback As New _
Graphics.DrawImageAbort(AddressOf DrawImageCallback6)
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 Integer = 50
Dim y As Integer = 50
Dim width As Integer = 150
Dim height As Integer = 150
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)
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
Commenti
I srcX
parametri , srcY
, srcWidth
e srcHeight
specificano una parte rettangolare dell'oggetto image
da disegnare. Il rettangolo è relativo all'angolo superiore sinistro dell'immagine di origine. Questa parte viene ridimensionata per adattarsi al rettangolo specificato dal destRect
parametro.
Questo overload con i callback
parametri e callbackData
fornisce i mezzi per arrestare il disegno di un'immagine dopo l'avvio in base ai criteri e ai dati determinati dall'applicazione. Ad esempio, un'applicazione potrebbe avviare il disegno di un'immagine di grandi dimensioni e l'utente potrebbe scorrere l'immagine dalla schermata, in questo caso l'applicazione potrebbe arrestare il disegno.
Vedi anche
Si applica a
DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttrs, System::Drawing::Graphics::DrawImageAbort ^ callback, IntPtr callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttrs, System.Drawing.Graphics.DrawImageAbort callback, IntPtr callbackData);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttrs, System.Drawing.Graphics.DrawImageAbort? callback, IntPtr callbackData);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * single * single * single * single * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes * System.Drawing.Graphics.DrawImageAbort * nativeint -> unit
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 Graphics.DrawImageAbort, callbackData As IntPtr)
Parametri
- destRect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcX
- Single
Coordinata X dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcY
- Single
Coordinata Y dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcWidth
- Single
Larghezza della parte dell'immagine di origine da disegnare.
- srcHeight
- Single
Altezza della parte dell'immagine di origine da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate per determinare il rettangolo di origine.
- imageAttrs
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
- callback
- Graphics.DrawImageAbort
Delegato Graphics.DrawImageAbort che specifica un metodo da chiamare durante il disegno dell'immagine. Questo metodo viene chiamato frequentemente per controllare se sia necessario interrompere l'esecuzione del metodo DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit, ImageAttributes, Graphics+DrawImageAbort, IntPtr) secondo i criteri determinati dall'applicazione.
- callbackData
-
IntPtr
nativeint
Valore che specifica ulteriori dati per il delegato Graphics.DrawImageAbort da usare quando si verifica se interrompere l'esecuzione del metodo DrawImage
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice definisce prima un metodo di callback per il Graphics.DrawImageAbort delegato. La definizione è semplicistica e verifica semplicemente se il DrawImage metodo lo chiama con un parametro Null callBackData
. Il corpo principale dell'esempio esegue le azioni seguenti:
Crea un'istanza del Graphics.DrawImageAbort metodo di callback.
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un rettangolo di destinazione in cui disegnare l'immagine.
Crea un rettangolo di origine per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine originale sullo schermo.
Crea un rettangolo di destinazione aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per il rettangolo di destinazione originale, non modificato, la posizione individua l'immagine sullo schermo e le dimensioni del rettangolo di origine e la dimensione e la forma del rettangolo di destinazione determina il ridimensionamento dell'immagine disegnata.
Poiché in questo esempio viene usato un overload che passa un callBackData
parametro, il Graphics.DrawImageAbortDrawImage callback restituisce false
, che causa la continuazione del metodo e l'esempio disegna l'immagine modificata sullo schermo.
// 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) );
}
}
// 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));
}
}
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
Commenti
I srcX
parametri , srcY
, srcWidth
e srcHeight
specificano una parte rettangolare dell'oggetto image
da disegnare. Il rettangolo è relativo all'angolo superiore sinistro dell'immagine di origine. Questa parte viene ridimensionata per adattarsi al rettangolo specificato dal destRect
parametro.
Questo overload con i callback
parametri e callbackData
fornisce i mezzi per arrestare il disegno di un'immagine dopo l'avvio in base ai criteri e ai dati determinati dall'applicazione. Ad esempio, un'applicazione potrebbe avviare il disegno di un'immagine di grandi dimensioni e l'utente potrebbe scorrere l'immagine dalla schermata, in questo caso l'applicazione potrebbe arrestare il disegno.
Vedi anche
Si applica a
DrawImage(Image, Rectangle, Single, Single, Single, Single, GraphicsUnit)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * single * single * single * single * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcX As Single, srcY As Single, srcWidth As Single, srcHeight As Single, srcUnit As GraphicsUnit)
Parametri
- destRect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcX
- Single
Coordinata X dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcY
- Single
Coordinata Y dell'angolo superiore sinistro della parte dell'immagine di origine da disegnare.
- srcWidth
- Single
Larghezza della parte dell'immagine di origine da disegnare.
- srcHeight
- Single
Altezza della parte dell'immagine di origine da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate per determinare il rettangolo di origine.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea le coordinate di un rettangolo di destinazione in cui disegnare l'immagine.
Crea un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine sullo schermo.
La posizione del rettangolo di destinazione individua l'immagine sullo schermo, le dimensioni dei rettangoli di origine e di destinazione determinano il ridimensionamento dell'immagine disegnata e le dimensioni del rettangolo di origine determinano la parte dell'immagine originale sullo schermo.
private:
void DrawImageRect4Float( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create rectangle for displaying image.
Rectangle destRect = Rectangle(100,100,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 image to screen.
e->Graphics->DrawImage( newImage, destRect, x, y, width, height, units );
}
private void DrawImageRect4Float(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create rectangle for displaying image.
Rectangle destRect = new Rectangle(100, 100, 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 image to screen.
e.Graphics.DrawImage(newImage, destRect, x, y, width, height, units);
}
Private Sub DrawImageRect4Float(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create rectangle for displaying image.
Dim destRect As New Rectangle(100, 100, 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 image to screen.
e.Graphics.DrawImage(newImage, destRect, x, y, width, height, _
units)
End Sub
Commenti
I srcX
parametri , srcY
, srcWidth
e srcHeight
specificano una parte rettangolare dell'oggetto image
da disegnare. Il rettangolo è relativo all'angolo superiore sinistro dell'immagine di origine. Questa parte viene ridimensionata per adattarsi al rettangolo specificato dal destRect
parametro.
Vedi anche
Si applica a
DrawImage(Image, Int32, Int32, Int32, Int32)
Disegna l'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, int x, int y, int width, int height);
public void DrawImage (System.Drawing.Image image, int x, int y, int width, int height);
member this.DrawImage : System.Drawing.Image * int * int * int * int -> unit
Public Sub DrawImage (image As Image, x As Integer, y As Integer, width As Integer, height As Integer)
Parametri
- x
- Int32
Coordinata X dell'angolo superiore sinistro dell'immagine disegnata.
- y
- Int32
Coordinata Y dell'angolo superiore sinistro dell'immagine disegnata.
- width
- Int32
Larghezza dell'immagine disegnata.
- height
- Int32
Altezza dell'immagine disegnata.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea la posizione e le dimensioni di un rettangolo in cui disegnare l'immagine.
Disegna l'immagine sullo schermo.
La posizione del rettangolo individua l'immagine sullo schermo e le dimensioni dell'immagine originale e le dimensioni del rettangolo determinano il ridimensionamento dell'immagine disegnata.
public:
void DrawImage4Int( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create coordinates for upper-left corner.
// of image and for size of image.
int x = 100;
int y = 100;
int width = 450;
int height = 150;
// Draw image to screen.
e->Graphics->DrawImage( newImage, x, y, width, height );
}
public void DrawImage4Int(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create coordinates for upper-left corner.
// of image and for size of image.
int x = 100;
int y = 100;
int width = 450;
int height = 150;
// Draw image to screen.
e.Graphics.DrawImage(newImage, x, y, width, height);
}
Public Sub DrawImage4Int(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create coordinates for upper-left corner
' of image and for size of image.
Dim x As Integer = 100
Dim y As Integer = 100
Dim width As Integer = 450
Dim height As Integer = 150
' Draw image to screen.
e.Graphics.DrawImage(newImage, x, y, width, height)
End Sub
Commenti
Il rettangolo definito dai x
parametri , y
, width
e height
determina la posizione e le dimensioni dell'immagine disegnata.
Vedi anche
Si applica a
DrawImage(Image, Single, Single, Single, Single)
Disegna l'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, float x, float y, float width, float height);
public void DrawImage (System.Drawing.Image image, float x, float y, float width, float height);
member this.DrawImage : System.Drawing.Image * single * single * single * single -> unit
Public Sub DrawImage (image As Image, x As Single, y As Single, width As Single, height As Single)
Parametri
- x
- Single
Coordinata X dell'angolo superiore sinistro dell'immagine disegnata.
- y
- Single
Coordinata Y dell'angolo superiore sinistro dell'immagine disegnata.
- width
- Single
Larghezza dell'immagine disegnata.
- height
- Single
Altezza dell'immagine disegnata.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea la posizione e le dimensioni di un rettangolo in cui disegnare l'immagine.
Disegna l'immagine sullo schermo.
La posizione del rettangolo individua l'immagine sullo schermo e le dimensioni dell'immagine originale e le dimensioni del rettangolo determinano il ridimensionamento dell'immagine disegnata.
public:
void DrawImage4Float( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create coordinates for upper-left corner.
// of image and for size of image.
float x = 100.0F;
float y = 100.0F;
float width = 450.0F;
float height = 150.0F;
// Draw image to screen.
e->Graphics->DrawImage( newImage, x, y, width, height );
}
public void DrawImage4Float(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create coordinates for upper-left corner.
// of image and for size of image.
float x = 100.0F;
float y = 100.0F;
float width = 450.0F;
float height = 150.0F;
// Draw image to screen.
e.Graphics.DrawImage(newImage, x, y, width, height);
}
Public Sub DrawImage4Float(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create coordinates for upper-left corner
' of image and for size of image.
Dim x As Single = 100.0F
Dim y As Single = 100.0F
Dim width As Single = 450.0F
Dim height As Single = 150.0F
' Draw image to screen.
e.Graphics.DrawImage(newImage, x, y, width, height)
End Sub
Commenti
Il rettangolo definito dai x
parametri , y
, width
e height
determina la posizione e le dimensioni dell'immagine disegnata.
Vedi anche
Si applica a
DrawImage(Image, PointF[], RectangleF, GraphicsUnit, ImageAttributes)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
Public Sub DrawImage (image As Image, destPoints As PointF(), srcRect As RectangleF, srcUnit As GraphicsUnit, imageAttr As ImageAttributes)
Parametri
- srcRect
- RectangleF
Struttura RectangleF che specifica la parte dell'oggetto image
da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
- imageAttr
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma di destinazione in cui disegnare l'immagine.
Crea un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine originale sullo schermo.
Crea un parallelogramma aggiuntivo in cui disegnare un'immagine modificata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma maggiore del solito.
Disegna l'immagine modificata sullo schermo.
Per il parallelogramma di destinazione originale, non modificato, la posizione individua l'immagine sullo schermo, le dimensioni del rettangolo di origine e la forma del parallelogramma di destinazione determinano il ridimensionamento e l'shearing dell'immagine disegnata e le dimensioni del rettangolo determinano la parte dell'immagine originale sullo schermo.
void DrawImageParaFRectFAttrib( PaintEventArgs^ e )
{
// 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 );
// Draw adjusted image to screen.
e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr );
}
private void DrawImageParaFRectFAttrib(PaintEventArgs e)
{
// 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);
// Draw adjusted image to screen.
e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr);
}
Private Sub DrawImageParaFRectFAttrib(ByVal e As PaintEventArgs)
' 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)
' Draw adjusted image to screen.
e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _
imageAttr)
End Sub
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre PointF strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dal primo tre per formare un parallelogramma.
Il srcRect
parametro specifica una parte rettangolare dell'oggetto image
da disegnare. Questa porzione viene ridimensionata e viene ridimensionata per adattarsi all'interno del destPoints
parallelogramma specificato dal parametro.
Vedi anche
Si applica a
DrawImage(Image, Effect)
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Imaging::Effects::Effect ^ effect);
public void DrawImage (System.Drawing.Image image, System.Drawing.Imaging.Effects.Effect effect);
member this.DrawImage : System.Drawing.Image * System.Drawing.Imaging.Effects.Effect -> unit
Public Sub DrawImage (image As Image, effect As Effect)
Parametri
- image
- Image
- effect
- Effect
Si applica a
DrawImage(Image, Point)
Disegna l'oggetto Image specificato usando le dimensioni originali, nella posizione indicata.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Point point);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point point);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point -> unit
Public Sub DrawImage (image As Image, point As Point)
Parametri
- point
- Point
Struttura Point che rappresenta la posizione dell'angolo superiore sinistro dell'immagine disegnata.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea un punto in corrispondenza del quale disegnare l'angolo superiore sinistro dell'immagine.
Disegna l'immagine non ridimensionata sullo schermo.
private:
void DrawImagePoint( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create Point for upper-left corner of image.
Point ulCorner = Point(100,100);
// Draw image to screen.
e->Graphics->DrawImage( newImage, ulCorner );
}
private void DrawImagePoint(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create Point for upper-left corner of image.
Point ulCorner = new Point(100, 100);
// Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner);
}
Private Sub DrawImagePoint(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create Point for upper-left corner of image.
Dim ulCorner As New Point(100, 100)
' Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner)
End Sub
Commenti
Un Image oggetto archivia un valore per la larghezza dei pixel e un valore per la risoluzione orizzontale (punti per pollice). La larghezza fisica, misurata in pollici, di un'immagine è la larghezza di pixel divisa dalla risoluzione orizzontale. Ad esempio, un'immagine con larghezza pixel di 216 e una risoluzione orizzontale di 72 punti per pollice ha una larghezza fisica di 3 pollici. Le osservazioni simili si applicano all'altezza dei pixel e all'altezza fisica.
Questo metodo disegna un'immagine usando le dimensioni fisiche, quindi l'immagine avrà le dimensioni corrette in pollici indipendentemente dalla risoluzione (punti per pollice) del dispositivo di visualizzazione. Si supponga, ad esempio, che un'immagine abbia una larghezza di pixel pari a 216 e una risoluzione orizzontale di 72 punti per pollice. Se si chiama questo metodo per disegnare l'immagine in un dispositivo con una risoluzione di 96 punti per pollice, la larghezza dei pixel dell'immagine di rendering sarà (216/72)*96 = 288.
Vedi anche
Si applica a
DrawImage(Image, Point[])
Disegna l'oggetto Image specificato nella posizione indicata e con la forma e le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] -> unit
Public Sub DrawImage (image As Image, destPoints As Point())
Parametri
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma in cui disegnare l'immagine.
Disegna l'immagine sullo schermo.
La posizione del parallelogramma individua l'immagine sullo schermo e le dimensioni dell'immagine originale e la dimensione e la forma del parallelogramma determina il ridimensionamento e l'avvio dell'immagine disegnata.
private:
void DrawImagePara( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create parallelogram for drawing image.
Point ulCorner = Point(100,100);
Point urCorner = Point(550,100);
Point llCorner = Point(150,250);
array<Point>^ destPara = {ulCorner,urCorner,llCorner};
// Draw image to screen.
e->Graphics->DrawImage( newImage, destPara );
}
private void DrawImagePara(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create parallelogram for drawing image.
Point ulCorner = new Point(100, 100);
Point urCorner = new Point(550, 100);
Point llCorner = new Point(150, 250);
Point[] destPara = {ulCorner, urCorner, llCorner};
// Draw image to screen.
e.Graphics.DrawImage(newImage, destPara);
}
Private Sub DrawImagePara(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create parallelogram for drawing image.
Dim ulCorner As New Point(100, 100)
Dim urCorner As New Point(550, 100)
Dim llCorner As New Point(150, 250)
Dim destPara As Point() = {ulCorner, urCorner, llCorner}
' Draw image to screen.
e.Graphics.DrawImage(newImage, destPara)
End Sub
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre Point strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dal primo tre per formare un parallelogramma.
L'immagine rappresentata dal image
parametro viene ridimensionata e si esea per adattare la forma del parallelogramma specificato dai destPoints
parametri.
Vedi anche
Si applica a
DrawImage(Image, PointF)
Disegna l'oggetto Image specificato usando le dimensioni originali, nella posizione indicata.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::PointF point);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF point);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF -> unit
Public Sub DrawImage (image As Image, point As PointF)
Parametri
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea un punto in corrispondenza del quale disegnare l'angolo superiore sinistro dell'immagine.
Disegna l'immagine non ridimensionata sullo schermo.
private:
void DrawImagePointF( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create point for upper-left corner of image.
PointF ulCorner = PointF(100.0F,100.0F);
// Draw image to screen.
e->Graphics->DrawImage( newImage, ulCorner );
}
private void DrawImagePointF(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create point for upper-left corner of image.
PointF ulCorner = new PointF(100.0F, 100.0F);
// Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner);
}
Private Sub DrawImagePointF(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create point for upper-left corner of image.
Dim ulCorner As New PointF(100.0F, 100.0F)
' Draw image to screen.
e.Graphics.DrawImage(newImage, ulCorner)
End Sub
Commenti
Un Image oggetto archivia un valore per la larghezza dei pixel e un valore per la risoluzione orizzontale (punti per pollice). La larghezza fisica, misurata in pollici, di un'immagine è la larghezza di pixel divisa dalla risoluzione orizzontale. Ad esempio, un'immagine con larghezza pixel di 216 e una risoluzione orizzontale di 72 punti per pollice ha una larghezza fisica di 3 pollici. Le osservazioni simili si applicano all'altezza dei pixel e all'altezza fisica.
Questo metodo disegna un'immagine usando le dimensioni fisiche, quindi l'immagine avrà le dimensioni corrette in pollici indipendentemente dalla risoluzione (punti per pollice) del dispositivo di visualizzazione. Si supponga, ad esempio, che un'immagine abbia una larghezza di pixel pari a 216 e una risoluzione orizzontale di 72 punti per pollice. Se si chiama questo metodo per disegnare l'immagine in un dispositivo con una risoluzione di 96 punti per pollice, la larghezza dei pixel dell'immagine di rendering sarà (216/72)*96 = 288.
Vedi anche
Si applica a
DrawImage(Image, PointF[])
Disegna l'oggetto Image specificato nella posizione indicata e con la forma e le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] -> unit
Public Sub DrawImage (image As Image, destPoints As PointF())
Parametri
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma in cui disegnare l'immagine.
Disegna l'immagine sullo schermo.
La posizione del parallelogramma individua l'immagine sullo schermo e le dimensioni dell'immagine originale e la dimensione e la forma del parallelogramma determina il ridimensionamento e l'avvio dell'immagine disegnata.
private:
void DrawImageParaF( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create parallelogram for drawing image.
PointF ulCorner = PointF(100.0F,100.0F);
PointF urCorner = PointF(550.0F,100.0F);
PointF llCorner = PointF(150.0F,250.0F);
array<PointF>^ destPara = {ulCorner,urCorner,llCorner};
// Draw image to screen.
e->Graphics->DrawImage( newImage, destPara );
}
private void DrawImageParaF(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create parallelogram for drawing image.
PointF ulCorner = new PointF(100.0F, 100.0F);
PointF urCorner = new PointF(550.0F, 100.0F);
PointF llCorner = new PointF(150.0F, 250.0F);
PointF[] destPara = {ulCorner, urCorner, llCorner};
// Draw image to screen.
e.Graphics.DrawImage(newImage, destPara);
}
Private Sub DrawImageParaF(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create parallelogram for drawing image.
Dim ulCorner As New PointF(100.0F, 100.0F)
Dim urCorner As New PointF(550.0F, 100.0F)
Dim llCorner As New PointF(150.0F, 250.0F)
Dim destPara As PointF() = {ulCorner, urCorner, llCorner}
' Draw image to screen.
e.Graphics.DrawImage(newImage, destPara)
End Sub
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre PointF strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dal primo tre per formare un parallelogramma.
L'immagine rappresentata dall'oggetto image
viene ridimensionata e viene ridimensionata per adattare la forma del parallelogramma specificato dal destPoints
parametro.
Vedi anche
Si applica a
DrawImage(Image, Rectangle)
Disegna l'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle rect);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle rect);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle -> unit
Public Sub DrawImage (image As Image, rect As Rectangle)
Parametri
- rect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea un rettangolo in cui disegnare l'immagine.
Disegna l'immagine sullo schermo.
La posizione del rettangolo individua l'immagine sullo schermo e le dimensioni dell'immagine originale e le dimensioni del rettangolo determinano il ridimensionamento dell'immagine disegnata.
private:
void DrawImageRect( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create rectangle for displaying image.
Rectangle destRect = Rectangle(100,100,450,150);
// Draw image to screen.
e->Graphics->DrawImage( newImage, destRect );
}
private void DrawImageRect(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create rectangle for displaying image.
Rectangle destRect = new Rectangle(100, 100, 450, 150);
// Draw image to screen.
e.Graphics.DrawImage(newImage, destRect);
}
Private Sub DrawImageRect(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create rectangle for displaying image.
Dim destRect As New Rectangle(100, 100, 450, 150)
' Draw image to screen.
e.Graphics.DrawImage(newImage, destRect)
End Sub
Commenti
L'immagine rappresentata dall'oggetto image
viene ridimensionata alle dimensioni del rect
rettangolo.
Vedi anche
Si applica a
DrawImage(Image, RectangleF)
Disegna l'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::RectangleF rect);
public void DrawImage (System.Drawing.Image image, System.Drawing.RectangleF rect);
member this.DrawImage : System.Drawing.Image * System.Drawing.RectangleF -> unit
Public Sub DrawImage (image As Image, rect As RectangleF)
Parametri
- rect
- RectangleF
Struttura RectangleF che specifica la posizione e le dimensioni dell'immagine disegnata.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea un rettangolo in cui disegnare l'immagine.
Disegna l'immagine sullo schermo.
La posizione del rettangolo individua l'immagine sullo schermo e le dimensioni originali dell'immagine e le dimensioni del rettangolo determinano il ridimensionamento dell'immagine disegnata.
public:
void DrawImageRectF( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create rectangle for displaying image.
RectangleF rect = RectangleF(100.0F,100.0F,450.0F,150.0F);
// Draw image to screen.
e->Graphics->DrawImage( newImage, rect );
}
public void DrawImageRectF(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create rectangle for displaying image.
RectangleF rect = new RectangleF(100.0F, 100.0F, 450.0F, 150.0F);
// Draw image to screen.
e.Graphics.DrawImage(newImage, rect);
}
Public Sub DrawImageRectF(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create rectangle for displaying image.
Dim rect As New RectangleF(100.0F, 100.0F, 450.0F, 150.0F)
' Draw image to screen.
e.Graphics.DrawImage(newImage, rect)
End Sub
Commenti
L'immagine rappresentata dall'oggetto image
viene ridimensionata alle dimensioni del rect
rettangolo.
Vedi anche
Si applica a
DrawImage(Image, Int32, Int32, Rectangle, GraphicsUnit)
Disegna una parte di un'immagine nella posizione specifica.
public:
void DrawImage(System::Drawing::Image ^ image, int x, int y, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, int x, int y, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * int * int * System.Drawing.Rectangle * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, x As Integer, y As Integer, srcRect As Rectangle, srcUnit As GraphicsUnit)
Parametri
- x
- Int32
Coordinata X dell'angolo superiore sinistro dell'immagine disegnata.
- y
- Int32
Coordinata Y dell'angolo superiore sinistro dell'immagine disegnata.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea le coordinate in corrispondenza della quale disegnare l'angolo superiore sinistro dell'immagine.
Crea un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine sullo schermo.
Le dimensioni del rettangolo di origine determinano la parte dell'immagine originale non ridimensionata sullo schermo.
public:
void DrawImage2IntRect( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create coordinates for upper-left corner of image.
int x = 100;
int y = 100;
// Create rectangle for source image.
Rectangle srcRect = Rectangle(50,50,150,150);
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw image to screen.
e->Graphics->DrawImage( newImage, x, y, srcRect, units );
}
public void DrawImage2IntRect(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create coordinates for upper-left corner of image.
int x = 100;
int y = 100;
// Create rectangle for source image.
Rectangle srcRect = new Rectangle(50, 50, 150, 150);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw image to screen.
e.Graphics.DrawImage(newImage, x, y, srcRect, units);
}
Public Sub DrawImage2IntRect(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create coordinates for upper-left corner of image.
Dim x As Integer = 100
Dim y As Integer = 100
' Create rectangle for source image.
Dim srcRect As New Rectangle(50, 50, 150, 150)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw image to screen.
e.Graphics.DrawImage(newImage, x, y, srcRect, units)
End Sub
Commenti
Un Image oggetto archivia un valore per la larghezza dei pixel e un valore per la risoluzione orizzontale (punti per pollice). La larghezza fisica, misurata in pollici, di un'immagine è la larghezza di pixel divisa dalla risoluzione orizzontale. Ad esempio, un'immagine con larghezza pixel di 360 e una risoluzione orizzontale di 72 punti per pollice ha una larghezza fisica di 5 pollici. Le osservazioni simili si applicano all'altezza dei pixel e all'altezza fisica.
Questo metodo disegna una parte di un'immagine usando le dimensioni fisiche, quindi la parte dell'immagine avrà le dimensioni corrette in pollici indipendentemente dalla risoluzione (punti per pollice) del dispositivo di visualizzazione. Si supponga, ad esempio, che una parte dell'immagine abbia una larghezza di pixel pari a 216 e una risoluzione orizzontale di 72 punti per pollice. Se si chiama questo metodo per disegnare tale parte dell'immagine in un dispositivo con una risoluzione di 96 punti per pollice, la larghezza dei pixel della parte dell'immagine di cui è stato eseguito il rendering sarà (216/72)*96 = 288.
Vedi anche
Si applica a
DrawImage(Image, Single, Single)
Disegna l'oggetto Image specificato usando le dimensioni originali, nella posizione indicata.
public:
void DrawImage(System::Drawing::Image ^ image, float x, float y);
public void DrawImage (System.Drawing.Image image, float x, float y);
member this.DrawImage : System.Drawing.Image * single * single -> unit
Public Sub DrawImage (image As Image, x As Single, y As Single)
Parametri
- x
- Single
Coordinata X dell'angolo superiore sinistro dell'immagine disegnata.
- y
- Single
Coordinata Y dell'angolo superiore sinistro dell'immagine disegnata.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea le coordinate di un punto in corrispondenza del quale disegnare l'angolo superiore sinistro dell'immagine.
Disegna l'immagine non ridimensionata sullo schermo.
public:
void DrawImage2Float( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create coordinates for upper-left corner of image.
float x = 100.0F;
float y = 100.0F;
// Draw image to screen.
e->Graphics->DrawImage( newImage, x, y );
}
public void DrawImage2Float(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create coordinates for upper-left corner of image.
float x = 100.0F;
float y = 100.0F;
// Draw image to screen.
e.Graphics.DrawImage(newImage, x, y);
}
Public Sub DrawImage2Float(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create coordinates for upper-left corner of image.
Dim x As Single = 100.0F
Dim y As Single = 100.0F
' Draw image to screen.
e.Graphics.DrawImage(newImage, x, y)
End Sub
Commenti
Un Image oggetto archivia un valore per la larghezza dei pixel e un valore per la risoluzione orizzontale (punti per pollice). La larghezza fisica, misurata in pollici, di un'immagine è la larghezza di pixel divisa dalla risoluzione orizzontale. Ad esempio, un'immagine con larghezza pixel di 216 e una risoluzione orizzontale di 72 punti per pollice ha una larghezza fisica di 3 pollici. Le osservazioni simili si applicano all'altezza dei pixel e all'altezza fisica.
Questo metodo disegna un'immagine usando le dimensioni fisiche, quindi l'immagine avrà le dimensioni corrette in pollici indipendentemente dalla risoluzione (punti per pollice) del dispositivo di visualizzazione. Si supponga, ad esempio, che un'immagine abbia una larghezza di pixel pari a 216 e una risoluzione orizzontale di 72 punti per pollice. Se si chiama questo metodo per disegnare l'immagine in un dispositivo con una risoluzione di 96 punti per pollice, la larghezza dei pixel dell'immagine di rendering sarà (216/72)*96 = 288.
Vedi anche
Si applica a
DrawImage(Image, Point[], Rectangle, GraphicsUnit)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destPoints As Point(), srcRect As Rectangle, srcUnit As GraphicsUnit)
Parametri
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma in cui disegnare l'immagine.
Crea un rettangolo per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine sullo schermo.
La posizione del parallelogramma individua l'immagine sullo schermo e le dimensioni del rettangolo e la dimensione e la forma del parallelogramma determina il ridimensionamento e l'shearing dell'immagine disegnata.
private:
void DrawImageParaRect( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create parallelogram for drawing image.
Point ulCorner = Point(100,100);
Point urCorner = Point(325,100);
Point llCorner = Point(150,250);
array<Point>^ destPara = {ulCorner,urCorner,llCorner};
// Create rectangle for source image.
Rectangle srcRect = Rectangle(50,50,150,150);
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw image to screen.
e->Graphics->DrawImage( newImage, destPara, srcRect, units );
}
private void DrawImageParaRect(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create parallelogram for drawing image.
Point ulCorner = new Point(100, 100);
Point urCorner = new Point(325, 100);
Point llCorner = new Point(150, 250);
Point[] destPara = {ulCorner, urCorner, llCorner};
// Create rectangle for source image.
Rectangle srcRect = new Rectangle(50, 50, 150, 150);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw image to screen.
e.Graphics.DrawImage(newImage, destPara, srcRect, units);
}
Private Sub DrawImageParaRect(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create parallelogram for drawing image.
Dim ulCorner As New Point(100, 100)
Dim urCorner As New Point(325, 100)
Dim llCorner As New Point(150, 250)
Dim destPara As Point() = {ulCorner, urCorner, llCorner}
' Create rectangle for source image.
Dim srcRect As New Rectangle(50, 50, 150, 150)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw image to screen.
e.Graphics.DrawImage(newImage, destPara, srcRect, units)
End Sub
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre Point strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dal primo tre per formare un parallelogramma.
Il srcRect
parametro specifica una parte rettangolare dell'oggetto image
da disegnare. Questa porzione viene ridimensionata e viene ridimensionata per adattarsi all'interno del destPoints
parallelogramma specificato dal parametro.
Vedi anche
Si applica a
DrawImage(Image, PointF[], RectangleF, GraphicsUnit)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::PointF> ^ destPoints, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.PointF[] destPoints, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.PointF[] * System.Drawing.RectangleF * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destPoints As PointF(), srcRect As RectangleF, srcUnit As GraphicsUnit)
Parametri
- srcRect
- RectangleF
Struttura RectangleF che specifica la parte dell'oggetto image
da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma di destinazione in cui disegnare l'immagine.
Crea un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine sullo schermo.
La posizione del parallelogramma di destinazione individua l'immagine sullo schermo, le dimensioni del rettangolo di origine e la dimensione e la forma del parallelogramma di destinazione determina il ridimensionamento e l'shearing dell'immagine disegnata e le dimensioni del rettangolo determinano la parte dell'immagine originale sullo schermo.
private:
void DrawImageParaFRectF( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create parallelogram for drawing image.
PointF ulCorner = PointF(100.0F,100.0F);
PointF urCorner = PointF(550.0F,100.0F);
PointF llCorner = PointF(150.0F,250.0F);
array<PointF>^ destPara = {ulCorner,urCorner,llCorner};
// Create rectangle for source image.
RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F);
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw image to screen.
e->Graphics->DrawImage( newImage, destPara, srcRect, units );
}
private void DrawImageParaFRectF(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create parallelogram for drawing image.
PointF ulCorner = new PointF(100.0F, 100.0F);
PointF urCorner = new PointF(550.0F, 100.0F);
PointF llCorner = new PointF(150.0F, 250.0F);
PointF[] destPara = {ulCorner, urCorner, llCorner};
// Create rectangle for source image.
RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw image to screen.
e.Graphics.DrawImage(newImage, destPara, srcRect, units);
}
Private Sub DrawImageParaFRectF(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create parallelogram for drawing image.
Dim ulCorner As New PointF(100.0F, 100.0F)
Dim urCorner As New PointF(550.0F, 100.0F)
Dim llCorner As New PointF(150.0F, 250.0F)
Dim destPara As PointF() = {ulCorner, urCorner, llCorner}
' Create rectangle for source image.
Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw image to screen.
e.Graphics.DrawImage(newImage, destPara, srcRect, units)
End Sub
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre PointF strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dal primo tre per formare un parallelogramma.
Il srcRect
parametro specifica una parte rettangolare dell'oggetto image
da disegnare. Questa porzione viene ridimensionata e viene ridimensionata per adattarsi all'interno del destPoints
parallelogramma specificato dal parametro.
Vedi anche
Si applica a
DrawImage(Image, Rectangle, Rectangle, GraphicsUnit)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::Rectangle destRect, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.Rectangle destRect, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.Rectangle * System.Drawing.Rectangle * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destRect As Rectangle, srcRect As Rectangle, srcUnit As GraphicsUnit)
Parametri
- destRect
- Rectangle
Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea un rettangolo di destinazione in cui disegnare l'immagine.
Crea un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine sullo schermo.
La posizione del rettangolo di destinazione individua l'immagine sullo schermo, le dimensioni dei rettangoli di origine e di destinazione determinano il ridimensionamento dell'immagine disegnata e le dimensioni del rettangolo di origine determinano la parte dell'immagine originale sullo schermo.
private:
void DrawImageRectRect( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create rectangle for displaying image.
Rectangle destRect = Rectangle(100,100,450,150);
// Create rectangle for source image.
Rectangle srcRect = Rectangle(50,50,150,150);
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw image to screen.
e->Graphics->DrawImage( newImage, destRect, srcRect, units );
}
private void DrawImageRectRect(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create rectangle for displaying image.
Rectangle destRect = new Rectangle(100, 100, 450, 150);
// Create rectangle for source image.
Rectangle srcRect = new Rectangle(50, 50, 150, 150);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw image to screen.
e.Graphics.DrawImage(newImage, destRect, srcRect, units);
}
Private Sub DrawImageRectRect(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create rectangle for displaying image.
Dim destRect As New Rectangle(100, 100, 450, 150)
' Create rectangle for source image.
Dim srcRect As New Rectangle(50, 50, 150, 150)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw image to screen.
e.Graphics.DrawImage(newImage, destRect, srcRect, units)
End Sub
Commenti
Il srcRect
parametro specifica una parte rettangolare dell'oggetto image
da disegnare. Questa parte viene ridimensionata per adattarsi al rettangolo specificato dal destRect
parametro.
Vedi anche
Si applica a
DrawImage(Image, RectangleF, RectangleF, GraphicsUnit)
Disegna la parte specificata dell'oggetto Image specificato nella posizione e con le dimensioni specificate.
public:
void DrawImage(System::Drawing::Image ^ image, System::Drawing::RectangleF destRect, System::Drawing::RectangleF srcRect, System::Drawing::GraphicsUnit srcUnit);
public void DrawImage (System.Drawing.Image image, System.Drawing.RectangleF destRect, System.Drawing.RectangleF srcRect, System.Drawing.GraphicsUnit srcUnit);
member this.DrawImage : System.Drawing.Image * System.Drawing.RectangleF * System.Drawing.RectangleF * System.Drawing.GraphicsUnit -> unit
Public Sub DrawImage (image As Image, destRect As RectangleF, srcRect As RectangleF, srcUnit As GraphicsUnit)
Parametri
- destRect
- RectangleF
Struttura RectangleF che specifica la posizione e le dimensioni dell'immagine disegnata. L'immagine viene adattata al rettangolo.
- srcRect
- RectangleF
Struttura RectangleF che specifica la parte dell'oggetto image
da disegnare.
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea un rettangolo di destinazione in cui disegnare l'immagine.
Crea un rettangolo di origine da cui estrarre una parte dell'immagine.
Imposta l'unità di misura del rettangolo di origine su pixel.
Disegna l'immagine sullo schermo.
La posizione del rettangolo di destinazione individua l'immagine sullo schermo, le dimensioni dei rettangoli di origine e di destinazione determinano il ridimensionamento dell'immagine disegnata e le dimensioni del rettangolo di origine determinano la parte dell'immagine originale sullo schermo.
public:
void DrawImageRectFRectF( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create rectangle for displaying image.
RectangleF destRect = RectangleF(100.0F,100.0F,450.0F,150.0F);
// Create rectangle for source image.
RectangleF srcRect = RectangleF(50.0F,50.0F,150.0F,150.0F);
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw image to screen.
e->Graphics->DrawImage( newImage, destRect, srcRect, units );
}
public void DrawImageRectFRectF(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create rectangle for displaying image.
RectangleF destRect = new RectangleF(100.0F, 100.0F, 450.0F, 150.0F);
// Create rectangle for source image.
RectangleF srcRect = new RectangleF(50.0F, 50.0F, 150.0F, 150.0F);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw image to screen.
e.Graphics.DrawImage(newImage, destRect, srcRect, units);
}
Public Sub DrawImageRectFRectF(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create rectangle for displaying image.
Dim destRect As New RectangleF(100.0F, 100.0F, 450.0F, 150.0F)
' Create rectangle for source image.
Dim srcRect As New RectangleF(50.0F, 50.0F, 150.0F, 150.0F)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw image to screen.
e.Graphics.DrawImage(newImage, destRect, srcRect, units)
End Sub
Commenti
Il srcRect
parametro specifica una parte rettangolare dell'oggetto image
da disegnare. Questa parte viene ridimensionata per adattarsi al rettangolo specificato dal destRect
parametro.
Vedi anche
Si applica a
DrawImage(Image, Int32, Int32)
Disegna l'immagine specificata usando le dimensioni fisiche originali nella posizione indicata da una coppia di coordinate.
public:
void DrawImage(System::Drawing::Image ^ image, int x, int y);
public void DrawImage (System.Drawing.Image image, int x, int y);
member this.DrawImage : System.Drawing.Image * int * int -> unit
Public Sub DrawImage (image As Image, x As Integer, y As Integer)
Parametri
- x
- Int32
Coordinata X dell'angolo superiore sinistro dell'immagine disegnata.
- y
- Int32
Coordinata Y dell'angolo superiore sinistro dell'immagine disegnata.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio SampImag.jpg nella cartella dell'esempio.
Crea le coordinate di un punto in corrispondenza del quale disegnare l'angolo superiore sinistro dell'immagine.
Disegna l'immagine non ridimensionata.
public:
void DrawImage2Int( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create coordinates for upper-left corner of image.
int x = 100;
int y = 100;
// Draw image to screen.
e->Graphics->DrawImage( newImage, x, y );
}
public void DrawImage2Int(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create coordinates for upper-left corner of image.
int x = 100;
int y = 100;
// Draw image to screen.
e.Graphics.DrawImage(newImage, x, y);
}
Public Sub DrawImage2Int(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create coordinates for upper-left corner of image.
Dim x As Integer = 100
Dim y As Integer = 100
' Draw image to screen.
e.Graphics.DrawImage(newImage, x, y)
End Sub
Commenti
Un Image archivia un valore per la larghezza dei pixel e un valore per la risoluzione orizzontale (punti per pollice). La larghezza fisica, misurata in pollici, di un'immagine è la larghezza in pixel divisa per la risoluzione orizzontale. Ad esempio, un'immagine con larghezza in pixel di 216 e una risoluzione orizzontale di 72 punti per pollice ha una larghezza fisica di 3 pollici. Le osservazioni simili si applicano all'altezza dei pixel e all'altezza fisica.
Il DrawImage metodo disegna un'immagine usando le dimensioni fisiche, quindi l'immagine avrà le dimensioni corrette in pollici indipendentemente dalla risoluzione (punti per pollice) del dispositivo di visualizzazione. Si supponga, ad esempio, che un'immagine abbia una larghezza in pixel di 216 e una risoluzione orizzontale di 72 punti per pollice. Se si chiama DrawImage per disegnare l'immagine in un dispositivo con una risoluzione di 96 punti per pollice, la larghezza in pixel dell'immagine sottoposta a rendering sarà (216/72)*96 = 288.
Vedi anche
Si applica a
DrawImage(Image, Point[], Rectangle, GraphicsUnit, ImageAttributes)
Disegna la parte specificata dell'oggetto Image specificato nella posizione indicata.
public:
void DrawImage(System::Drawing::Image ^ image, cli::array <System::Drawing::Point> ^ destPoints, System::Drawing::Rectangle srcRect, System::Drawing::GraphicsUnit srcUnit, System::Drawing::Imaging::ImageAttributes ^ imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes imageAttr);
public void DrawImage (System.Drawing.Image image, System.Drawing.Point[] destPoints, System.Drawing.Rectangle srcRect, System.Drawing.GraphicsUnit srcUnit, System.Drawing.Imaging.ImageAttributes? imageAttr);
member this.DrawImage : System.Drawing.Image * System.Drawing.Point[] * System.Drawing.Rectangle * System.Drawing.GraphicsUnit * System.Drawing.Imaging.ImageAttributes -> unit
Public Sub DrawImage (image As Image, destPoints As Point(), srcRect As Rectangle, srcUnit As GraphicsUnit, imageAttr As ImageAttributes)
Parametri
- srcUnit
- GraphicsUnit
Membro dell'enumerazione GraphicsUnit che specifica le unità di misura usate dal parametro srcRect
.
- imageAttr
- ImageAttributes
Oggetto ImageAttributes che specifica le informazioni di ricolorazione e gamma per l'oggetto image
.
Eccezioni
image
è null
.
Esempio
L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse
, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:
Crea un'immagine da un file JPEG SampImag.jpg nella cartella dell'esempio.
Crea punti che definiscono un parallelogramma in cui disegnare l'immagine.
Crea un rettangolo per selezionare la parte dell'immagine da disegnare.
Imposta l'unità di disegno grafica su pixel.
Disegna l'immagine originale sullo schermo.
Crea un parallelogramma aggiuntivo in cui disegnare un'immagine regolata.
Crea e imposta gli attributi dell'immagine modificata in modo da avere un valore gamma più grande del solito.
Disegna l'immagine modificata sullo schermo.
Per il parallelogramma originale, non regolato, la posizione individua l'immagine sullo schermo e le dimensioni del rettangolo e la dimensione e la forma del parallelogramma determinano la scala e l'aringa dell'immagine disegnata.
private:
void DrawImageParaRectAttrib( PaintEventArgs^ e )
{
// Create image.
Image^ newImage = Image::FromFile( "SampImag.jpg" );
// Create parallelogram for drawing image.
Point ulCorner1 = Point(100,100);
Point urCorner1 = Point(325,100);
Point llCorner1 = Point(150,250);
array<Point>^ destPara1 = {ulCorner1,urCorner1,llCorner1};
// Create rectangle for source image.
Rectangle srcRect = Rectangle(50,50,150,150);
GraphicsUnit units = GraphicsUnit::Pixel;
// Draw original image to screen.
e->Graphics->DrawImage( newImage, destPara1, srcRect, units );
// Create parallelogram for drawing adjusted image.
Point ulCorner2 = Point(325,100);
Point urCorner2 = Point(550,100);
Point llCorner2 = Point(375,250);
array<Point>^ destPara2 = {ulCorner2,urCorner2,llCorner2};
// Create image attributes and set large gamma.
ImageAttributes^ imageAttr = gcnew ImageAttributes;
imageAttr->SetGamma( 4.0F );
// Draw adjusted image to screen.
e->Graphics->DrawImage( newImage, destPara2, srcRect, units, imageAttr );
}
private void DrawImageParaRectAttrib(PaintEventArgs e)
{
// Create image.
Image newImage = Image.FromFile("SampImag.jpg");
// Create parallelogram for drawing image.
Point ulCorner1 = new Point(100, 100);
Point urCorner1 = new Point(325, 100);
Point llCorner1 = new Point(150, 250);
Point[] destPara1 = {ulCorner1, urCorner1, llCorner1};
// Create rectangle for source image.
Rectangle srcRect = new Rectangle(50, 50, 150, 150);
GraphicsUnit units = GraphicsUnit.Pixel;
// Draw original image to screen.
e.Graphics.DrawImage(newImage, destPara1, srcRect, units);
// Create parallelogram for drawing adjusted image.
Point ulCorner2 = new Point(325, 100);
Point urCorner2 = new Point(550, 100);
Point llCorner2 = new Point(375, 250);
Point[] destPara2 = {ulCorner2, urCorner2, llCorner2};
// Create image attributes and set large gamma.
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetGamma(4.0F);
// Draw adjusted image to screen.
e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr);
}
Private Sub DrawImageParaRectAttrib(ByVal e As PaintEventArgs)
' Create image.
Dim newImage As Image = Image.FromFile("SampImag.jpg")
' Create parallelogram for drawing image.
Dim ulCorner1 As New Point(100, 100)
Dim urCorner1 As New Point(325, 100)
Dim llCorner1 As New Point(150, 250)
Dim destPara1 As Point() = {ulCorner1, urCorner1, llCorner1}
' Create rectangle for source image.
Dim srcRect As New Rectangle(50, 50, 150, 150)
Dim units As GraphicsUnit = GraphicsUnit.Pixel
' Draw original image to screen.
e.Graphics.DrawImage(newImage, destPara1, srcRect, units)
' Create parallelogram for drawing adjusted image.
Dim ulCorner2 As New Point(325, 100)
Dim urCorner2 As New Point(550, 100)
Dim llCorner2 As New Point(375, 250)
Dim destPara2 As Point() = {ulCorner2, urCorner2, llCorner2}
' Create image attributes and set large gamma.
Dim imageAttr As New ImageAttributes
imageAttr.SetGamma(4.0F)
' Draw adjusted image to screen.
e.Graphics.DrawImage(newImage, destPara2, srcRect, units, _
imageAttr)
End Sub
Commenti
Il destPoints
parametro specifica tre punti di un parallelogramma. Le tre Point strutture rappresentano gli angoli superiore sinistro, superiore destro e inferiore sinistro del parallelogramma. Il quarto punto viene estrapolato dai primi tre per formare un parallelogramma.
Il srcRect
parametro specifica una parte rettangolare dell'oggettoimage
da disegnare. Questa parte viene ridimensionata e ridimensionata per adattarsi all'interno del parallelogramma specificato dal destPoints
parametro .
Vedi anche
Si applica a
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: nel corso del 2024 verranno dismessi i problemi di GitHub come meccanismo di feedback per il contenuto e verranno sostituiti con un nuovo sistema di feedback. Per altre informazioni, vedere:Invia e visualizza il feedback per