如题,我想在图片上隐藏一些代码,如果图片被操作了,就自动运行这些代码,请教达人能不能实现这样的功能
首先声明一下,我不是想隐藏病毒,现在学信息隐藏技术。在图片里隐藏了机密信息后,如果有这样一段代码实现自动计时(时间根据隐藏信息的容量来设置,以便合法提出时能够正常提出出这些信息),只要有人操作此图片,代码就运行开始计时,在指定的时间内就自动删除此图片,这样的话如果非法想提取隐藏的机密信息,那只能在指定的时间内必须完成,否则图片自动删除。在对不知道用何种隐藏算法或加密算法的攻击者来说,在设置的时间内是肯定不能破译的。这样的话我认为可以很好的防止攻击。而不用去考虑这样或那样的复杂的算法来隐藏信息了。
问题就是能不能实现这样的功能啊??????????????

解决方案 »

  1.   


    功能很强大,编写也很好,可以添加图片水印和文字水印两种添加出来的效果非常好,现在就把代码贴出来,供大家欣赏 
     要导入的空间: 
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;
     添加图片水印的方法: 
    /// <summary>
        /// 加图片水印
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="waterFilename">水印文件名</param>
        /// <param name="waterStatus">图片水印位置 0=不使用 1=左上 2=中上 3=右上 4=左中  9=右下</param>
        /// <param name="quality">附加图片质量,1是 0不是</param>
        /// <param name="waterTransparency">水印的透明度 1--10 10为不透明</param>
        public static void AddImageSignPic(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;
            }        ImageAttributes imageAttributes = new ImageAttributes();
            ColorMap colorMap = new ColorMap();        colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
            colorMap.NewColor = 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);
            //g.DrawImage(water, new System.Drawing.Rectangle(xpos, ypos, water.Width, water.Height), 0, 0, water.Width, water.Height, System.Drawing.GraphicsUnit.Pixel);        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);
            }        g.Dispose();
            img.Dispose();
            water.Dispose();
            imageAttributes.Dispose();
        }
     
     
      

  2.   

    [CODE=C3]
    下面这个是添加文字水印的方法 
     /// <summary>
        /// 增加图片文字水印
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="waterText">水印文字</param>
        /// <param name="waterStatus">图片水印位置</param>
        public static void AddImageSignText(Image img, string filename, string waterText, int waterStatus, int quality, string fontname, int fontsize)
        {
            //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(img);
            //    .FromFile(filename);
            Graphics g = Graphics.FromImage(img);
            Font drawFont = new Font(fontname, fontsize, FontStyle.Regular, GraphicsUnit.Pixel);
            SizeF crSize;
            crSize = g.MeasureString(waterText, drawFont);        float xpos = 0;
            float ypos = 0;        switch (waterStatus)
            {
                case 1:
                    xpos = (float)img.Width * (float).01;
                    ypos = (float)img.Height * (float).01;
                    break;
                case 2:
                    xpos = ((float)img.Width * (float).50) - (crSize.Width / 2);
                    ypos = (float)img.Height * (float).01;
                    break;
                case 3:
                    xpos = ((float)img.Width * (float).99) - crSize.Width;
                    ypos = (float)img.Height * (float).01;
                    break;
                case 4:
                    xpos = (float)img.Width * (float).01;
                    ypos = ((float)img.Height * (float).50) - (crSize.Height / 2);
                    break;
                case 5:
                    xpos = ((float)img.Width * (float).50) - (crSize.Width / 2);
                    ypos = ((float)img.Height * (float).50) - (crSize.Height / 2);
                    break;
                case 6:
                    xpos = ((float)img.Width * (float).99) - crSize.Width;
                    ypos = ((float)img.Height * (float).50) - (crSize.Height / 2);
                    break;
                case 7:
                    xpos = (float)img.Width * (float).01;
                    ypos = ((float)img.Height * (float).99) - crSize.Height;
                    break;
                case 8:
                    xpos = ((float)img.Width * (float).50) - (crSize.Width / 2);
                    ypos = ((float)img.Height * (float).99) - crSize.Height;
                    break;
                case 9:
                    xpos = ((float)img.Width * (float).99) - crSize.Width;
                    ypos = ((float)img.Height * (float).99) - crSize.Height;
                    break;
            }        //            System.Drawing.StringFormat StrFormat = new System.Drawing.StringFormat();
            //            StrFormat.Alignment = System.Drawing.StringAlignment.Center;
            //
            //            g.DrawString(waterText, drawFont, new System.Drawing.SolidBrush(System.Drawing.Color.White), xpos + 1, ypos + 1, StrFormat);
            //            g.DrawString(waterText, drawFont, new System.Drawing.SolidBrush(System.Drawing.Color.Black), xpos, ypos, StrFormat);
            g.DrawString(waterText, drawFont, new SolidBrush(Color.White), xpos + 1, ypos + 1);
            g.DrawString(waterText, drawFont, new SolidBrush(Color.Black), xpos, ypos);        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);
            }
            g.Dispose();
            //bmp.Dispose();
            img.Dispose();
        }
     这个是我测试用的代码 
     Image img = Image.FromStream(this.FileUpload1.PostedFile.InputStream);
            string filename = Server.MapPath("img/test1.jpg");
            string watername = Server.MapPath("img/11.jpg");
            WaterMark.AddImageSignPic(img, filename, watername, 1, 100, 6);[/CODE]
      

  3.   

    http://hi.baidu.com/blueyund/blog/item/0f21fc1f0323430d314e1575.html