主要实现图片颜色变换功能,流程如下:
1、系统管理员可由后台上传图片,图片均为300dpi的jpeg纯色图,每张图最多存在三种颜色,如下图示:(此图黄色为R:230,G:147,B17,蓝色为:R:0,G:102,B:102)
2、会员可输入需要的RGB值,来替换图片中的颜色,最后,生成一张按图片输入颜色的新图片,如,会员输入:(R:247,G:0,B:0,R:0,G:128,B:0),则生成一张,红,绿五角星的图。图形与原图不变
1、系统管理员可由后台上传图片,图片均为300dpi的jpeg纯色图,每张图最多存在三种颜色,如下图示:(此图黄色为R:230,G:147,B17,蓝色为:R:0,G:102,B:102)
2、会员可输入需要的RGB值,来替换图片中的颜色,最后,生成一张按图片输入颜色的新图片,如,会员输入:(R:247,G:0,B:0,R:0,G:128,B:0),则生成一张,红,绿五角星的图。图形与原图不变
/**/
/// <summary>
/// 在图片上增加文字水印
/// </summary>
/// <param name="Path">原服务器图片路径</param>
/// <param name="Path_sy">生成的带文字水印的图片路径</param>
protected void AddWater(string Path, string Path_sy)
{
string addText = "51aspx.com";
System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
g.DrawImage(image, 0, 0, image.Width, image.Height);
System.Drawing.Font f = new System.Drawing.Font("Verdana", 60);
System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Green); g.DrawString(addText, f, b, 35, 35);
g.Dispose(); image.Save(Path_sy);
image.Dispose();
} /**/
/// <summary>
/// 在图片上生成图片水印
/// </summary>
/// <param name="Path">原服务器图片路径</param>
/// <param name="Path_syp">生成的带图片水印的图片路径</param>
/// <param name="Path_sypf">水印图片路径</param>
protected void AddWaterPic(string Path, string Path_syp, string Path_sypf)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Path_sypf);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
g.DrawImage(copyImage, new System.Drawing.Rectangle(image.Width - copyImage.Width, image.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, System.Drawing.GraphicsUnit.Pixel);
g.Dispose(); image.Save(Path_syp);
image.Dispose();
} protected void Button2_Click(object sender, EventArgs e)
{
//自动保存远程图片
WebClient client = new WebClient();
//备用Reg:<img.*?src=([\"\'])(http:\/\/.+\.(jpg|gif|bmp|bnp))\1.*?>
Regex reg = new Regex("IMG[^>]*?src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^\']*)')", RegexOptions.IgnoreCase);
MatchCollection m = reg.Matches(TextBox1.Text); foreach (Match math in m)
{
string imgUrl = math.Groups[1].Value; //在原图片名称前加YYMMDD重名名并上传 Regex regName = new Regex(@"\w+.(?:jpg|gif|bmp|png)", RegexOptions.IgnoreCase); string strNewImgName = DateTime.Now.ToShortDateString().Replace("-", "") + regName.Match(imgUrl).ToString(); try
{
//保存图片
client.DownloadFile(imgUrl, Server.MapPath("ImgUpload/Auto/" + strNewImgName)); }
catch
{
}
finally
{ } client.Dispose();
} Response.Write("<script>alert('远程图片保存成功,保存路径为ImgUpload/auto')</script>"); }参考……我这是加文字文印的……你要改颜色原理差不多……PS:高分帖子回复真夸张……却没几个真正进来回答问题……唉……
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Data.SqlClient;using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] _Value = "R:247,G:0,B:0,R:0,G:128,B:0".Split(','); Color _Color1 = Color.FromArgb(Convert.ToInt32(_Value[0].Split(':')[1]), Convert.ToInt32(_Value[1].Split(':')[1]), Convert.ToInt32(_Value[2].Split(':')[1]));
Color _Color2 = Color.FromArgb(Convert.ToInt32(_Value[3].Split(':')[1]), Convert.ToInt32(_Value[4].Split(':')[1]), Convert.ToInt32(_Value[5].Split(':')[1])); Bitmap _Bimtap = new Bitmap(@"C:\1.bmp");
BitmapData _BitmapData = _Bimtap.LockBits(new Rectangle(0, 0, _Bimtap.Width, _Bimtap.Height), ImageLockMode.ReadWrite, _Bimtap.PixelFormat);
byte[] _DataBytes = new byte[_BitmapData.Stride * _BitmapData.Height];
Marshal.Copy(_BitmapData.Scan0, _DataBytes, 0, _DataBytes.Length);
int _ReadIndex = 0;
int _RedIndex = 0;
int _GreenIndex = 0;
int _BlueIndex = 0;
for (int i = 0; i != _BitmapData.Height; i++)
{
_ReadIndex = i * _BitmapData.Stride; for (int z = 0; z != _BitmapData.Width; z++)
{
switch (_Bimtap.PixelFormat)
{
case PixelFormat.Format32bppArgb:
_RedIndex = _ReadIndex + (z * 4) + 3;
_GreenIndex = _ReadIndex + (z * 4) + 2;
_BlueIndex = _ReadIndex + (z * 3) + 1;
break;
case PixelFormat.Format24bppRgb:
_RedIndex = _ReadIndex + (z * 3) + 2;
_GreenIndex = _ReadIndex + (z * 3) + 1;
_BlueIndex = _ReadIndex + (z * 3);
break;
} if ((_DataBytes[_RedIndex] >= 200 && _DataBytes[_RedIndex] <= 250) && (_DataBytes[_GreenIndex] >= 100 && _DataBytes[_GreenIndex] <= 170) && (_DataBytes[_BlueIndex] >= 10 && _DataBytes[_BlueIndex] <= 30))
{
_DataBytes[_RedIndex] = (byte)_Color1.R;
_DataBytes[_GreenIndex] = (byte)_Color1.G;
_DataBytes[_BlueIndex] = (byte)_Color1.B;
} if ((_DataBytes[_RedIndex] >= 0 && _DataBytes[_RedIndex] <= 20) && (_DataBytes[_GreenIndex] >= 90 && _DataBytes[_GreenIndex] <= 120) && (_DataBytes[_BlueIndex] >= 90 && _DataBytes[_BlueIndex] <= 120))
{
_DataBytes[_RedIndex] = (byte)_Color2.R;
_DataBytes[_GreenIndex] = (byte)_Color2.G;
_DataBytes[_BlueIndex] = (byte)_Color2.B;
} } } Marshal.Copy(_DataBytes, 0, _BitmapData.Scan0, _DataBytes.Length); _Bimtap.UnlockBits(_BitmapData);
Response.Clear();
System.IO.MemoryStream _Memory = new System.IO.MemoryStream();
_Bimtap.Save(_Memory, ImageFormat.Png);
Response.OutputStream.Write(_Memory.ToArray(), 0, (int)_Memory.Position); //输出图形
Response.End();
}
}
zgke
(Cloud)
能不能注释一下,看不太懂