zoukankan      html  css  js  c++  java
  • C# GDI

    绘制实心矩形

    using (Graphics gp = Graphics.FromImage(bmBlank))
    {
    //...
       int y = (int)currentPoint.Y - 5;
       Rectangle rec = new Rectangle(87, y, 40, 30);//画一个白块,即起到擦拭的效果
       gp.FillRectangle(Brushes.White, rec);

     Brushes颜色参考

    绘图基本方法

    string backImage = GetMaterialPath(param, this.reportType) + "image_blank_1.png";
    using (Image im = Image.FromFile(backImage))
    {
        using (Bitmap bmBlank = new Bitmap(230, 60, Graphics.FromImage(im)))
        {
            using (Graphics gp = Graphics.FromImage(bmBlank))
            {
                gp.DrawImage(im, new Point(0, 0));
                int width = (int)GetWidth_1(teamScore);
                Rectangle rec = new Rectangle((int)baseX, (int)baseY, width, 29);
                gp.FillRectangle(Brushes.Gold, rec);
            }
            ImageOperation.SaveImage(bmBlank, saveImgFilePath, 100000);
        }
    }
    //自定义工具类ImageOperation
    public static void SaveImage(Bitmap myBitmap,string fileName, int quality)
    {
    
        System.Drawing.Imaging.EncoderParameters myEncoderParameters =
            new System.Drawing.Imaging.EncoderParameters(1);
    
        System.Drawing.Imaging.EncoderParameter myEncoderParameter =
            new System.Drawing.Imaging.EncoderParameter(
            System.Drawing.Imaging.Encoder.Quality, quality);
    
        myEncoderParameters.Param[0] = myEncoderParameter;
    
        System.Drawing.Imaging.ImageCodecInfo myImageCodecInfo;
        myImageCodecInfo = GetEncoderInfo("image/jpeg");
    
    
        string ext = myImageCodecInfo.FilenameExtension.Split(';')[0];
        ext = System.IO.Path.GetExtension(ext).ToLower();
    
        string saveName = System.IO.Path.ChangeExtension(fileName, ext);
    
        //保存
        myBitmap.Save(saveName, myImageCodecInfo, myEncoderParameters);
    }
    using (FileStream fs = new FileStream(saveImgFilePath, FileMode.Create))
    {
        ImageCodecInfo imageCodeInfo = ImageOperation.GetEncoderInfo("image/jpeg");
        System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
        EncoderParameters myEncoderParameters = new EncoderParameters(1);
        myEncoderParameters.Param[0] = new EncoderParameter(myEncoder, 99L);
        bmBlank.Save(fs, imageCodeInfo, myEncoderParameters);
    }

    原生自定义背景色

    Bitmap bmBlank = new Bitmap(width, height);
    using (Graphics gp = Graphics.FromImage(bmBlank))
    {
        //清空画布并以白色背景色填充 
        gp.Clear(Color.White);
        for (int i = 0; i < imagePaths.Length; i++)
        {
             //加载一个图片
            string imagePath = imagePaths[i];
            //封装成Bitmap
            Bitmap bm = new Bitmap(Image.FromFile(imagePath));
            //切割此Bitmap为了等比例缩放
            Bitmap newbm = ImageOperation.Cut(bm, 200, 0, 800, 800);
            //查找所绘制每张图的新坐标
            int x = xValue[i];
            int y = yValue[i];
            gp.DrawImage(newbm, x, y, 400, 400);
            bm.Dispose();
        }
        gp.Dispose();
        //保存为图片...  
    }    
  • 相关阅读:
    Windows Phone 7 日期选择控件DatePicker和时间选择控件TimePicker
    Windows Phone 7 开发小技巧
    Windows Phone 7 MVVM模式的学习笔记
    Windows Phone 7 网络编程之留言板应用
    C# 中的INotifyPropertyChanged和ObservableCollection<T>
    《深入浅出:Windows Phone 7应用开发》
    Windows Phone 7 MVVM模式通讯方式之实现Command
    Windows Phone 7 chart图表编程
    Windows Phone 7 网络编程之调用web service
    Perst嵌入式数据库介绍
  • 原文地址:https://www.cnblogs.com/zhuji/p/6296458.html
Copyright © 2011-2022 走看看