登录
首页 » C#源码 » C#在图片格式转换时设置JPEG压缩级别的实现源码

C#在图片格式转换时设置JPEG压缩级别的实现源码

于 2022-05-18 发布 文件大小:33.04 kB
0 243
下载积分: 2 下载次数: 1

代码说明:

C#在转换图像格式时设置JPEG压缩级别,运行程序在窗口上单击按钮后,会生成多个版本不同压缩级别的图片,图片大小字节都不一样,如下代码是实现本功能的核心代码:   Bitmap MyBitmap = new Bitmap(@"J001.jpg");   ImageCodecInfo MyDecoder = null;   ImageCodecInfo[] MyDecoders = ImageCodecInfo.GetImageDecoders();   foreach (ImageCodecInfo MyFormat in MyDecoders)   {    if (MyFormat.FormatID == ImageFormat.Jpeg.Guid)    {    MyDecoder = MyFormat;    }   }   System.Drawing.Imaging.Encoder MyEncoder =    System.Drawing.Imaging.Encoder.Quality;   EncoderParameters MyEncoderParameters = new EncoderParameters(1);   //以50中级压缩图像   EncoderParameter MyEncoderParameter = new EncoderParameter(MyEncoder, 50L);   MyEncoderParameters.Param[0] = MyEncoderParameter;   MyBitmap.Save("J50L.jpg", MyDecoder, MyEncoderParameters);   //以100高级压缩图像   MyEncoderParameter = new EncoderParameter(MyEncoder, 100L);   MyEncoderParameters.Param[0] = MyEncoderParameter;   MyBitmap.Save("J99L.jpg", MyDecoder, MyEncoderParameters);   //以0低级压缩图像   MyEncoderParameter = new Enc

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • Visual C#对 XML操作的演示示例集
    这是一个C#操作XML文件的示例集,可完成 如下功能演示:   枚举XML集合中的元素名称   枚举XML集合中的元素文本   判断XML元素在集合中是否存在   筛选XML中的子代元素集合   使用链接轴方法枚举XML元素   根据元素属性查找XML元素   根据元素名称查找XML元素   根据元素属性和名称查找XML元素   根据中间计算值查找XML元素   比如枚举XML集合中的元素文本:private void button2_Click(object sender, EventArgs e)   {//枚举XML集合中的元素文本    XElement MyXElements = new XElement("Root",    new XElement("贵州省", "贵阳市"),    new XElement("四川省", "成都市"));    IEnumerable MyXElement =    from MySelect in MyXElements.Elements()    select MySelect;    string MyInfo = "元素文本包括:";    foreach (XElement MyValue in MyXElement)    MyInfo += MyValue.Value + "、";    //显示:贵阳市、成都市    MessageBox.Show(MyInfo, "信息提示", MessageBoxButtons.OK);   }
    2022-03-14 22:11:51下载
    积分:1
  • C# 复制和删除数据表指定行数据
    C# 复制和删除数据表指定行数据,主要是完成了两项功能,删除目标数据表的选择行的整行数据,将源数据表的选择行数据复制到目标数据表,这两个功能的实现思路和代码演示如下:   private void Form1_Load(object sender, EventArgs e)   {    MySourceTable = new DataTable();    var MyConnectString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:Northwind.mdb";    var MySQL = "Select * From 客户";    var MyAdapter=new OleDbDataAdapter(MySQL,MyConnectString);    MyAdapter.Fill(MySourceTable);    this.DataGridView1.DataSource = MySourceTable;    MyTargetTable = MySourceTable.Clone();    this.DataGridView2.DataSource = MyTargetTable;   }   private void Button1_Click(object sender, EventArgs e)   {//将源数据表的选择行数据复制到目标数据表    var MyID= "客户ID=;    MyID = MyID + this.DataGridView1.CurrentRow.Cells[0].Value.ToString() +";    MyTargetTable.ImportRow(this.MySourceTable.Select(MyID)[0]);   }   private void Button2_Click(object sender, EventArgs e)   {//删除目标数据表的选择行的整行数据    var MyID = "客户ID=;    MyID = MyID +this.DataGridView2.CurrentRow.Cells[0].Value.ToString
    2022-04-17 22:21:45下载
    积分:1
  • C# 使用互斥量禁止程序运行两个实例
    C# 使用互斥量禁止程序运行两个实例,这个主要是根据开发的程序使用环境决定,有时候一个程序运行多个副本,会浪费系统资源造成不稳定,但有人说这样会让软件使用更方便,以下代码是不让程序运行多个实例副本,关键代码如下所示:   private void Form1_Load(object sender, EventArgs e)   {//使用互斥量禁止程序运行两个实例    bool bExist;    var MyMutex =new System.Threading.Mutex(true, "OnlyOneTime", out bExist);    if (bExist)    MyMutex.ReleaseMutex();    else    {    MessageBox.Show("程序已经运行!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);    this.Close();    }   }
    2022-03-24 02:20:34下载
    积分:1
  • C# 从RichTextBox 控件中提取文本内容
    C# 从RichTextBox 控件中提取文本内容,并设置RichTextBox 控件中的字体大小-附完整源代码,   private void button1_Click(object sender, RoutedEventArgs e)   {//从RichTextBox 控件中提取文本内容    TextRange MyText = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);    MessageBox.Show(MyText.Text, "RichTextBox控件中的文本内容",MessageBoxButton.OK);   }   private void button2_Click(object sender, RoutedEventArgs e)   {//设置RichTextBox 控件中的字体大小    TextRange MyText = new TextRange(this.richTextBox1.Document.ContentStart, this.richTextBox1.Document.ContentEnd);    MyText.ApplyPropertyValue(TextElement.FontSizeProperty, 36.00);    MyText.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);   
    2022-09-21 17:55:02下载
    积分:1
  • C# 根据用户输入的防伪生成随机数
    C# 根据用户输入的防伪码生成随机数,测试时请输入防伪码的长度和个数(以空格来分开),请键入任意字符以结束,这个过程适时显示生成个数:{0},运行时间:{1}ms。根据指定字符生成随机数,这个在平时应用广泛,希望这个源码在生成随机数方面会给你一定参考。
    2022-02-01 00:12:10下载
    积分:1
  • C#保存和显示XML图像文件
    C#保存和显示XML图像文件的源码,本程序实现的功能主要是打开一个图像,格式为JPeg, Gif, Bmp, etc等,然后可保存XML图像文件,还可显示显示XML图像文件,每一步操作都会以MessageBox.Show的方式弹出对话框提示。
    2023-06-27 15:40:04下载
    积分:1
  • C#在JPG图片上添加半透明文字水印
    C#在图片上添加文字,这个仿PhotoShop的功能,用C#可以轻松实现哦,对象为JPG图像,可在上面添加半透明的文字效果,不能可看作是一种图片添加水印的效果,文字是半透明处理了,可隐约看到文字下层的图像细节。   private void Form1_Load(object sender, EventArgs e)   {//在指定图像上添加半透明文字    string MyFileName = "Forest.jpg";    Image MyImage = Image.FromFile(MyFileName);    Graphics g = Graphics.FromImage(MyImage);    String MyText = "国家";    Font MyFont = new Font("宋体", 150);    SolidBrush MyBrush = new SolidBrush(Color.FromArgb(18, 255, 0, 255));    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.GammaCorrected;    g.DrawString(MyText, MyFont, MyBrush, 10, 10);    this.pictureBox1.Image = MyImage;   }
    2023-02-17 00:50:03下载
    积分:1
  • C# 清除IE地址栏中的历史网址(修改注册表)
    C# 清除IE地址栏中的历史网址,也就是历史记录,这些记录都是平时自己输入的,IE会自动保存,本程序会把保存的这些网址信息全部删除了,主要是删除注册表中对应键值下的URL子键:   RegistryKey rkBase = Registry.CurrentUser;//定位到CurrentUser注册表项   //打开指定的注册表项   RegistryKey rkChild = rkBase.OpenSubKey(@"SoftwareMicrosoftInternet ExplorerTypedURLs",true);   String[] strValueNames = rkChild.GetValueNames();//获取所有的历史网址   foreach (string strItem in strValueNames)//遍历获取到的历史网址   {    rkChild.DeleteValue(strItem);//删除遍历到的历史网址   }
    2022-11-06 13:05:04下载
    积分:1
  • C# 打印XPS文档 XPS文件打印
    C# 打印选择的XPS文档,打印XPS文件,相关代码如下:   private void button1_Click(object sender, RoutedEventArgs e)   {//打印选择的XPS文档    var MyDlg = new Microsoft.Win32.OpenFileDialog();    MyDlg.InitialDirectory = System.IO.Directory.GetCurrentDirectory();    MyDlg.Filter = "XPS文件(*.xps)|*.xps|所有文件(*.*)|*.*";    if (MyDlg.ShowDialog() == true)    {    string MyFileName = MyDlg.FileName;    var pDialog = new PrintDialog();    pDialog.PageRangeSelection = PageRangeSelection.AllPages;    pDialog.UserPageRangeEnabled = true;    if (pDialog.ShowDialog() == true)    {    var MyDocument = new System.Windows.Xps.Packaging.XpsDocument(MyFileName, System.IO.FileAccess.ReadWrite);    FixedDocumentSequence MyFixedDocumentSequence = MyDocument.GetFixedDocumentSequence();    pDialog.PrintDocument(MyFixedDocumentSequence.DocumentPaginator, "我的XPS打印文档");    }    }   }
    2022-03-23 09:37:24下载
    积分:1
  • 网狐_台球__亲测_特效碰撞棒棒滴_HGE框架
    网狐台球源码,亲测,支持6603,经典平台。 HGE框架,UI,碰撞效果特别好。 运营级代码。 走过路过千万不要错过。
    2022-11-23 09:40:03下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载