我是这么用了,没有实现我所需的放大功能啊。我用的是一个按钮来实现的,具体如下:
private void picBox_Click(object sender, EventArgs e)//该按钮要实现放大功能
{
Image imgPhotoVert = Image.FromFile(@"F:\风景图片\image1.jpg");//我的图片在F盘
Image imgPhoto = null;
imgPhoto = ScaleByPercent(imgPhotoVert, 50);
imgPhoto.Save(@"F:\风景图片\image11.jpg", ImageFormat.Jpeg);//保存的F盘下
imgPhoto.Dispose();
}
static Image ScaleByPercent(Image imgPhoto, int Percent)
{
float nPercent = ((float)Percent / 100); int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0; int destX = 0;
int destY = 0;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent); Bitmap bmPhoto = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic; grPhoto.DrawImage(imgPhoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel); grPhoto.Dispose();
return bmPhoto;
}
请高手指教,谢谢我想要的效果是类似ACDsee那样的简单的图片放大功能,把图片直接单击就可以放大,而不是放到另一个图片保存时才能看到放大。至于图像的失真处理,如果高手们有办法解决,小生将不胜感激!
private void picBox_Click(object sender, EventArgs e)//该按钮要实现放大功能
{
Image imgPhotoVert = Image.FromFile(@"F:\风景图片\image1.jpg");//我的图片在F盘
Image imgPhoto = null;
imgPhoto = ScaleByPercent(imgPhotoVert, 50);
imgPhoto.Save(@"F:\风景图片\image11.jpg", ImageFormat.Jpeg);//保存的F盘下
imgPhoto.Dispose();
}
static Image ScaleByPercent(Image imgPhoto, int Percent)
{
float nPercent = ((float)Percent / 100); int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0;
int sourceY = 0; int destX = 0;
int destY = 0;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent); Bitmap bmPhoto = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic; grPhoto.DrawImage(imgPhoto,
new Rectangle(destX, destY, destWidth, destHeight),
new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
GraphicsUnit.Pixel); grPhoto.Dispose();
return bmPhoto;
}
请高手指教,谢谢我想要的效果是类似ACDsee那样的简单的图片放大功能,把图片直接单击就可以放大,而不是放到另一个图片保存时才能看到放大。至于图像的失真处理,如果高手们有办法解决,小生将不胜感激!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货