Bitmap.LockBits 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
시스템 메모리에 Bitmap 잠깁니다.
오버로드
| Name | Description |
|---|---|
| LockBits(Rectangle, ImageLockMode, PixelFormat) |
시스템 메모리에 Bitmap 잠깁니다. |
| LockBits(Rectangle, ImageLockMode, PixelFormat, BitmapData) |
시스템 메모리에 Bitmap 잠깁니다. |
LockBits(Rectangle, ImageLockMode, PixelFormat)
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
시스템 메모리에 Bitmap 잠깁니다.
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
매개 변수
- flags
- ImageLockMode
에 ImageLockMode 대한 액세스 수준(읽기/쓰기)을 Bitmap지정하는 열거형입니다.
- format
- PixelFormat
PixelFormat 이 Bitmap데이터 형식을 지정하는 열거형입니다.
반품
이 잠금 작업에 대한 정보가 들어 있는 A BitmapData 입니다.
예외
작업이 실패했습니다.
예제
다음 코드 예제에서는 사용 PixelFormat하는 방법을 보여 줍니다. Height, Width및 Scan0 속성; LockBits 및 UnlockBits 메서드; 및 ImageLockMode 열거형입니다. 이 예제는 Windows Forms와 함께 사용하도록 설계되었습니다. 이 예제는 모든 픽셀 형식에서 올바르게 작동하는 것이 아니라 메서드를 사용하는 LockBits 방법의 예를 제공하도록 설계되었습니다. 이 예제를 실행하려면 폼에 붙여넣고 메서드 PaintLockUnlockBitsExample를 호출 e 하여 폼의 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
설명
LockBits 프로그래밍 방식으로 변경할 수 있도록 시스템 메모리에서 기존 비트맵을 잠그려면 이 메서드를 사용합니다. 메서드는 대규모 변경에 더 나은 성능을 제공하지만 메서드를 SetPixel 사용하여 이미지 LockBits 의 색을 변경할 수 있습니다.
크기 BitmapData , 픽셀 형식, 메모리에 Bitmap있는 픽셀 데이터의 시작 주소 및 각 스캔 줄의 길이(stride)와 같은 특성이 지정됩니다.
이 메서드를 호출할 때 특정 BPP(픽셀당 비트) 값을 포함하는 열거형의 System.Drawing.Imaging.PixelFormat 멤버를 사용해야 합니다. 와 같은 System.Drawing.Imaging.PixelFormatIndexed 값을 사용하면 .GdiSystem.ArgumentException 또한 비트맵에 잘못된 픽셀 형식을 전달하면 .System.ArgumentException
적용 대상
LockBits(Rectangle, ImageLockMode, PixelFormat, BitmapData)
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
- Source:
- Bitmap.cs
시스템 메모리에 Bitmap 잠깁니다.
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
매개 변수
- flags
- ImageLockMode
에 ImageLockMode 대한 액세스 수준(읽기/쓰기)을 Bitmap지정하는 값 중 하나입니다.
- format
- PixelFormat
의 PixelFormat 데이터 형식을 지정하는 값 중 Bitmap하나입니다.
- bitmapData
- BitmapData
잠금 작업에 대한 정보가 들어 있는 A BitmapData 입니다.
반품
잠금 작업에 대한 정보가 들어 있는 A BitmapData 입니다.
예외
작업이 실패했습니다.
설명
LockBits 프로그래밍 방식으로 변경할 수 있도록 시스템 메모리에서 기존 비트맵을 잠그려면 이 메서드를 사용합니다. 메서드는 대규모 변경에 더 나은 성능을 제공하지만 메서드를 SetPixel 사용하여 이미지 LockBits 의 색을 변경할 수 있습니다.
이 메서드를 호출할 때 특정 BPP(픽셀당 비트) 값을 포함하는 열거형의 System.Drawing.Imaging.PixelFormat 멤버를 사용해야 합니다. 와 같은 System.Drawing.Imaging.PixelFormatIndexed값을 사용하면 .GdiSystem.ArgumentException 또한 비트맵에 잘못된 픽셀 형식을 전달하면 .System.ArgumentException
이 버전의 LockBits 메서드는 값flags과 함께 ImageLockMode.UserInputBuffer 사용됩니다.