PictureBox 读取图片及绘画[亲测有效]

(41) 2023-03-26 19:32

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说PictureBox 读取图片及绘画[亲测有效],希望能够帮助你!!!。
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第1张



Form1.cs

 
文件如下:

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
using System;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
using System.Drawing;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
using System.Collections;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
using System.ComponentModel;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
using System.Windows.Forms;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
using System.Data;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
//
myself

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张

using System.Collections.Specialized;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
using System.Text;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
using System.Drawing.Imaging;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
using System.Runtime.InteropServices;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第2张
namespace haopai


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第16张 {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张    
///
 
<summary>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张    

///
 Form1 的摘要说明。
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张    

///
 
</summary>


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张    
public 
class Form1 : System.Windows.Forms.Form


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张    {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        
///
 
<summary>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        

///
 必需的设计器变量。
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        

///
 
</summary>


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.ComponentModel.Container components = 
null;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
public Form1()


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
//

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
 Windows 窗体设计器支持所必需的
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
            InitializeComponent();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
//

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
 TODO: 在 InitializeComponent 调用后添加任何构造函数代码
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张
        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        
///
 
<summary>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        

///
 清理所有正在使用的资源。
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        

///
 
</summary>


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
protected 
override 
void Dispose( 
bool disposing )


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
if( disposing )


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
if (components != 
null


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张                {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    components.Dispose();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张                }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张            }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
base.Dispose( disposing );


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第54张        
Windows 窗体设计器生成的代码


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        
///
 
<summary>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        

///
 应用程序的主入口点。
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        

///
 
</summary>


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        [STAThread]


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
static 
void Main() 


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            Application.Run(
new Form1());


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private 
void Form1_Load(
object sender, System.EventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张              
//
 GrayByPixels();  
//
灰度处理

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张
        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.PictureBox pictureBox1;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.Label r;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.TextBox valueBox;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.Button getbutton;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.TrackBar trackBar1;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.Label label1;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.Label label2;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.TextBox txtStartX;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.TextBox txtStartY;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.TextBox txtEndX;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.TextBox txtEndY;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.Label label5;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.Label label6;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.Label label3;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.Label label4;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private System.Windows.Forms.Button btn_SavePoint; 
//
灰度值

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
protected  
int  nHuidu = 
0;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
public  Bitmap bmpobj;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private Cursor inCursor;  
//
鼠标样式

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private Cursor MyCursor;  
//
鼠标样式

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private Point m_ptStart = 
new Point(
0,
0);


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private Point m_ptEnd = 
new Point(
0
0);


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private 
bool m_bMouseDown = 
false;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
//
读取图片

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private 
void getbutton_Click(
object sender, System.EventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
try


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                bmpobj=
null
//
初始化为空

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
                
string path = Application.ExecutablePath.Substring(
0,Application.ExecutablePath.LastIndexOf(
"
\\
"))+ 
"
\\aa.jpg
";


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                Image get_Image = Image.FromFile(path); 


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                pictureBox1.Image =get_Image;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                 GrayByPixels();  
//
灰度处理
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                

//
初始化trackBar1

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
                trackBar1.Value = nHuidu;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张            }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
catch(ArgumentException)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                MessageBox.Show(
"
There was an error.Check the path to the image file.
");


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张            }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
//
滚动条

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private 
void trackBar1_Scroll(
object sender, System.EventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
int r,g,b;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
//
Bitmap memBmp = new Bitmap(pictureBox1.Image);
//
(pictureBox1.Width,pictureBox1.Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
            UnCodebase () ;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            Bitmap memBmp = bmpobj;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
//
Image userDrawAreaImage = Bitmap memBmp

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
            
int nChang = trackBar1.Value - nHuidu;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
for(
int x=
0; x<pictureBox1.Image.Width; x++)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
for(
int y=
0; y<pictureBox1.Image.Height; y++)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张                {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    Color pixelColor = memBmp.GetPixel(x, y);


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
//
byte i = 0x01;

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
                    
if(( (pixelColor.R + nChang) >=
0) && ((pixelColor.R + nChang) <= 
250)) r = pixelColor.R + nChang;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
else r = pixelColor.R;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
if(( (pixelColor.G + nChang) >=
0) && ((pixelColor.G + nChang) <= 
250)) g = pixelColor.G + nChang;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
else g = pixelColor.G;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
if(( (pixelColor.B + nChang) >=
0) && ((pixelColor.B + nChang) <= 
250)) b = pixelColor.B + nChang;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
else b = pixelColor.B; 


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
//
Color newColor = Color.FromArgb(r,g ,b);
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    

//
memBmp.SetPixel(x, y, newColor);

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
                    memBmp.SetPixel(x, y, Color.FromArgb(r, g, b));


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张                }  


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张            } 


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
//
bmpobj = memBmp; 
//
把图片传给全局变量
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
 GrayByPixels();
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
Graphics memGp = Graphics.FromImage(memBmp);

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
            pictureBox1.Image = memBmp;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            GrayByPixels();  
//
灰度处理

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
            valueBox.Text = nHuidu.ToString();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }    


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
//
pictureBox1 按下鼠标

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private 
void pictureBox1_MouseDown(
object sender, System.Windows.Forms.MouseEventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            m_ptStart = 
new Point(e.X, e.Y);


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            txtStartX.Text = m_ptStart.X.ToString();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            txtStartY.Text = m_ptStart.Y.ToString();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
//
if (!m_bMouseDown)
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
{

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                

//
m_ptEnd = new Point(e.X, e.Y);
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                

//
txtEndX.Text = m_ptEnd.X.ToString();
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                

//
txtEndY.Text = m_ptEnd.Y.ToString();
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
}

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
            m_bMouseDown = !m_bMouseDown;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
//
pictureBox1 移动鼠标

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private 
void pictureBox1_MouseMove(
object sender, System.Windows.Forms.MouseEventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
try 


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
if (!m_bMouseDown == 
true
return;  
//
判断是否按下 pictureBox1_MouseDown

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
                m_ptEnd = 
new Point(e.X, e.Y);


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
this.pictureBox1.Refresh();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
if ((e.Button & MouseButtons.Left) == MouseButtons.Left) 


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张                {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
//
m_ptEnd = new Point(e.X, e.Y);

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
                    MyCursor = 
new Cursor(
"
cross_m.cur
");


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    Cursor.Current = MyCursor;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
//
Rectangle rec = new Rectangle(Convert.ToInt32(txtStartX),Convert.ToInt32(txtStartY),Convert.ToInt32(txtEndX),Convert.ToInt32(txtEndY));
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    

//
pictureBox1.Image.Size
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    

//
Bitmap memBmp = bmpobj;
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    

//
pictureBox1.Image = System.Drawing.Image.FromFile(selection.SubItems[1].Text);

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张
                }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
//
显示"+"指针

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
                
else


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张                {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    inCursor = 
new Cursor(
"
pen_rm.cur
");


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    Cursor.Current = inCursor;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张                }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张            }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
catch


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
if (inCursor != 
null)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    inCursor.Dispose();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
if (MyCursor != 
null)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    MyCursor.Dispose();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张            }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
//
鼠标离开 pictureBox1

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private 
void pictureBox1_MouseLeave(
object sender, System.EventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
if (inCursor != 
null)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                inCursor.Dispose();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
if (MyCursor != 
null)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                MyCursor.Dispose();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
//
pictureBox1 释放鼠标

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private 
void pictureBox1_MouseUp(
object sender, System.Windows.Forms.MouseEventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
if (!m_bMouseDown == 
true
return


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            m_ptEnd = 
new Point(e.X, e.Y);


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            txtEndX.Text = m_ptEnd.X.ToString();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            txtEndY.Text = m_ptEnd.Y.ToString();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            m_bMouseDown = !m_bMouseDown;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
//

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
Bitmap memBmp = new Bitmap(pictureBox1.Image);
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
Graphics myGraphics = Graphics.FromImage(pictureBox1.Image);
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
Pen blackPen = new Pen(Color.Black, 3);
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
Rectangle rec = new Rectangle(Convert.ToInt32(txtStartX),Convert.ToInt32(txtStartY),Convert.ToInt32(txtEndX),Convert.ToInt32(txtEndY));
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
myGraphics.DrawRectangle(blackPen, rec);
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
pictureBox1.Image = Image.FromStream(myGraphics);
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
myGraphics.Dispose();

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张
        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
//
pictureBox1 点击图片

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private 
void pictureBox1_Click(
object sender, System.EventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
//
pictureBox1 绘制图片

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private 
void pictureBox1_Paint(
object sender, System.Windows.Forms.PaintEventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
if (m_ptStart.Equals(m_ptEnd)) 
return;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
//
if(pictureBox1.Image == null || CurX == 0) return;
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            

//
Pen blackPen = new Pen(Color.Black, 3);

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
            e.Graphics.DrawRectangle(System.Drawing.Pens.Yellow,m_ptStart.X,m_ptStart.Y,m_ptEnd.X - m_ptStart.X, m_ptEnd.Y - m_ptStart.Y);


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
//
this.pictureBox1.Refresh();

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张
        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
//
保存截取图片点

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
        
private 
void btn_SavePoint_Click(
object sender, System.EventArgs e)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        

/ xg 
//


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
public 
void UnCodebase () 
//
(Bitmap pic)

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张
        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
if(bmpobj == 
null)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张               
//
Bitmap memBmp = new Bitmap(pictureBox1.Image);
//
(pictureBox1.Width,pictureBox1.Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb);

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
               bmpobj = 
new Bitmap (pictureBox1.Image);
//
(pic);    
//
转换为Format32bppRgb

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张
            }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        
///
 
<summary>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        

///
 根据RGB,计算灰度值
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        

///
 
</summary>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        

///
 
<param name="posClr">
Color值
</param>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        

///
 
<returns>
灰度值,整型
</returns>


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
private 
int GetGrayNumColor(System.Drawing.Color posClr)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
return (posClr.R * 
19595 + posClr.G * 
38469 + posClr.B * 
7472)>> 
16;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        
///
 
<summary>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        

///
 灰度转换,逐点方式
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        

///
 
</summary>


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
public 
void GrayByPixels()  
//
灰度处理

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张
        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            
//
 xg 
//


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
int tmpValue = 
0


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            UnCodebase ();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            Bitmap memBmp = bmpobj;


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
for (
int i = 
0; i < bmpobj.Height; i++)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
for (
int j = 
0; j < bmpobj.Width; j++)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张                {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
//
int tmpValue = GetGrayNumColor(bmpobj.GetPixel(j, i));

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张
                    tmpValue += GetGrayNumColor(bmpobj.GetPixel(j, i));


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
//
bmpobj.SetPixel(j, i, Color.FromArgb(tmpValue, tmpValue, tmpValue));

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张
                }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张            }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            tmpValue = tmpValue/(bmpobj.Height * bmpobj.Width);


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            valueBox.Text = tmpValue.ToString();


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            nHuidu = tmpValue; 
//
全局灰度

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张
        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        
///
 
<summary>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        

///
 去图形边框
PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        

///
 
</summary>

PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        

///
 
<param name="borderWidth"></param>


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张        
public 
void ClearPicBorder(
int borderWidth)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张        {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张            
for (
int i = 
0; i < bmpobj.Height; i++)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张            {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                
for (
int j = 
0; j < bmpobj.Width; j++)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第17张                {



PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                    
if (i < borderWidth || j < borderWidth || j > bmpobj.Width - 
1 - borderWidth || i > bmpobj.Height - 
1 - borderWidth)


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张                        bmpobj.SetPixel(j, i, Color.FromArgb(
255
255
255));


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张                }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张            }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张        }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第18张


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第19张    }


PictureBox 读取图片及绘画[亲测有效]_https://bianchenghao6.com/blog__第307张}



本文转自钢钢博客园博客,原文链接:http://www.cnblogs.com/xugang/archive/2007/12/24/1012665.html,如需转载请自行联系原作者

上一篇

已是最后文章

下一篇

已是最新文章

发表回复