• 利用GDI+分割图片,在图片上加字


    System.Drawing.Image img;
                System.Drawing.Graphics g;
                System.Drawing.Bitmap bmp;
            
                img
    =System.Drawing.Image.FromFile(filename);

                
    if(img.Width!=768 ||img.Height!=928)
                    
    return "";
                
    if(!BakFilePath.Equals("nobak"&& !File.Exists(this.BakFilePath+Path.GetFileName(filename))  )
                    File.Copy(filename,
    this.BakFilePath+Path.GetFileName(filename));
                bmp
    =new Bitmap(1536,304,System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                g
    =System.Drawing.Graphics.FromImage(bmp);            
                g.DrawImage(img,
    0,0,new Rectangle(0,608,768,304),GraphicsUnit.Pixel);//取第三张
                
                g.DrawImage(img,
    768,0,new Rectangle(0,304,768,304),GraphicsUnit.Pixel);//第一张
                
                
    /*************************加字*******************************/        
                SolidBrush drawBrush 
    = new SolidBrush(Color.Red); 
                Font drawFont 
    = new Font("Arial"4, FontStyle.Regular, GraphicsUnit.Millimeter); 
                
    float xPos = 550
                
    float yPos = 0
                
                
    decimal Speed,SpeedP;        
                Speed
    =decimal.Parse(PicConvert.LoadConfig("Speed"));
                SpeedP 
    =decimal.Parse(PicConvert.LoadConfig("SpeedP"));
                
    //g.DrawString("限速"+Speed+"公里/小时 超速百分比:"+SpeedP+"%", drawFont, drawBrush, xPos, yPos); 
                g.DrawString("限速:"+Speed+"公里 超速:"+SpeedP+" %", drawFont, drawBrush, xPos, yPos); 
    //            newbmp=new Bitmap(bmp,1536,592);
                /*************************加字*******************************/

    /*********************************************************************/
    //            ImageCodecInfo[]  codecs=ImageCodecInfo.GetImageEncoders();    
    //        
    //            ImageCodecInfo  ici=null;  
    //            foreach(ImageCodecInfo  codec  in  codecs)  
    //            {  
    //                if(codec.MimeType=="image/jpeg")  
    //                    ici=codec;  
    //            }  
    //            
    //            EncoderParameters  ep=new  EncoderParameters();  
    //            ep.Param[0]=new  EncoderParameter(Encoder.Quality,(long)25);  
    //            newbmp.Save(this.DesFilePath+@"\"+newfilename,ici,ep);    


                Bitmap myBitmap;
                ImageCodecInfo myImageCodecInfo;
                Encoder myEncoder;
                EncoderParameter myEncoderParameter;
                EncoderParameters myEncoderParameters;
                
    // Create a Bitmap object based on a BMP file.
                myBitmap = new Bitmap(bmp,1536,592);
                
    // Get an ImageCodecInfo object that represents the JPEG codec.
                myImageCodecInfo = GetEncoderInfo("image/jpeg");
                
    // Create an Encoder object based on the GUID
                
    // for the Quality parameter category.
                myEncoder = Encoder.Quality;
                
    // Create an EncoderParameters object.
                
    // An EncoderParameters object has an array of EncoderParameter
                
    // objects. In this case, there is only one
                
    // EncoderParameter object in the array.
                myEncoderParameters = new EncoderParameters(1);
                
    // Save the bitmap as a JPEG file with quality level 25.
                myEncoderParameter = new EncoderParameter(myEncoder, 40L);
                myEncoderParameters.Param[
    0= myEncoderParameter;
                myBitmap.Save(
    this.DesFilePath+@"\"+newfilename, myImageCodecInfo, myEncoderParameters);
    //            // Save the bitmap as a JPEG file with quality level 50.
    //            myEncoderParameter = new EncoderParameter(myEncoder, 50L);
    //            myEncoderParameters.Param[0] = myEncoderParameter;
    //            myBitmap.Save(this.DesFilePath+@"\"+"Shapes050"+newfilename, myImageCodecInfo, myEncoderParameters);
    //            // Save the bitmap as a JPEG file with quality level 75.
    //            myEncoderParameter = new EncoderParameter(myEncoder, 75L);
    //            myEncoderParameters.Param[0] = myEncoderParameter;
    //            myBitmap.Save(this.DesFilePath+@"\"+"Shapes075"+newfilename, myImageCodecInfo, myEncoderParameters);

                
    /*****************************************************/
                
    //newbmp.Save(this.DesFilePath+@"\"+newfilename,System.Drawing.Imaging.ImageFormat.Jpeg);    
                myBitmap.Dispose();
                bmp.Dispose();
                g.Dispose();
                img.Dispose();
                File.Delete(filename);
                
    return newfilename;
  • 相关阅读:
    读后感四
    读后感五
    公文流转系统
    统计文件中单词的频率,给出前N的单词
    读入一个文件输出每个字母的频率
    小工到专家
    从小工到专家读后感
    动手动脑 类与对象
    海芋
    棕竹
  • 原文地址:https://www.cnblogs.com/lidune/p/546747.html
Copyright © 2020-2023  润新知