Bitmap コンストラクタ (String)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
例外
このファイルは Bitmap が破棄されるまでロックされます。
GDI+ デコーダには制約があるので、65,535 ピクセルよりも大きい 1 次元の .png イメージ ファイルからビットマップを作成した場合、System.ArgumentException がスローされます。
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Image)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
プラットフォーム
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Stream, Boolean)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
例外
Bitmap の有効期間の間は、このストリームを開いておく必要があります。
GDI+ デコーダには制約があるので、65,535 ピクセルよりも大きい 1 次元の .png イメージ ファイルからビットマップを作成した場合、System.ArgumentException がスローされます。
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Stream)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
例外
Bitmap の有効期間の間は、このストリームを開いておく必要があります。
GDI+ デコーダには制約があるので、65,535 ピクセルよりも大きい 1 次元の .png イメージ ファイルからビットマップを作成した場合、System.ArgumentException がスローされます。
ビットマップをストリームから読み込む方法を次のコード例に示します。
この例は、Windows フォームでの使用を意図してデザインされています。PictureBox1 という名前の PictureBox を格納するフォームを作成します。コードをフォームに貼り付けて、InitializeStreamBitmap メソッドをフォームのコンストラクタ 、または Load イベント処理メソッドから呼び出します。
Private Sub InitializeStreamBitmap() Try Dim request As System.Net.WebRequest = _ System.Net.WebRequest.Create( _ "http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif") Dim response As System.Net.WebResponse = request.GetResponse() Dim responseStream As System.IO.Stream = response.GetResponseStream() Dim bitmap2 As New Bitmap(responseStream) PictureBox1.Image = bitmap2 Catch ex As System.Net.WebException MessageBox.Show("There was an error opening the image file. Check the URL") End Try End Sub
private void InitializeStreamBitmap() { try { System.Net.WebRequest request = System.Net.WebRequest.Create( "http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif"); System.Net.WebResponse response = request.GetResponse(); System.IO.Stream responseStream = response.GetResponseStream(); Bitmap bitmap2 = new Bitmap(responseStream); PictureBox1.Image = bitmap2; } catch(System.Net.WebException) { MessageBox.Show("There was an error opening the image file." + "Check the URL"); } }
void InitializeStreamBitmap() { try { System::Net::WebRequest^ request = System::Net::WebRequest::Create( "http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif" ); System::Net::WebResponse^ response = request->GetResponse(); System::IO::Stream^ responseStream = response->GetResponseStream(); Bitmap^ bitmap2 = gcnew Bitmap( responseStream ); PictureBox1->Image = bitmap2; } catch ( System::Net::WebException^ ) { MessageBox::Show( "There was an error opening the image file." "Check the URL" ); } }
private void InitializeStreamBitmap() { try { System.Net.WebRequest request = System.Net.WebRequest.Create( "http://www.microsoft.com//h/en-us/r/ms_masthead_ltr.gif"); System.Net.WebResponse response = request.GetResponse(); System.IO.Stream responseStream = response.GetResponseStream(); Bitmap bitmap2 = new Bitmap(responseStream); pictureBox1.set_Image(bitmap2); } catch (System.Net.WebException exp) { MessageBox.Show(("There was an error opening the image file." + "Check the URL")); } } //InitializeStreamBitmap
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Int32, Int32, Int32, PixelFormat, IntPtr)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
Public Sub New ( _ width As Integer, _ height As Integer, _ stride As Integer, _ format As PixelFormat, _ scan0 As IntPtr _ )
Dim width As Integer Dim height As Integer Dim stride As Integer Dim format As PixelFormat Dim scan0 As IntPtr Dim instance As New Bitmap(width, height, stride, format, scan0)
public function Bitmap ( width : int, height : int, stride : int, format : PixelFormat, scan0 : IntPtr )
.NET Framework のセキュリティ
- SecurityPermission (アンマネージ コードを呼び出すために必要なアクセス許可)。UnmanagedCode (関連する列挙体)
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Image, Size)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
例外
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (String, Boolean)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
例外
このファイルは Bitmap が破棄されるまでロックされます。
GDI+ デコーダには制約があるので、65,535 ピクセルよりも大きい 1 次元の .png イメージ ファイルからビットマップを作成した場合、System.ArgumentException がスローされます。
GetPixel および SetPixel メソッドを使用して、イメージの色を変更する方法を次のコード例に示します。また、この例では PixelFormat プロパティも使用しています。
この例は、Label1 という名前の Label、PictureBox1 という名前の PictureBox、および Button1 という名前の Buttonを含んだ Windows フォームでの使用を意図してデザインされています。コードをフォームに貼り付け、Button1_Click メソッドをボタンの Click イベントに関連付けます。
Dim image1 As Bitmap Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Try ' Retrieve the image. image1 = New Bitmap( _ "C:\Documents and Settings\All Users\Documents\My Music\music.bmp", _ True) Dim x, y As Integer ' Loop through the images pixels to reset color. For x = 0 To image1.Width - 1 For y = 0 To image1.Height - 1 Dim pixelColor As Color = image1.GetPixel(x, y) Dim newColor As Color = _ Color.FromArgb(pixelColor.R, 0, 0) image1.SetPixel(x, y, newColor) Next Next ' Set the PictureBox to display the image. PictureBox1.Image = image1 ' Display the pixel format in Label1. Label1.Text = "Pixel format: " + image1.PixelFormat.ToString() Catch ex As ArgumentException MessageBox.Show("There was an error." _ & "Check the path to the image file.") End Try End Sub
Bitmap image1; private void Button1_Click(System.Object sender, System.EventArgs e) { try { // Retrieve the image. image1 = new Bitmap(@"C:\Documents and Settings\All Users\" + @"Documents\My Music\music.bmp", true); int x, y; // Loop through the images pixels to reset color. for(x=0; x<image1.Width; x++) { for(y=0; y<image1.Height; y++) { Color pixelColor = image1.GetPixel(x, y); Color newColor = Color.FromArgb(pixelColor.R, 0, 0); image1.SetPixel(x, y, newColor); } } // Set the PictureBox to display the image. PictureBox1.Image = image1; // Display the pixel format in Label1. Label1.Text = "Pixel format: "+image1.PixelFormat.ToString(); } catch(ArgumentException) { MessageBox.Show("There was an error." + "Check the path to the image file."); } }
private: Bitmap^ image1; void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ ) { try { // Retrieve the image. image1 = gcnew Bitmap( "C:\\Documents and Settings\\All Users\\" "Documents\\My Music\\music.bmp",true ); int x; int y; // Loop through the images pixels to reset color. for ( x = 0; x < image1->Width; x++ ) { for ( y = 0; y < image1->Height; y++ ) { Color pixelColor = image1->GetPixel( x, y ); Color newColor = Color::FromArgb( pixelColor.R, 0, 0 ); image1->SetPixel( x, y, newColor ); } } // Set the PictureBox to display the image. PictureBox1->Image = image1; // Display the pixel format in Label1. Label1->Text = String::Format( "Pixel format: {0}", image1->PixelFormat ); } catch ( ArgumentException^ ) { MessageBox::Show( "There was an error." "Check the path to the image file." ); } }
private Bitmap image1; private void button1_Click(Object sender, System.EventArgs e) { try { // Retrieve the image. image1 = new Bitmap("C:\\Documents and Settings\\All Users\\" + "Documents\\My Music\\music.bmp", true); int x, y; // Loop through the images pixels to reset color. for (x = 0; x < image1.get_Width(); x++) { for (y = 0; y < image1.get_Height(); y++) { Color pixelColor = image1.GetPixel(x, y); Color newColor = Color.FromArgb(pixelColor.get_R(), 0, 0); image1.SetPixel(x, y, newColor); } } // Set the PictureBox to display the image. pictureBox1.set_Image(image1); // Display the pixel format in label1. label1.set_Text("Pixel format: " + image1.get_PixelFormat().ToString()); } catch (ArgumentException exp) { MessageBox.Show(("There was an error." + "Check the path to the image file.")); } } //button1_Click
- SecurityPermission (アンマネージ コードを呼び出すために必要なアクセス許可)。UnmanagedCode (関連する列挙体)
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Image, Int32, Int32)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
Dim original As Image Dim width As Integer Dim height As Integer Dim instance As New Bitmap(original, width, height)
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Int32, Int32, PixelFormat)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
Dim width As Integer Dim height As Integer Dim format As PixelFormat Dim instance As New Bitmap(width, height, format)
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Type, String)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
解説
このコンストラクタは、特定の型の名前空間をリソースの文字列名と組み合わせて、アセンブリ マニフェスト内で一致を探します。たとえば、Button 型および Button.bmp をこのコンストラクタに渡すと、コンストラクタは System.Windows.Forms.Button.bmp という名前のリソースを探します。
ビットマップを型から作成する方法、および Save メソッドを使用する方法を次のコード例に示します。この例を実行するには、コードを Windows フォームに貼り付けます。フォームの Paint イベントを処理し、ConstructFromResourceSaveAsGif メソッドを呼び出し、e を PaintEventArgs として渡します。
Private Sub ConstructFromResourceSaveAsGif(ByVal e As PaintEventArgs) ' Construct a bitmap from the button image resource. Dim bmp1 As New Bitmap(GetType(Button), "Button.bmp") ' Save the image as a GIF. bmp1.Save("c:\button.gif", System.Drawing.Imaging.ImageFormat.Gif) ' Construct a new image from the GIF file. Dim bmp2 As New Bitmap("c:\button.gif") ' Draw the two images. e.Graphics.DrawImage(bmp1, New Point(10, 10)) e.Graphics.DrawImage(bmp2, New Point(10, 40)) ' Dispose of the image files. bmp1.Dispose() bmp2.Dispose() End Sub
private void ConstructFromResourceSaveAsGif(PaintEventArgs e) { // Construct a bitmap from the button image resource. Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp"); // Save the image as a GIF. bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif); // Construct a new image from the GIF file. Bitmap bmp2 = new Bitmap("c:\\button.gif"); // Draw the two images. e.Graphics.DrawImage(bmp1, new Point(10, 10)); e.Graphics.DrawImage(bmp2, new Point(10, 40)); // Dispose of the image files. bmp1.Dispose(); bmp2.Dispose(); }
private: void ConstructFromResourceSaveAsGif(PaintEventArgs^ e) { // Construct a bitmap from the button image resource. Bitmap^ bmp1 = gcnew Bitmap(Button::typeid, "Button.bmp"); String^ savePath = Environment::GetEnvironmentVariable("TEMP") + "\\Button.bmp"; try { // Save the image as a GIF. bmp1->Save(savePath, System::Drawing::Imaging::ImageFormat::Gif); } catch (IOException^) { // Carry on regardless } // Construct a new image from the GIF file. Bitmap^ bmp2 = nullptr; if (File::Exists(savePath)) { bmp2 = gcnew Bitmap(savePath); } // Draw the two images. e->Graphics->DrawImage(bmp1, Point(10, 10)); // If bmp1 did not save to disk, bmp2 may be null if (bmp2 != nullptr) { e->Graphics->DrawImage(bmp2, Point(10, 40)); } // Dispose of the image files. delete bmp1; if (bmp2 != nullptr) { delete bmp2; } }
private void ConstructFromResourceSaveAsGif(PaintEventArgs e) { // Construct a bitmap from the button image resource. Bitmap bmp1 = new Bitmap(Button.class.ToType(), "Button.bmp"); // Save the image as a GIF. bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.get_Gif()); // Construct a new image from the GIF file. Bitmap bmp2 = new Bitmap("c:\\button.gif"); // Draw the two images. e.get_Graphics().DrawImage(bmp1, new Point(10, 10)); e.get_Graphics().DrawImage(bmp2, new Point(10, 40)); // Dispose of the image files. bmp1.Dispose(); bmp2.Dispose(); } //ConstructFromResourceSaveAsGif
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Int32, Int32)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
例外
解説
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ (Int32, Int32, Graphics)
アセンブリ: System.Drawing (system.drawing.dll 内)
構文
Dim width As Integer Dim height As Integer Dim g As Graphics Dim instance As New Bitmap(width, height, g)
解説
プラットフォーム
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
Bitmap コンストラクタ
オーバーロードの一覧
- Bitmap コンストラクタのページへのリンク