本文目錄一覽:
c#的bitmap類是什麼 博客園
Bitmap 類
封裝 GDI+ 位圖,此位圖由圖形圖像及其特性的像素數據組成。 Bitmap 是用於處理由像素數據定義的圖像的對象。
命名空間: System.Drawing
程序集: System.Drawing(在 System.Drawing.dll 中)
示例:
下面的代碼示例演示了如何使用 GetPixel 和 SetPixel 方法從文件構造新的 Bitmap,為圖像重新着色。 它還使用 PixelFormat、Width 和 Height 屬性。
此示例旨在用於包含名為 Label1 的 Label、名為 PictureBox1 的 PictureBox 和名為 Button1 的 Button 的 Windows 窗體。 將代碼粘貼到該窗體中,並將 Button1_Click 方法與按鈕的 Click 事件關聯。
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; ximage1.Width; x++)
{
for(y=0; yimage1.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.”);
}
}
如何用C語言在已有的bmp圖片上添加文字生成新的圖片?
用C語言在已有的bmp圖片上添加文字生成新的圖片方法是:
1、首先要了解位圖文件的結構和熟悉C語言的畫圖函數等基層知識,這些知識可以在網上找到自學;
2、BMP(全稱Bitmap)是Windows操作系統中的標準圖像文件格式,可以分成兩類:設備相關位圖(DDB)和設備無關位圖(DIB),它採用位映射存儲格式,除了圖像深度可選以外,不採用其他任何壓縮,因此,BMP文件所佔用的空間很大,BMP文件存儲數據時,圖像的掃描方式是按從左到右、從下到上的順序,由於BMP文件格式是Windows環境中交換與圖有關的數據的一種標準,因此在Windows環境中運行的圖形圖像軟件都支持BMP圖像格式,圖像中每個像素的顏色值都保存在BMP文件中。
3、C語言是一種計算機程序設計語言,它既有高級語言的特點,又具有彙編語言的特點,它可以作為系統設計語言,編寫工作系統應用程序,也可以作為應用程序設計語言,編寫不依賴計算機硬件的應用程序,因此,它的應用範圍廣泛,
用C語言顯示BMP圖片,最直接的方法就是先將每個像素的顏色值提取出來,再用C語言的畫圖函數畫。
C#Bitmap是幹什麼用的?能幫我解釋下嗎?
c#.net Bitmap類的基本使用方法 Bitmap 類更新:2007 年 11 月封裝 GDI+ 位圖,此位圖由圖形圖像及其屬性的像素數據組成。Bitmap 是用於處理由像素數據定義的圖像的對象。 命名空間: System.Drawing
程序集: System.Drawing(在 System.Drawing.dll 中) 語法
Visual Basic(聲明)
SerializableAttribute _
ComVisibleAttribute(True) _
Public NotInheritable Class Bitmap _
Inherits ImageVisual Basic (用法)
Dim instance As BitmapC#
[SerializableAttribute]
[ComVisibleAttribute(true)]
public sealed class Bitmap : ImageVisual C++
[SerializableAttribute]
[ComVisibleAttribute(true)]
public ref class Bitmap sealed : public ImageJ#
/** @attribute SerializableAttribute */
/** @attribute ComVisibleAttribute(true) */
public final class Bitmap extends ImageJScript
public final class Bitmap extends Image
備註
位圖由圖形圖像及其屬性的像素數據組成。可使用許多標準格式將位圖保存到文件中。GDI+ 支持下列文件格式:BMP、GIF、EXIG、JPG、PNG 和 TIFF。有關支持的格式的更多信息,請參見位圖類型。 可以使用 Bitmap 構造函數中的一種來從文件、流和其他源創建圖像,然後使用 Save 方法將這些圖像保存到流或文件系統中。使用 Graphics 對象的 DrawImage 方法,將圖像繪製到屏幕上或內存中。有關使用圖像文件的主題的列表,請參見使用圖像、位圖、圖標和圖元文件。 說明:
不能跨應用程序域訪問 Bitmap 類。例如,如果您創建了一個動態 AppDomain,並在該域中創建了幾個畫筆、鋼筆和位圖,然後將這些對象傳遞迴主應用程序域,則您可以成功使用這些鋼筆和畫筆。但是,如果您調用 DrawImage 方法來繪製封送的 Bitmap,您會收到以下異常信息。遠程處理無法在類型“System.Drawing.Image”上找到字段“本機映像”。
示例
下面的代碼示例演示了如何使用 GetPixel 和 SetPixel 方法從文件構造新的 Bitmap,為圖像重新着色。它還使用 PixelFormat、Width 和 Height 屬性。 此示例旨在用於包含名為 Label1 的 Label、名為 PictureBox1 的 PictureBox 和名為 Button1 的 Button 的 Windows 窗體。將代碼粘貼到該窗體中,並將 Button1_Click 方法與按鈕的 Click 事件關聯。 Visual Basic 複製代碼
Dim image1 As BitmapPrivate 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
C# 複製代碼
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; ximage1.Width; x++)
{
for(y=0; yimage1.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.”);
}
}
原創文章,作者:PINR,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/133440.html