form透明度用Opacity指定 , 存取image有如下方法!
using System;
using System.IO;
using System.Drawing;
using System.Data.SqlClient;
using System.Windows.Forms;namespace myTest{
class rwimg : Form
{
private PictureBox pictureBox1 ;
public static void Main(string[] args)
{
Application.Run(new rwimg());
}
public rwimg()
{
try{
// 指定透明度
this.Opacity = 0.7;
// 连接SQL-Server Northwind数据库
SqlConnection conn = new SqlConnection("user id=sa;password=ip3;initial catalog=Northwind;data source=gr0-ip3home;");
conn.Open();
SqlCommand com = new SqlCommand("Select Photo from Employees where EmployeeID = 4", conn);
byte[] img = (byte[]) com.ExecuteScalar();
MemoryStream ms = new MemoryStream();
ms.Write(img,78,img.Length-78);
Bitmap bm = new Bitmap(ms);
bm.Save("1.gif",System.Drawing.Imaging.ImageFormat.Gif);
conn.Close();
this.Width = bm.Width+10;
this.Height = bm.Height+30; this.pictureBox1 = new PictureBox();
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(this.Width, this.Height);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
this.pictureBox1.Image = bm;
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.pictureBox1});
MessageBox.Show("Succeeded");
}catch(Exception ex){ MessageBox.Show(ex.Message ); }
}
}
}
using System;
using System.IO;
using System.Drawing;
using System.Data.SqlClient;
using System.Windows.Forms;namespace myTest{
class rwimg : Form
{
private PictureBox pictureBox1 ;
public static void Main(string[] args)
{
Application.Run(new rwimg());
}
public rwimg()
{
try{
// 指定透明度
this.Opacity = 0.7;
// 连接SQL-Server Northwind数据库
SqlConnection conn = new SqlConnection("user id=sa;password=ip3;initial catalog=Northwind;data source=gr0-ip3home;");
conn.Open();
SqlCommand com = new SqlCommand("Select Photo from Employees where EmployeeID = 4", conn);
byte[] img = (byte[]) com.ExecuteScalar();
MemoryStream ms = new MemoryStream();
ms.Write(img,78,img.Length-78);
Bitmap bm = new Bitmap(ms);
bm.Save("1.gif",System.Drawing.Imaging.ImageFormat.Gif);
conn.Close();
this.Width = bm.Width+10;
this.Height = bm.Height+30; this.pictureBox1 = new PictureBox();
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(this.Width, this.Height);
this.pictureBox1.TabIndex = 1;
this.pictureBox1.TabStop = false;
this.pictureBox1.Image = bm;
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.pictureBox1});
MessageBox.Show("Succeeded");
}catch(Exception ex){ MessageBox.Show(ex.Message ); }
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货