现在主要是上传头像。。太大了要截取一部分
不会用C#里的drawing类。。自己不会写。
希望能提供代码。
不会用C#里的drawing类。。自己不会写。
希望能提供代码。
解决方案 »
- 在程序里面对数据库进行恢复,就要将进程杀掉,杀掉之后连接的话,连接的数据库没有任何进程,就不能进行任何操作了,可以在程序不关的前提下让数据库起来吗?
- 求办公协同系统项目文件
- 怎么判断Button已经触发了事件
- c#如何反射获得一个类的实例
- xml?????????
- 我想用C#编写一个查询系统,请高手指点!
- 如何在vs2005-c#中检测键盘的caps lock,num lock,insert lock键状态?
- 怎么实现datetimepicker没有输入时像textbox,需要输入时显示datetimepicker形式选择时间,离开以后以textbox形式显示时间
- AE 图例
- 大家觉得这本书值得买吗?《Window Forms高级编程》
- 关于网站广告图片轮换显示效果???
- C#面试 考数据结构吗 ?
简例:
Image.GetThumbnailImageAbort callback= new Image.GetThumbnailImageAbort(ThumbnailCallback);
Bitmap bmp= new Bitmap("1.jpg");
Image img= bmp.GetThumbnailImage( nWidth, nHeight, callback, IntPtr.Zero);
e.Graphics.DrawImage(img, nWidth, nHeight);
Bitmap bmp= new Bitmap("test.jpg");
Image img= bmp.GetThumbnailImage( 200, 200, null, IntPtr.Zero); 把图版压缩成长和高都是200的图片;
从数据库里显示压缩的图片
byte[] stillsData = (byte[])Dr0["Image"];
System.IO.Stream ms = new System.IO.MemoryStream(stillsData);
System.Drawing.Image photo = Image.FromStream(ms); //得到图片
this.pEVIPClientImage.Image = photo.GetThumbnailImage(200, 200, null, IntPtr.Zero);
ms.Close();
Bitmap newImage = new Bitmap(newWidth, newHeight, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(newImage);
g.DrawImage(oldImage, startx, starty, newWIdth, newHeigh);
newImage.Save
{ //SourcePhotoName
string m_OriginalFilename = postFile.FileName;
string m_strGoodFile = saveImg; //GetPhotoObject From SourceFile
System.Drawing.Image m_Image = System.Drawing.Image.FromStream(postFile.InputStream, true); System.Double NewWidth, NewHeight;
NewWidth = 160;
NewHeight = 120; //GetPhotoSize
System.Drawing.Size size = new System.Drawing.Size((int)NewWidth, (int)NewHeight);
//The New of Bimp Photo
System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width, size.Height);
// The New of Palette
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
// Set HightQuality Arithmetic For Graphics
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//ClearCanvas
g.Clear(System.Drawing.Color.White);
//在指定位置画图
g.DrawImage(m_Image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
new System.Drawing.Rectangle(0, 0, m_Image.Width, m_Image.Height),
System.Drawing.GraphicsUnit.Pixel); //SavePhoto Of HightFocus
bitmap.Save(m_strGoodFile, System.Drawing.Imaging.ImageFormat.Jpeg);
//DisposeRes
g.Dispose();
m_Image.Dispose();
bitmap.Dispose();
}这个不是很完整,生成160×120的,参数没用,楼主可以改一下按比例生成,很简单啊
在picturebox1截图后的图像就能显示在picturebox2上了
using System.Drawing;private int _x, _y;
Image _img = null;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
_img = pictureBox1.Image.Clone() as Image; _x = e.X;
_y = e.Y;
} private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
int sx = _x < e.X ? _x : e.X;
int sy = _y < e.Y ? _y : e.Y;
int w = Math.Abs(_x - e.X);
int h = Math.Abs(_y - e.Y);
Graphics g = Graphics.FromHwnd(pictureBox2.Handle);
g.Clear(pictureBox2.BackColor);
g.DrawImage(pictureBox1.Image, new Rectangle(0, 0, w, h), sx, sy, w, h, GraphicsUnit.Pixel); } private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Pen p = new Pen(Color.Blue,1);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
Graphics g = Graphics.FromHwnd(pictureBox1.Handle);
int sx = _x < e.X ? _x : e.X;
int sy = _y < e.Y ? _y : e.Y;
int w = Math.Abs(_x - e.X);
int h = Math.Abs(_y - e.Y);
pictureBox1.Image = _img;
g.DrawRectangle(p, sx, sy, w, h);
} }