标签:GetThumbnailImage img source int destion newWidth Graphics 图片大小 newHeight
private void button1_Click(object sender, EventArgs e)
{
Image img_source = Image.FromFile("c:/920.jpg");
int newWidth;
int newHeight;
//你自定义图的长宽如
newWidth=600;
newHeight = 400;
Bitmap img_destion = new Bitmap(newWidth, newHeight);
Graphics g = Graphics.FromImage(img_destion);
g.DrawImage(img_source, 0, 0, newWidth, newHeight);
img_destion.Save("c:/920new.jpg");
}
/// <summary>
/// 图片大小调整
/// </summary>
/// <param name="img_souce_file">图片源文件</param>
/// <param name="img_destion_file">图片目标文件</param>
/// <param name="destion_size">调整图片目标大小</param>
/// <param name="destion_size_iswidth">目标大小是宽度吗(true 调整目标大小为宽度 false调整目标大小为高度)</param>
void image_resize(string img_souce_file,string img_destion_file,int destion_size,bool destion_size_iswidth)
{
Image img_source = Image.FromFile(img_souce_file);
int newWidth;
int newHeight;
if (destion_size_iswidth)//按指定宽度进行调整
{
newWidth = destion_size;
newHeight =(int)((float)img_source.Height/((float) img_source.Width/(float)newWidth));
}
else//按指定高度度进行调整
{
newHeight = destion_size;
newWidth = (int)((float)img_source.Width / ((float)img_source.Height / (float)newHeight));
}
Bitmap img_destion = new Bitmap(newWidth, newHeight);
Graphics g = Graphics.FromImage(img_destion);
g.DrawImage(img_source, 0, 0, newWidth, newHeight);
img_destion.Save(img_destion_file);
}
private void button2_Click(object sender, EventArgs e)
{
image_resize("c:/920.jpg", "c:/920_new.jpg", Convert.ToInt16(textBox1.Text), checkBox1.Checked);
}
标签:GetThumbnailImage,img,source,int,destion,newWidth,Graphics,图片大小,newHeight 来源: https://blog.csdn.net/zybpub/article/details/119409119
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。