You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.5 KiB

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GummingCommon
{
public class GDIService
{
public static bool IsPicture(string fileName)
{
string strFilter = ".jpeg|.gif|.jpg|.png|.bmp|.pic|.tiff|.ico|.iff|.lbm|.mag|.mac|.mpt|.opt|";
char[] separtor = { '|' };
string[] tempFileds = strFilter.Trim().Split(separtor);
foreach (string str in tempFileds)
{
if (str.ToUpper() == fileName.Substring(fileName.LastIndexOf("."), fileName.Length - fileName.LastIndexOf(".")).ToUpper())
{
return true;
}
}
return false;
}
public static string GetImageType(string contentType)
{
switch (contentType)
{
case "image/jpeg":
return "jpg";
}
return "jpg";
}
private static void SetGraphics(Graphics g, Color c)
{
g.CompositingMode = CompositingMode.SourceCopy;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.Clear(c);
///////////////////////////////////////////////////////////////////////////
}
public static void SetGraphics(Graphics g)
{
SetGraphics(g, Color.FromArgb(235, 235, 235));
}
public static MemoryStream DrawString(int left, int top, string content, Font font)
{
Bitmap bitmap = new Bitmap(100, 20);
Graphics g = Graphics.FromImage(bitmap);
g.Clear(Color.FromArgb(235, 235, 235));
//Font font = new Font("Airal", 9);
g.DrawString(content, font, Brushes.Black, new Point(left, top));
EncoderParameters encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 100);
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, ImageCodecInfo.GetImageEncoders()[1], encoderParameters);
return ms;
}
}
}