C#对不可见的水印的图片或文字的的提取 对图片进行水印加密(图片或文字),加密后不可见,已经加密成功了,可是我要如何提取出来??求大侠指导 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <summary> /// 加图片水印 /// </summary> /// <param name="img">要加水印的原图(System.Drawing)</param> /// <param name="filename">文件名</param> /// <param name="waterFilename">水印文件名</param> /// <param name="waterStatus">图片水印位置1=左上 2=中上 3=右上 4=左中 5=中中 6=右中 7=左下 8=右中 9=右下</param> /// <param name="quality">加水印后的质量0~100,数字越大质量越高</param> /// <param name="waterTransparency">水印图片的透明度1~10,数字越小越透明,10为不透明</param> public static Image ImageWaterMarkPic(Image img, string filename, string waterFilename, int waterStatus, int quality, int waterTransparency) { Graphics g = Graphics.FromImage(img); //设置高质量插值法 //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; Image water = new Bitmap(waterFilename); //如果水印的图片比原图片大,则退出 //if (water.Height >= img.Height || water.Width >= img.Width) //{ // return img; //} ImageAttributes imageAttributes = new ImageAttributes(); ColorMap colorMap = new ColorMap(); colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0); ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap); //设置透明度 float transparency = 0.5F; if (waterTransparency >= 1 && waterTransparency <= 10) transparency = (waterTransparency / 10.0F); float[][] colorMatrixElements = { new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 0.0f, transparency, 0.0f}, new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); int xpos = 0; int ypos = 0; switch (waterStatus) { case 1: xpos = (int)(img.Width * (float).01); ypos = (int)(img.Height * (float).01); break; case 2: xpos = (int)((img.Width * (float).50) - (water.Width / 2)); ypos = (int)(img.Height * (float).01); break; case 3: xpos = (int)((img.Width * (float).99) - (water.Width)); ypos = (int)(img.Height * (float).01); break; case 4: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).50) - (water.Height / 2)); break; case 5: xpos = (int)((img.Width * (float).50) - (water.Width / 2)); ypos = (int)((img.Height * (float).50) - (water.Height / 2)); break; case 6: xpos = (int)((img.Width * (float).99) - (water.Width)); ypos = (int)((img.Height * (float).50) - (water.Height / 2)); break; case 7: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).99) - water.Height); break; case 8: xpos = (int)((img.Width * (float).50) - (water.Width / 2)); ypos = (int)((img.Height * (float).99) - water.Height); break; case 9: xpos = (int)((img.Width * (float).99) - (water.Width)); ypos = (int)((img.Height * (float).99) - water.Height); break; } g.DrawImage(water, new Rectangle(xpos, ypos, water.Width, water.Height), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel, imageAttributes); ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo ici = null; foreach (ImageCodecInfo codec in codecs) { if (codec.MimeType.IndexOf("jpeg") > -1) ici = codec; } EncoderParameters encoderParams = new EncoderParameters(); long[] qualityParam = new long[1]; if (quality < 0 || quality > 100) quality = 80; qualityParam[0] = quality; EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam); encoderParams.Param[0] = encoderParam; if (ici != null) img.Save(filename, ici, encoderParams); else img.Save(filename); return img; g.Dispose(); img.Dispose(); water.Dispose(); imageAttributes.Dispose(); }这个就是水印的代码,也不是我自己写的,网络上找的 你这哪是什么加密,完全就只是加了一个水印而已加了水印然后保存成jpeg的格式,然后呢?你保存出来的就是一个image啊你是说这个image 打不开?还是去除这个image中的水印? image 可以正常打开,我现在是要从image中提取出我水印的图片,这个我不会 给你个思路,不知道可行不可行呀。你查看某种类型的图片的构成,比如jpeg,查看它的格式定义中有没有预留字段。然后你把你的信息写到图片的预留字段中。 当然,前提是你要存的信息比较少,另外,这个图片是内部流转的。 其实有比较简单的隐写办法就是 $我的隐藏开始$ ---------我要隐藏的二进制数据----------$我的隐藏结束$ 把这串数据写到图片数据,最后一个字节的最后一位比如我要隐藏的数据为:0111000, 对应图片数据的8个字节 xxxxxxx0xxxxxxx1xxxxxxx1xxxxxxx1xxxxxxx0xxxxxxx0xxxxxxx0xxxxxxx0我需要做的事情就是挨个提取图片数据的字节最后1位,就能得到原来的数据(对图片最后1位数据处理,对人眼的分辨无碍)当然你还可以这样,把图片数据的R通道的最后一位全变成偶数,然后把要写入的地方最后一位改成奇数,解码时,只要是奇数都是你写的。 【求群】有没有C#群 介绍几个啊? 关于水晶报表字段求和问题 OWC 11如何载入Excel 还是打开文件的问题~有点难度~ [求助]在textbox中,当按下enter触发一个事件,应该怎么做? 我大在在在在 在 关于DataGrid的问题 ???? c#客户端用protobuf序列化的时间很长 C#中结构体定义跟C语言 一本教程自带的例子,为什么无法通过编译?? 一台主机,多个activex控件混淆调用问题 IsValueType 的BUG
/// <summary>
/// 加图片水印
/// </summary>
/// <param name="img">要加水印的原图(System.Drawing)</param>
/// <param name="filename">文件名</param>
/// <param name="waterFilename">水印文件名</param>
/// <param name="waterStatus">图片水印位置1=左上 2=中上 3=右上 4=左中 5=中中 6=右中 7=左下 8=右中 9=右下</param>
/// <param name="quality">加水印后的质量0~100,数字越大质量越高</param>
/// <param name="waterTransparency">水印图片的透明度1~10,数字越小越透明,10为不透明</param>
public static Image ImageWaterMarkPic(Image img, string filename, string waterFilename, int waterStatus, int quality, int waterTransparency)
{
Graphics g = Graphics.FromImage(img);
//设置高质量插值法
//g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
//g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
Image water = new Bitmap(waterFilename);
//如果水印的图片比原图片大,则退出
//if (water.Height >= img.Height || water.Width >= img.Width)
//{
// return img;
//} ImageAttributes imageAttributes = new ImageAttributes();
ColorMap colorMap = new ColorMap(); colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0);
colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap); //设置透明度
float transparency = 0.5F;
if (waterTransparency >= 1 && waterTransparency <= 10)
transparency = (waterTransparency / 10.0F);
float[][] colorMatrixElements = {
new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, transparency, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}
}; ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); int xpos = 0;
int ypos = 0; switch (waterStatus)
{
case 1:
xpos = (int)(img.Width * (float).01);
ypos = (int)(img.Height * (float).01);
break;
case 2:
xpos = (int)((img.Width * (float).50) - (water.Width / 2));
ypos = (int)(img.Height * (float).01);
break;
case 3:
xpos = (int)((img.Width * (float).99) - (water.Width));
ypos = (int)(img.Height * (float).01);
break;
case 4:
xpos = (int)(img.Width * (float).01);
ypos = (int)((img.Height * (float).50) - (water.Height / 2));
break;
case 5:
xpos = (int)((img.Width * (float).50) - (water.Width / 2));
ypos = (int)((img.Height * (float).50) - (water.Height / 2));
break;
case 6:
xpos = (int)((img.Width * (float).99) - (water.Width));
ypos = (int)((img.Height * (float).50) - (water.Height / 2));
break;
case 7:
xpos = (int)(img.Width * (float).01);
ypos = (int)((img.Height * (float).99) - water.Height);
break;
case 8:
xpos = (int)((img.Width * (float).50) - (water.Width / 2));
ypos = (int)((img.Height * (float).99) - water.Height);
break;
case 9:
xpos = (int)((img.Width * (float).99) - (water.Width));
ypos = (int)((img.Height * (float).99) - water.Height);
break;
} g.DrawImage(water, new Rectangle(xpos, ypos, water.Width, water.Height), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel, imageAttributes); ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici = null;
foreach (ImageCodecInfo codec in codecs)
{
if (codec.MimeType.IndexOf("jpeg") > -1)
ici = codec;
}
EncoderParameters encoderParams = new EncoderParameters();
long[] qualityParam = new long[1];
if (quality < 0 || quality > 100)
quality = 80; qualityParam[0] = quality; EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
encoderParams.Param[0] = encoderParam; if (ici != null)
img.Save(filename, ici, encoderParams);
else
img.Save(filename);
return img;
g.Dispose();
img.Dispose();
water.Dispose();
imageAttributes.Dispose();
}这个就是水印的代码,也不是我自己写的,网络上找的
加了水印然后保存成jpeg的格式,然后呢?你保存出来的就是一个image啊你是说这个image 打不开?还是去除这个image中的水印?
就是
$我的隐藏开始$ ---------我要隐藏的二进制数据----------$我的隐藏结束$ 把这串数据写到图片数据,最后一个字节的最后一位比如我要隐藏的数据为:0111000, 对应图片数据的8个字节 xxxxxxx0
xxxxxxx1
xxxxxxx1
xxxxxxx1
xxxxxxx0
xxxxxxx0
xxxxxxx0
xxxxxxx0我需要做的事情就是挨个提取图片数据的字节最后1位,就能得到原来的数据(对图片最后1位数据处理,对人眼的分辨无碍)当然你还可以这样,把图片数据的R通道的最后一位全变成偶数,然后把要写入的地方最后一位改成奇数,解码时,只要是奇数都是你写的。