ImageLockMode ImageLockMode ImageLockMode ImageLockMode Enum

Definición

Especifica los marcadores que se pasan al parámetro marcadores del método LockBits. El método LockBits bloquea una parte de una imagen para poder leer o escribir los datos de píxeles.The LockBits method locks a portion of an image so that you can read or write the pixel data.

public enum class ImageLockMode
public enum ImageLockMode
type ImageLockMode = 
Public Enum ImageLockMode
Herencia
ImageLockModeImageLockModeImageLockModeImageLockMode

Campos

ReadOnly ReadOnly ReadOnly ReadOnly 1

Especifica que una porción de la imagen está bloqueada para lectura.Specifies that a portion of the image is locked for reading.

ReadWrite ReadWrite ReadWrite ReadWrite 3

Especifica que una porción de la imagen está bloqueada para lectura o escritura.Specifies that a portion of the image is locked for reading or writing.

UserInputBuffer UserInputBuffer UserInputBuffer UserInputBuffer 4

Especifica que el búfer que se utiliza para leer o escribir datos de píxeles lo asigna el usuario.Specifies that the buffer used for reading or writing pixel data is allocated by the user. Si se establece este marcador, el parámetro flags del método LockBits actúa como parámetro de entrada (y quizá como parámetro de salida).If this flag is set, the flags parameter of the LockBits method serves as an input parameter (and possibly as an output parameter). Si se desactiva este marcador, el parámetro flags actúa únicamente como parámetro de salida.If this flag is cleared, then the flags parameter serves only as an output parameter.

WriteOnly WriteOnly WriteOnly WriteOnly 2

Especifica que una porción de la imagen está bloqueada para escritura.Specifies that a portion of the image is locked for writing.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el PixelFormat, Height, Width, y Scan0 propiedades; el LockBits y UnlockBits métodos; y el ImageLockMode enumeración.The following code example demonstrates how to use the PixelFormat, Height, Width, and Scan0 properties; the LockBits and UnlockBits methods; and the ImageLockMode enumeration. En este ejemplo está diseñado para usarse con Windows Forms.This example is designed to be used with Windows Forms. Para ejecutar este ejemplo, péguelo en un formulario y controlar el formato Paint eventos mediante una llamada a la LockUnlockBitsExample método, pasando e como PaintEventArgs.To run this example, paste it into a form and handle the form's Paint event by calling the LockUnlockBitsExample method, passing e as PaintEventArgs.

void LockUnlockBitsExample( PaintEventArgs^ e )
{
   // Create a new bitmap.
   Bitmap^ bmp = gcnew Bitmap( "c:\\fakePhoto.jpg" );

   // Lock the bitmap's bits.  
   Rectangle rect = Rectangle(0,0,bmp->Width,bmp->Height);
   System::Drawing::Imaging::BitmapData^ bmpData = bmp->LockBits( rect, System::Drawing::Imaging::ImageLockMode::ReadWrite, bmp->PixelFormat );

   // Get the address of the first line.
   IntPtr ptr = bmpData->Scan0;

   // Declare an array to hold the bytes of the bitmap.
   // This code is specific to a bitmap with 24 bits per pixels.
   int bytes = Math::Abs(bmpData->Stride) * bmp->Height;
   array<Byte>^rgbValues = gcnew array<Byte>(bytes);

   // Copy the RGB values into the array.
   System::Runtime::InteropServices::Marshal::Copy( ptr, rgbValues, 0, bytes );

   // Set every third value to 255.  
   for ( int counter = 2; counter < rgbValues->Length; counter += 3 )
      rgbValues[ counter ] = 255;

   // Copy the RGB values back to the bitmap
   System::Runtime::InteropServices::Marshal::Copy( rgbValues, 0, ptr, bytes );

   // Unlock the bits.
   bmp->UnlockBits( bmpData );

   // Draw the modified image.
   e->Graphics->DrawImage( bmp, 0, 150 );
}
private void LockUnlockBitsExample(PaintEventArgs e)
    {

        // Create a new bitmap.
        Bitmap bmp = new Bitmap("c:\\fakePhoto.jpg");

        // Lock the bitmap's bits.  
        Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
        System.Drawing.Imaging.BitmapData bmpData =
            bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
            bmp.PixelFormat);

        // Get the address of the first line.
        IntPtr ptr = bmpData.Scan0;

        // Declare an array to hold the bytes of the bitmap.
        int bytes  = Math.Abs(bmpData.Stride) * bmp.Height;
        byte[] rgbValues = new byte[bytes];

        // Copy the RGB values into the array.
        System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

        // Set every third value to 255. A 24bpp bitmap will look red.  
        for (int counter = 2; counter < rgbValues.Length; counter += 3)
            rgbValues[counter] = 255;

        // Copy the RGB values back to the bitmap
        System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes);

        // Unlock the bits.
        bmp.UnlockBits(bmpData);

        // Draw the modified image.
        e.Graphics.DrawImage(bmp, 0, 150);

    }

Private Sub LockUnlockBitsExample(ByVal e As PaintEventArgs)

    ' Create a new bitmap.
    Dim bmp As New Bitmap("c:\fakePhoto.jpg")

    ' Lock the bitmap's bits.  
    Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
    Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(rect, _
        Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat)

    ' Get the address of the first line.
    Dim ptr As IntPtr = bmpData.Scan0

    ' Declare an array to hold the bytes of the bitmap.
    ' This code is specific to a bitmap with 24 bits per pixels.
    Dim bytes As Integer = Math.Abs(bmpData.Stride) * bmp.Height
    Dim rgbValues(bytes - 1) As Byte

    ' Copy the RGB values into the array.
    System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes)

    ' Set every third value to 255. A 24bpp image will look red.
    For counter As Integer = 2 To rgbValues.Length - 1 Step 3
        rgbValues(counter) = 255
    Next

    ' Copy the RGB values back to the bitmap
    System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes)

    ' Unlock the bits.
    bmp.UnlockBits(bmpData)

    ' Draw the modified image.
    e.Graphics.DrawImage(bmp, 0, 150)

End Sub

Se aplica a