zoukankan      html  css  js  c++  java
  • 绘制合成图(进行中...)

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    namespace DrawGraphic
    {
        
    public class DrawProduct 
        
    {
            
    /// <summary>
            
    /// construct(s) function
            
    /// </summary>

            public DrawProduct()
            

            }


            
    /// <summary>
            
    /// 绘制产品图
            
    /// </summary>
            
    /// <param name="product_type">合成底图地址</param>
            
    /// <param name="product_src">合成图片地址</param>
            
    /// <param name="txt_context">合成文字内容</param>
            
    /// <param name="txt_top">合成文字top坐标</param>
            
    /// <param name="txt_left">合成文字left坐标</param>
            
    /// <param name="prod_top">合成图片top坐标</param>
            
    /// <param name="prod_left">合成图片left坐标</param>
            
    /// <param name="prod_width">合成图片Width</param>
            
    /// <param name="prod_height">合成图片Height</param>
            
    /// <param name="txt_size">合成文字Font-Size</param>
            
    /// <param name="resulturl">保存路径</param>
            
    /// <param name="model">绘制何种产品,T-shirt(TS),cup(CUP),mouse-mat(MM),picture mosaic(PM)</param>
            
    /// <returns>返回,绘制成功产品图地址</returns>

            public static void drawProduct(string product_type, string product_src, string txt_context, int txt_top, int txt_left,
                
    int prod_top, int prod_left, int prod_width, int prod_height, int txt_size, string model, string resulturl)
            
    {
                
    //System.Web.HttpServerUtility
                
    //System.Web.HttpContext.Current.Server.MapPath();
                Image typeImage = null;     //底图
                Image srcImage = null;
                
    int W = 0;
     
                
    switch (model)
                
    {
                    
    case "TS":
                        
    {
                            
    if (product_src.Length > 0)
                            
    {
                                
    string a1 = System.Web.HttpContext.Current.Server.MapPath(product_src);
                                srcImage 
    = Image.FromFile(System.Web.HttpContext.Current.Server.MapPath(product_src));    //合成图
                                
    //指定高,宽按比例
                                W = srcImage.Width * 128 / srcImage.Height;
                            }

                            
    string a2 = System.Web.HttpContext.Current.Server.MapPath(product_type);
                            typeImage 
    = Image.FromFile(System.Web.HttpContext.Current.Server.MapPath(product_type));
                            Graphics g 
    = Graphics.FromImage(typeImage);
                            g.SmoothingMode 
    = SmoothingMode.AntiAlias;
                            
    //底图大小400x400, 合成图坐标起点128x160,合成图大小160x128; 高128
                            if (product_src.Length > 0)
                            
    {
                                g.DrawImage(srcImage, 
    128 + prod_left, 160 + prod_top, W, 128);
                            }

                            
    if (txt_context.Length > 0)
                            
    {
                                
    //Brushes; SolidBrush s = new SolidBrush(Color)
                                g.DrawString(txt_context, new Font("宋体", (float)txt_size, FontStyle.Regular), SystemBrushes.WindowText, new Point(128 + txt_left, 160 + txt_top));
                            }

                            typeImage.Save(resulturl, System.Drawing.Imaging.ImageFormat.Jpeg);
                            g.Dispose();
                            srcImage.Dispose();
                            typeImage.Dispose();
                            
    break;
                        }

                    
    case "CUP":
                        
    {
                            
    //图片切,绘制三个面

                            
    break;
                        }

                    
    case "MM":
                        
    {
                            
                            
    break;
                        }

                    
    case "PM":
                        
    {

                            
    break;
                        }

                    
    default :
                        
    {
                            
    break;
                        }

                }

            }

        }

    }

  • 相关阅读:
    C#Note13:如何在C#中调用python
    C# Note12:WPF只允许数字的限制性TextBox
    C# Note11:如何优雅地退出WPF应用程序
    C#读书笔记:线程,任务和同步
    Programming好文解读系列(—)——代码整洁之道
    java算法面试题:从类似如下的文本文件中读取出所有的姓名,并打印出重复的姓名和重复的次数,并按重复次数排序 ;读取docx 读取doc 使用poi 相关jar包提集提供下载
    java面试题:如果一串字符如"aaaabbc中国1512"要分别统计英文字符的数量,中文字符的数量,和数字字符的数量,假设字符中没有中文字符、英文字符、数字字符之外的其他特殊字符。
    java算法面试题:有一个字符串,其中包含中文字符、英文字符和数字字符,请统计和打印出各个字符的个数 按值的降序排序,如果值相同则按键值的字母顺序
    java算法面试题:编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串,但要保证汉字不被截取半个, 如“我ABC”,4,应该截取“我AB”,输入“我ABC汉DEF”,6,应该输出“我ABC”,而不是“我ABC+汉的半个”。
    Java算法面试题:编写一个程序,将e: eck目录下的所有.java文件复制到e:jpg目录下,并将原来文件的扩展名从.java改为.jpg
  • 原文地址:https://www.cnblogs.com/sjett/p/449302.html
Copyright © 2011-2022 走看看