BitmapData 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
비트맵 이미지의 특성을 지정합니다. 클래스는 BitmapData 클래스의 LockBits 메서드 및 UnlockBits(BitmapData) 메서드에서 Bitmap 사용됩니다. 상속할 수 없습니다.
public ref class BitmapData sealed
public sealed class BitmapData
type BitmapData = class
Public NotInheritable Class BitmapData
- 상속
-
BitmapData
예제
다음 코드 예제에서는 클래스 LockBits 와 UnlockBits 메서드를 BitmapData 사용하는 방법을 보여 줍니다. 이 예제는 Windows Forms와 함께 사용하도록 설계되었습니다. 이 예제를 실행하려면 폼에 붙여넣고 메서드 ePaintEventArgs를 호출 LockUnlockBitsExample 하여 폼의 Paint 이벤트를 처리합니다.
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
생성자
| Name | Description |
|---|---|
| BitmapData() |
BitmapData 클래스의 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| Height |
개체의 픽셀 높이를 Bitmap 가져오거나 설정합니다. 또한 검사 줄의 수라고도 합니다. |
| PixelFormat |
이 BitmapData 개체를 반환한 개체의 픽셀 정보 형식을 Bitmap 가져오거나 설정합니다. |
| Reserved |
예약되었습니다. 사용하지 마세요. |
| Scan0 |
비트맵에서 첫 번째 픽셀 데이터의 주소를 가져오거나 설정합니다. 비트맵의 첫 번째 검색 줄로 간주할 수도 있습니다. |
| Stride |
개체의 보폭 너비(스캔 너비라고도 함) Bitmap 를 가져오거나 설정합니다. |
| Width |
개체의 픽셀 너비를 Bitmap 가져오거나 설정합니다. 한 스캔 줄의 픽셀 수로 간주할 수도 있습니다. |
메서드
| Name | Description |
|---|---|
| Equals(Object) |
지정한 개체와 현재 개체가 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| GetHashCode() |
기본 해시 함수로 작동합니다. (다음에서 상속됨 Object) |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |