Bitmap.LockBits Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Bir Bitmap sistem belleğine kilitler.
Aşırı Yüklemeler
| Name | Description |
|---|---|
| LockBits(Rectangle, ImageLockMode, PixelFormat) |
Bir Bitmap sistem belleğine kilitler. |
| LockBits(Rectangle, ImageLockMode, PixelFormat, BitmapData) |
Bir Bitmap sistem belleğine kilitler. |
LockBits(Rectangle, ImageLockMode, PixelFormat)
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
Bir Bitmap sistem belleğine kilitler.
public:
System::Drawing::Imaging::BitmapData ^ LockBits(System::Drawing::Rectangle rect, System::Drawing::Imaging::ImageLockMode flags, System::Drawing::Imaging::PixelFormat format);
public System.Drawing.Imaging.BitmapData LockBits(System.Drawing.Rectangle rect, System.Drawing.Imaging.ImageLockMode flags, System.Drawing.Imaging.PixelFormat format);
member this.LockBits : System.Drawing.Rectangle * System.Drawing.Imaging.ImageLockMode * System.Drawing.Imaging.PixelFormat -> System.Drawing.Imaging.BitmapData
Public Function LockBits (rect As Rectangle, flags As ImageLockMode, format As PixelFormat) As BitmapData
Parametreler
- flags
- ImageLockMode
ImageLockMode için Bitmaperişim düzeyini (okuma/yazma) belirten bir numaralandırma.
- format
- PixelFormat
PixelFormat Bu Bitmapöğesinin veri biçimini belirten bir numaralandırma.
Döndürülenler
BitmapData Bu kilit işlemi hakkında bilgi içeren bir.
Özel durumlar
PixelFormat belirli bir bit/piksel değeri değildir.
-veya-
Bit eşlem için yanlış PixelFormat geçirilir.
İşlem başarısız oldu.
Örnekler
Aşağıdaki kod örneği, , , PixelFormatHeightve özelliklerinin, ve WidthScan0 yöntemlerinin LockBits ve numaralandırmasının UnlockBits nasıl kullanılacağını ImageLockModegösterir. Bu örnek, Windows Forms ile kullanılacak şekilde tasarlanmıştır. Bu örnek, tüm piksel biçimleriyle doğru çalışacak şekilde tasarlanmamıştır, yöntemin nasıl kullanılacağına LockBits ilişkin bir örnek sağlamak için tasarlanmıştır. Bu örneği çalıştırmak için bir forma yapıştırın ve yöntemini çağırarak formun PaintLockUnlockBitsExample olayını işleyip e olarak PaintEventArgsgeçirin.
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
Açıklamalar
LockBits Program aracılığıyla değiştirebilmek için sistem belleğindeki mevcut bit eşlemi kilitlemek için yöntemini kullanın. Yöntemi büyük ölçekli değişiklikler için daha iyi performans sunsa daSetPixel, yöntemiyle LockBits görüntünün rengini değiştirebilirsiniz.
boyutu BitmapData , piksel biçimi, bellekteki piksel verilerinin başlangıç adresi ve her tarama çizgisinin uzunluğu (adım) gibi özniteliklerini Bitmapbelirtir.
Bu yöntemi çağırırken, sabit listesinin System.Drawing.Imaging.PixelFormat belirli bir bit/piksel (BPP) değeri içeren bir üyesini kullanmanız gerekir. ve gibi System.Drawing.Imaging.PixelFormatIndexed değerlerin kullanılması Gdi bir System.ArgumentExceptionoluşturur. Ayrıca, bit eşlem için yanlış piksel biçimini geçirmek bir System.ArgumentExceptionoluşturur.
Şunlara uygulanır
LockBits(Rectangle, ImageLockMode, PixelFormat, BitmapData)
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
- Kaynak:
- Bitmap.cs
Bir Bitmap sistem belleğine kilitler.
public:
System::Drawing::Imaging::BitmapData ^ LockBits(System::Drawing::Rectangle rect, System::Drawing::Imaging::ImageLockMode flags, System::Drawing::Imaging::PixelFormat format, System::Drawing::Imaging::BitmapData ^ bitmapData);
public System.Drawing.Imaging.BitmapData LockBits(System.Drawing.Rectangle rect, System.Drawing.Imaging.ImageLockMode flags, System.Drawing.Imaging.PixelFormat format, System.Drawing.Imaging.BitmapData bitmapData);
member this.LockBits : System.Drawing.Rectangle * System.Drawing.Imaging.ImageLockMode * System.Drawing.Imaging.PixelFormat * System.Drawing.Imaging.BitmapData -> System.Drawing.Imaging.BitmapData
Public Function LockBits (rect As Rectangle, flags As ImageLockMode, format As PixelFormat, bitmapData As BitmapData) As BitmapData
Parametreler
- flags
- ImageLockMode
ImageLockMode için Bitmaperişim düzeyini (okuma/yazma) belirten değerlerden biri.
- format
- PixelFormat
veri PixelFormat biçimini Bitmapbelirten değerlerden biri.
- bitmapData
- BitmapData
BitmapData Kilit işlemi hakkında bilgi içeren bir.
Döndürülenler
BitmapData Kilit işlemi hakkında bilgi içeren bir.
Özel durumlar
PixelFormat değer, piksel başına belirli bir bit değeri değildir.
-veya-
Bit eşlem için yanlış PixelFormat geçirilir.
İşlem başarısız oldu.
Açıklamalar
LockBits Program aracılığıyla değiştirebilmek için sistem belleğindeki mevcut bit eşlemi kilitlemek için yöntemini kullanın. Yöntemi büyük ölçekli değişiklikler için daha iyi performans sunsa daSetPixel, yöntemiyle LockBits görüntünün rengini değiştirebilirsiniz.
Bu yöntemi çağırırken, sabit listesinin System.Drawing.Imaging.PixelFormat belirli bir bit/piksel (BPP) değeri içeren bir üyesini kullanmanız gerekir. ve System.Drawing.Imaging.PixelFormatgibi Indexed değerlerin kullanılması Gdi bir System.ArgumentExceptionoluşturur. Ayrıca, bit eşlem için yanlış piksel biçimini geçirmek bir System.ArgumentExceptionoluşturur.
Yönteminin LockBits bu sürümü değeriyle flagsImageLockMode.UserInputBufferkullanılmak üzere tasarlanmıştır.