C产品在市场上有哪些独特优势?

更新于
2026-10-10 03:59:16
1阅读来源:SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计389个文字,预计阅读时间需要2分钟。

C产品在市场上有哪些独特优势?

java/** * 缩放图像 * 指定原图片和目标尺寸,返回缩放后的图像 */public Image ScaleImage(Image image, int dstWidth, int dstHeight) { // 实现图像缩放逻辑}


C产品在市场上有哪些独特优势?

/// <summary> /// 按指定宽高缩放图片 /// </summary> /// <param name="image">原图片</param> /// <param name="dstWidth">目标图片宽</param> /// <param name="dstHeight">目标图片高</param> /// <returns></returns> public Image ScaleImage(Image image, int dstWidth, int dstHeight) { Graphics g = null; try { //按比例缩放 float scaleRate = GetWidthAndHeight(image.Width, image.Height, dstWidth, dstHeight); int width = (int)(image.Width * scaleRate); int height = (int)(image.Height * scaleRate); Bitmap destBitmap = new Bitmap(width, height); g = Graphics.FromImage(destBitmap); g.Clear(Color.Transparent); //设置画布的描绘质量 g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); return destBitmap; } catch (Exception e) { Console.WriteLine(e.Message); throw; } finally { if (g != null) { g.Dispose(); } if (image != null) { image.Dispose(); } } } /// <summary> /// 获取图片缩放比例 /// </summary> /// <param name="oldWidth">原图片宽</param> /// <param name="oldHeigt">原图片高</param> /// <param name="newWidth">目标图片宽</param> /// <param name="newHeight">目标图片高</param> /// <returns></returns> public float GetWidthAndHeight(int oldWidth, int oldHeigt, int newWidth, int newHeight) { //按比例缩放 float scaleRate; if (oldWidth >= newWidth && oldHeigt >= newHeight) { int widthDis = oldWidth - newWidth; int heightDis = oldHeigt - newHeight; if (widthDis > heightDis) { scaleRate = newWidth * 1f / oldWidth; } else { scaleRate = newHeight * 1f / oldHeigt; } } else if (oldWidth >= newWidth) { scaleRate = newWidth * 1f / oldWidth; } else if (oldHeigt >= newHeight) { scaleRate = newHeight * 1f / oldHeigt; } else { int widthDis = newWidth - oldWidth; int heightDis = newHeight - oldHeigt; if (widthDis > heightDis) { scaleRate = newHeight * 1f / oldHeigt; } else { scaleRate = newWidth * 1f / oldWidth; } } return scaleRate; }

本文共计389个文字,预计阅读时间需要2分钟。

C产品在市场上有哪些独特优势?

java/** * 缩放图像 * 指定原图片和目标尺寸,返回缩放后的图像 */public Image ScaleImage(Image image, int dstWidth, int dstHeight) { // 实现图像缩放逻辑}


C产品在市场上有哪些独特优势?

/// <summary> /// 按指定宽高缩放图片 /// </summary> /// <param name="image">原图片</param> /// <param name="dstWidth">目标图片宽</param> /// <param name="dstHeight">目标图片高</param> /// <returns></returns> public Image ScaleImage(Image image, int dstWidth, int dstHeight) { Graphics g = null; try { //按比例缩放 float scaleRate = GetWidthAndHeight(image.Width, image.Height, dstWidth, dstHeight); int width = (int)(image.Width * scaleRate); int height = (int)(image.Height * scaleRate); Bitmap destBitmap = new Bitmap(width, height); g = Graphics.FromImage(destBitmap); g.Clear(Color.Transparent); //设置画布的描绘质量 g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); return destBitmap; } catch (Exception e) { Console.WriteLine(e.Message); throw; } finally { if (g != null) { g.Dispose(); } if (image != null) { image.Dispose(); } } } /// <summary> /// 获取图片缩放比例 /// </summary> /// <param name="oldWidth">原图片宽</param> /// <param name="oldHeigt">原图片高</param> /// <param name="newWidth">目标图片宽</param> /// <param name="newHeight">目标图片高</param> /// <returns></returns> public float GetWidthAndHeight(int oldWidth, int oldHeigt, int newWidth, int newHeight) { //按比例缩放 float scaleRate; if (oldWidth >= newWidth && oldHeigt >= newHeight) { int widthDis = oldWidth - newWidth; int heightDis = oldHeigt - newHeight; if (widthDis > heightDis) { scaleRate = newWidth * 1f / oldWidth; } else { scaleRate = newHeight * 1f / oldHeigt; } } else if (oldWidth >= newWidth) { scaleRate = newWidth * 1f / oldWidth; } else if (oldHeigt >= newHeight) { scaleRate = newHeight * 1f / oldHeigt; } else { int widthDis = newWidth - oldWidth; int heightDis = newHeight - oldHeigt; if (widthDis > heightDis) { scaleRate = newHeight * 1f / oldHeigt; } else { scaleRate = newWidth * 1f / oldWidth; } } return scaleRate; }