怎么样注册一个网站,wordpress全站使用cdn,广告流量投放,企业网站搜索引擎推广方法包括1、对图片进行压缩#xff0c;保存在本地
对于一个200k的png文件按0.6的缩放比例进行压缩#xff0c;压缩后的大小为20k左右
对于一个80k的jpg文件按0.6的缩放比例压缩#xff0c;压缩后为13k左右
public void imageZoom(string name, Double zoomScale){Bitmap btImage …1、对图片进行压缩保存在本地
对于一个200k的png文件按0.6的缩放比例进行压缩压缩后的大小为20k左右
对于一个80k的jpg文件按0.6的缩放比例压缩压缩后为13k左右
public void imageZoom(string name, Double zoomScale){Bitmap btImage new Bitmap(name);Image serverImage btImage;int width (int)(serverImage.Width * zoomScale);int height (int)(serverImage.Height * zoomScale);//画板大小int finalWidth width, finalHeight height;int srcImageWidth serverImage.Width;int srcImageHeight serverImage.Height;if (srcImageWidth srcImageHeight){finalHeight srcImageHeight * width / srcImageWidth;}else{finalWidth srcImageWidth * height / srcImageHeight;}//新建一个bmp图片Image newImage new Bitmap(width, height);//新建一个画板Graphics g Graphics.FromImage(newImage);//设置高质量插值法g.InterpolationMode InterpolationMode.High;//设置高质量,低速度呈现平滑程度g.SmoothingMode SmoothingMode.HighQuality;//清空画布并以透明背景色填充g.Clear(Color.White);//在指定位置并且按指定大小绘制原图片的指定部分g.DrawImage(serverImage, new Rectangle((width - finalWidth) / 2, (height - finalHeight) / 2, finalWidth, finalHeight), 0, 0, srcImageWidth, srcImageHeight, GraphicsUnit.Pixel);//以jpg格式保存缩略图MemoryStream msSaveImage new MemoryStream();newImage.Save(D:\1.png,ImageFormat.Jpeg);serverImage.Dispose();newImage.Dispose();g.Dispose();} private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd new OpenFileDialog();ofd.ShowDialog();imageZoom(ofd.FileName,0.6);}
2、对图片进行压缩转换成Base64后进行传输可测量字符串长度来对比
对一张图片转换成base64后测量base64字符串的长度对于一个80k的图片压缩前长度为110800多压缩后长度不到20000减小了很多便于传输。
网上有关于对字符串进行压缩的那是针对纯字符串对于已经转换成base64的字符串使用GZipStream类来压缩数据基本上没有效果。
public string ImageToBase64(string name,Double zoomScale){Bitmap btImage new Bitmap(name);Image serverImage btImage;int width (int)(serverImage.Width * zoomScale);int height (int)(serverImage.Height * zoomScale);//画板大小int finalWidth width, finalHeight height;int srcImageWidth serverImage.Width;int srcImageHeight serverImage.Height;if (srcImageWidth srcImageHeight){finalHeight srcImageHeight * width / srcImageWidth;}else{finalWidth srcImageWidth * height / srcImageHeight;}//新建一个bmp图片Image newImage new Bitmap(width, height);//新建一个画板Graphics g Graphics.FromImage(newImage);//设置高质量插值法g.InterpolationMode InterpolationMode.High;//设置高质量,低速度呈现平滑程度g.SmoothingMode SmoothingMode.HighQuality;//清空画布并以透明背景色填充g.Clear(Color.White);//在指定位置并且按指定大小绘制原图片的指定部分g.DrawImage(serverImage, new Rectangle((width - finalWidth) / 2, (height - finalHeight) / 2, finalWidth, finalHeight), 0, 0, srcImageWidth, srcImageHeight, GraphicsUnit.Pixel);//以jpg格式保存缩略图MemoryStream msSaveImage new MemoryStream();newImage.Save(msSaveImage, ImageFormat.Jpeg);serverImage.Dispose();newImage.Dispose();g.Dispose();byte[] imageBytes msSaveImage.ToArray();msSaveImage.Close();return Convert.ToBase64String(imageBytes);}