Exemple #1
0
 static void GetPicUrlsFromBeautyPersonalPage(ImageTag imgNode, int fileIndex, int type)
 {
     if (imgNode.Attributes.ContainsKey("SRC") || imgNode.Attributes.ContainsKey("DATA-CFSRC"))
     {
         string imgUrl = imgNode.Attributes.ContainsKey("SRC") ? imgNode.GetAttribute("SRC") : imgNode.GetAttribute("DATA-CFSRC");
         //2014年5月16日根据网页结构修改
         //if (imgUrl.Contains("/250x0/"))
         //{
         //    imgUrl = imgUrl.Substring(imgUrl.IndexOf("/250x0/") + 7);
         //    imgUrl = "http://" + imgUrl;
         //}
         //int startIndex = imgUrl.IndexOf("/media.curator.im/images/");
         //imgUrl = "http:/" + imgUrl.Substring(startIndex);
         if (!imgFileNameSet.Contains(imgUrl))
         {
             string imgName = "";
             if (imgNode.Attributes.ContainsKey("ALT"))
             {
                 imgName = imgNode.GetAttribute("ALT");
                 if (type == 2)//type为2是爬取“正妹流”中的妹子的网页的情况
                 {
                     imgName = imgName.Substring(4);
                 }
             }
             else
             {
                 Console.WriteLine("第" + fileIndex + "张图片无法获取alt属性!");
                 return;
             }
             imgFileNameSet.Add(imgUrl);
             //因为要把美女的名字作为文件夹名,所以要排除所有不能用于文件夹的字符
             int invalideCharIndex = imgName.IndexOfAny(Path.GetInvalidPathChars());
             while (invalideCharIndex != -1)
             {
                 imgName           = imgName.Remove(invalideCharIndex, 1);
                 invalideCharIndex = imgName.IndexOfAny(Path.GetInvalidPathChars());
             }
             //因为要把美女的名字作为文件名,所以要排除所有不能用于文件名的字符
             invalideCharIndex = imgName.IndexOfAny(Path.GetInvalidFileNameChars());
             while (invalideCharIndex != -1)
             {
                 imgName           = imgName.Remove(invalideCharIndex, 1);
                 invalideCharIndex = imgName.IndexOfAny(Path.GetInvalidFileNameChars());
             }
             string completeImgName = type == 1 ? saveOneDayOneBeautyBasePath + imgName : saveBeautyFlowBasePath + imgName;//和上面类似,用type来区别图片保存路径
             if (!Directory.Exists(completeImgName))
             {
                 Directory.CreateDirectory(completeImgName);
             }
             currentImgFileNameSet.Add(imgUrl, completeImgName + "\\" + imgName + " (" + fileIndex + ").jpg");
             thunderAgent.AddTask2(imgUrl, imgName + " (" + fileIndex + ").jpg", "D:\\Download\\" + completeImgName + "\\", "", "", 1, 0, 1);
             fileIndex++;
         }
     }
     else
     {
         Console.WriteLine("无法获取第" + fileIndex + "张图片!");
         return;
     }
 }
Exemple #2
0
        public static HashSet <ImageTag> GetImageTags(string imagePath)
        {
            var result = new HashSet <ImageTag>(new ImageTagEqualityComparer());

            //Debug.WriteLine("tags at: " + imagePath);
            if (File.Exists(imagePath))
            {
                try
                {
                    var sFile    = ShellFile.FromParsingName(imagePath);
                    var tagsList = sFile.Properties.System.Keywords.Value;
                    if (tagsList != null)
                    {
                        foreach (var tagText in tagsList)
                        {
                            var newTag = new ImageTag(tagText);
                            if (!result.Contains(newTag))
                            {
                                result.Add(newTag);
                            }
                        }
                    }
                }
                catch (Exception e) { throw e; }
            }

            return(result);
        }
        public IEnumerable <ImageTag> GetTagsBySearch(string tag)
        {
            List <ImageTag> foundTags = new List <ImageTag>();

            using (SqlCommand query = new SqlCommand("SELECT * FROM Tags WHERE (Description LIKE '%' + @Tag + '%')", connection))
            {
                connection.Open();
                query.Parameters.AddWithValue("@Tag", tag);
                try
                {
                    using (SqlDataReader reader = query.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var foundtag = new ImageTag
                            {
                                Id          = Convert.ToInt32(reader["Id"]),
                                Description = reader["Created"].ToString(),
                            };

                            foundTags.Add(foundtag);
                        }
                        reader.Close();
                    }
                }
                catch
                {
                    return(null);
                }
                connection.Close();
                return(foundTags);
            }
        }
        /// <summary>
        /// 对图片做opencv的人脸分析
        /// </summary>
        /// <param name="imgTag"></param>
        public static void OpenCVAnalysis(ImageTag imgTag)
        {
            var imageFile = imgTag.GetTrueImageFile();
            var image     = Cv2.ImRead(imageFile);

            var tps = new List <TagPart>();

            foreach (var face in FaceDetect.OpenCvDetectMultiScale(image))
            {
                var body = AITag.Common.Utils.GetBodyRect(face, (double)(64 - 8) / 128, image.Width, image.Height);

                if (body != Rect.Empty)
                {
                    tps.Add(new TagPart
                    {
                        Face = face,
                        Body = body
                    });
                }
            }

            if (tps.Count == 0)
            {
                imgTag.Status = "opencv_fail";
            }
            else
            {
                imgTag.OpenCvParts = tps;
                imgTag.Status      = "opencv_finish";
            }
        }
        /// <summary>
        /// 根据一个AV,创建一个可以用来图片下载策略
        /// </summary>
        /// <param name="av"></param>
        /// <returns></returns>
        public static Request CreateRequest(AV av)
        {
            var img = new ImageTag()
            {
                ImageUrl      = av.pic,
                AvId          = av.Id,
                UpId          = av.UpId,
                LocalFileName = GetLocalFile(av.pic)
            };

            var trueFile = Path.Combine(DefaultImagePath, img.LocalFileName);

            if (File.Exists(trueFile))
            {
                // 本地下载过文件,就不考虑再下载图片数据了
                return(null);
            }

            var ret = new Request
            {
                RequestUri = new Uri(img.ImageUrl),
            };

            ret.Properties["requestType"]         = "image";
            ret.Properties[typeof(ImageTag).Name] = img;

            return(ret);
        }
Exemple #6
0
        /// <summary>
        ///    Reads the file with a specified read style.
        /// </summary>
        /// <param name="propertiesStyle">
        ///    A <see cref="ReadStyle" /> value specifying at what level
        ///    of accuracy to read the media properties, or <see
        ///    cref="ReadStyle.None" /> to ignore the properties.
        /// </param>
        protected void Read(ReadStyle propertiesStyle)
        {
            Mode = AccessMode.Read;
            try
            {
                uint first_ifd_offset = ReadHeader();
                ReadIFD(first_ifd_offset);

                // Find XMP data
                var xmp_entry = ImageTag.Exif.Structure.GetEntry(0, (ushort)IFDEntryTag.XMP) as ByteVectorIFDEntry;
                if (xmp_entry != null)
                {
                    ImageTag.AddTag(new XmpTag(xmp_entry.Data.ToString(), this));
                }

                if (propertiesStyle == ReadStyle.None)
                {
                    return;
                }

                properties = ExtractProperties();
            }
            finally
            {
                Mode = AccessMode.Closed;
            }
        }
Exemple #7
0
        /// <summary>
        /// 把内容中的图片,相对地址变为绝对地址。
        /// </summary>
        /// <param name="tmp_content"></param>
        /// <param name="url"></param>
        public static void ImageSrc(ref string tmp_content, string url)
        {
            //如果遇到使用绝对路径的图片,转换为全路径。
            NodeList htmlNodes = new Parser(new Lexer(tmp_content.Replace("<IMG", "<img").Replace("<Img", "<img"))).Parse(new TagNameFilter("img"));

            for (int j = htmlNodes.Count - 1; j >= 0; j--)
            {
                ImageTag link = (ImageTag)htmlNodes.ElementAt(j);

                string urlpart = link.GetAttribute("src");

                if (!string.IsNullOrEmpty(urlpart) && !new Regex(@"^http:").IsMatch(urlpart))
                {
                    urlpart = new xkHttp().getDealUrl(url, urlpart);
                    string oldlink = link.ToHtml();

                    link.RemoveAttribute("src");
                    link.RemoveAttribute("onclick");
                    string newsrc  = "src=\"" + urlpart + "\" ";
                    string newlink = link.ToHtml();
                    newlink     = newlink.Insert(5, newsrc);
                    tmp_content = tmp_content.Replace(oldlink, newlink);
                    //EchoHelper.Echo("成功转换了一个图片的SRC属性!", "", EchoHelper.EchoType.普通信息);
                }
                if (!string.IsNullOrEmpty(urlpart) && new Regex(@"^\.\.").IsMatch(urlpart))
                {
                    string oldlink = link.ToHtml();
                    tmp_content = tmp_content.Replace(oldlink, "");
                }
            }
        }
Exemple #8
0
    //创建图片标签
    protected ImageTag CreateImageTag(XmlNode nodeTag)
    {
        ImageTag tag = new ImageTag();

        tag.URL = nodeTag.Attributes["URL"].Value;
        return(tag);
    }
        public async Task<IActionResult> AddImageTag(ImageTag imageTag)
        {
            var project = _context.ImageModel.Include(i => i.Project).FirstOrDefault(i => i.ID == imageTag.ImageId)?.Project;

            if (project == null || project.OwnerId != GetUserID())
            {
                return NotFound();
            }

            if (ModelState.IsValid)
            {
                var imageTags = _context.ImageTags.Where(i => i.ImageId == imageTag.ImageId).ToList();
                var imageTagSameRegion = imageTags.FirstOrDefault(i => i.RelativeCoords.Equals(imageTag.RelativeCoords));
                if (imageTagSameRegion == null)
                    _context.Add(imageTag);
                else
                    imageTagSameRegion.TagId = imageTag.TagId;

                await _context.SaveChangesAsync();
            }

            imageTag.Image = null;

            return Json(imageTag);
        }
Exemple #10
0
        public Task CreateImageTagsAsync(int imageId, int tagId)
        {
            //List<ImageTag> imageTags = new List<ImageTag>();
            //foreach(var item in tags)
            //{
            //    ImageTag imageTag = new ImageTag{ ImageId = imageId, TagId = item.Id };
            //    imageTags.Add(imageTag);
            //}

            //var image = _flowerAppContext.Images.FirstOrDefault(i => i.Id == imageId);
            //image.ImageTags = imageTags;

            var image = GetImageById(imageId);

            if (!image.ImageTags.Any <ImageTag>(x => x.TagId == tagId))
            {
                ImageTag imageTag = new ImageTag
                {
                    ImageId = imageId,
                    TagId   = tagId,
                };

                image.ImageTags.Add(imageTag);

                _flowerAppContext.Images.Update(image);
            }

            return(_flowerAppContext.SaveChangesAsync());
        }
        public ActionResult Index(UploadModel model, HttpPostedFileBase file)
        {
            var man  = new ImageManager();
            var md   = new ImageMetaData();
            var tags = new List <ImageTag>();

            if (file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                md.FileName    = fileName;
                md.ContentType = file.ContentType;
                md.Description = model.Description;
                foreach (var tag in model.Tags)
                {
                    ImageTag t = new ImageTag();

                    t.TagName = tag;
                    tags.Add(t);
                }

                man.SaveImage(md, tags, file.InputStream);
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemple #12
0
        /// <summary>
        /// Save the properties of this in tagMain in a suitable form for writing to a file which we can read and LoadProperties from
        /// to recover the current state of this object.
        /// tagMain may be a CombinedImageTag (when working with a real image file) or an XmpTag (when working with an XMP file).
        /// Most of the data is stored simply in the XmpTag (which is the Xmp property of the combined tag, if it is not tagMain itself).
        /// But, we don't want to pass combinedTag.Xmp when working with a file, because setting CopyRightNotice and Creator directly
        /// on the combinedTag may save it in additional places that may be useful;
        /// and we need to handle the case where we only have an XmpTag, because there appears to be no way to create a
        /// combinedTag that just has an XmpTag inside it (or indeed any way to create any combinedTag except as part of
        /// reading a real file).
        /// </summary>
        void SaveInImageTag(ImageTag tagMain)
        {
            // Taglib doesn't care what namespace prefix is used for these namespaces (which it doesn't already know about).
            // It will happily assign them to be ns1 and ns2 and successfully read back the data.
            // However, exiftool and its clients, including older versions of this library, will only recognize the
            // cc data if the namespace has the 'standard' abbreviation.
            // I'm not sure whether the pdf one is necessary, but minimally it makes the xmp more readable and less unusual.
            // This is a bit of a kludge...I'm using a method that TagLib says is only meant for unit tests,
            // and modifying what is meant to be an internal data structure, bypassing the (internal) method normally used
            // to initialize it. But it gets the job done without requiring us to fork taglib.
            XmpTag.NamespacePrefixes["http://creativecommons.org/ns#"] = "cc";
            XmpTag.NamespacePrefixes["http://ns.adobe.com/pdf/1.3/"]   = "pdf";

            XmpTag xmp = tagMain as XmpTag;

            if (xmp == null)
            {
                xmp = ((CombinedImageTag)tagMain).Xmp;
            }
            SetCopyright(tagMain, CopyrightNotice);
            tagMain.Creator = Creator;
            AddOrModify(xmp, kNsCollections, "CollectionURI", CollectionUri);
            AddOrModify(xmp, kNsCollections, "CollectionName", CollectionName);
            AddOrModify(xmp, kNsCc, "attributionURL", AttributionUrl);
            if (License != null && !string.IsNullOrWhiteSpace(License.Url))
            {
                AddOrModify(xmp, kNsCc, "license", License.Url);
            }
            SetRights(xmp, License == null ? null : License.RightsStatement);
        }
Exemple #13
0
            private static async Task <ImageTag> DownloadImage(string source)
            {
                ImageTag imageTag;

                try
                {
                    var request = HttpWebRequest.CreateHttp(source);
                    request.Accept = "image/*";

                    var response = await request.GetResponseAsync();

                    using (var inStream = response.GetResponseStream())
                        using (var outStream = new MemoryStream())
                        {
                            var tempImage = Image.FromStream(inStream);
                            var thumbnail = tempImage.GetThumbnailImage(200, 200, new Image.GetThumbnailImageAbort(() => false), IntPtr.Zero);
                            thumbnail.Save(outStream, ImageFormat.Jpeg);

                            imageTag = new ImageTag
                            {
                                Height     = tempImage.Height,
                                Width      = tempImage.Width,
                                ImageBytes = outStream.ToArray()
                            };
                        }
                }
                catch
                {
                    imageTag = new ImageTag();
                }

                return(imageTag);
            }
Exemple #14
0
        /// <summary>
        ///    Reads a COM segment to find the JPEG comment.
        /// </summary>
        /// <param name="length">
        ///    The length of the segment that will be read.
        /// </param>
        private void ReadCOMSegment(int length)
        {
            if ((ImageTag.TagTypes & TagLib.TagTypes.JpegComment) != 0x00)
            {
                return;
            }

            long position = Tell;

            JpegCommentTag com_tag;

            if (length == 0)
            {
                com_tag = new JpegCommentTag();
            }
            else
            {
                ByteVector data = ReadBlock(length);

                int terminator = data.Find("\0", 0);

                if (terminator < 0)
                {
                    com_tag = new JpegCommentTag(data.ToString());
                }
                else
                {
                    com_tag = new JpegCommentTag(data.Mid(0, terminator).ToString());
                }
            }

            ImageTag.AddTag(com_tag);
            AddMetadataBlock(position - 4, length + 4);
        }
Exemple #15
0
    private static string getChildTag(INode node, string style)
    {
        string sResult = "";
        ITag   tag     = null;

        if (node.Children != null && node.Children.Count > 0)
        {
            for (int i = 0; i < node.Children.Count; i++)
            {
                if (node is ITag)
                {
                    tag = node as ITag;

                    if (tag.Attributes["STYLE"] != null && style.IndexOf(tag.Attributes["STYLE"].ToString()) < 0)//样式存在且没有添加到style
                    {
                        style += tag.Attributes["STYLE"];
                    }
                }
                sResult += getChildTag(node.Children[i], style);
            }
        }
        else
        {
            if (node is ITag)
            {
                tag = node as ITag;
                if (isNotNull(tag.ToPlainTextString()))//无内容,排除
                {
                    if (node is ATag)
                    {
                        sResult = "{\"tag\":\"text\",\"style\":\"" + style + tag.Attributes["STYLE"] + "\",\"isInLine\":true,\"value\":\"" + tag.ToPlainTextString() + "\"},";
                    }
                    else
                    {
                        sResult = "{\"tag\":\"text\",\"style\":\"" + style + tag.Attributes["STYLE"] + "\",\"isInLine\":false,\"value\":\"" + tag.ToPlainTextString() + "\"},";
                    }
                }
                if (node is ImageTag)//图片标签也是无内容,单独处理
                {
                    ImageTag imageTage = node as ImageTag;
                    sResult = "{\"tag\":\"image\",\"style\":\"" + style + "\",\"isInLine\":true,\"value\":\"" + imageTage.ImageURL + "\"},";
                }
                else if (node is TagNode)
                {
                    if (tag.RawTagName.Equals("br/"))
                    {
                        sResult = "{\"tag\":\"text\",\"style\":\"\",\"isInLine\":true,\"value\":\"\"},";//<br/>是换行
                    }
                }
            }
            else
            {
                if (isNotNull(node.ToPlainTextString()))//空文本标签,排除
                {
                    sResult = "{\"tag\":\"text\",\"style\":\"" + style + "\",\"isInLine\":false,\"value\":\"" + node.ToPlainTextString() + "\"},";
                }
            }
        }
        return(sResult);
    }
Exemple #16
0
 public Sprite(ImageTag inTag, SpriteEffects inEffect, Color inColor, SpriteName inName)
 {
     _image = ImageManager.getInstance().find(inTag);
     Effect = inEffect;
     color  = inColor;
     Name   = inName;
 }
Exemple #17
0
        /// <summary>
        ///    Reads a Comment Block at the current position. The current position must
        ///    point to the 3rd byte of the comment block. (The other 2 bytes are usually
        ///    read before to identify the comment block)
        /// </summary>
        private void ReadCommentBlock()
        {
            long position = Tell;

            // Comment Extension
            //
            // 1 Byte       Extension Introducer (0x21)
            // 1 Byte       Comment Label (0xFE)
            // N Bytes      Comment Data (Sub Blocks)
            // 1 Byte       Block Terminator (0x00)
            //
            // Note, the first 2 bytes are still read to identify the Comment Block.
            // Therefore, we only need to read the sub blocks and extract the data.

            string comment = ReadSubBlocks();

            // Only add the tag, if no one is still contained.
            if ((TagTypes & TagTypes.GifComment) == 0x00)
            {
                ImageTag.AddTag(new GifCommentTag(comment));

                // 2 bytes where read before
                AddMetadataBlock(position - 2, Tell - position + 2);
            }
        }
 public Image(Rectangle inRect, TexName Tex_Name, ImageTag inName)
 {
     Rect     = inRect;
     _texture = TextureManager.getInstance().find(Tex_Name);
     type     = _texture.Type;
     Name     = inName;
 }
Exemple #19
0
        private void ReadAPP13Segment(ushort length)
        {
            var data            = ReadBlock(length);
            var iptc_iim_length = IPTC_IIM_IDENTIFIER.Length;

            if (length < iptc_iim_length || data.Mid(0, iptc_iim_length) != IPTC_IIM_IDENTIFIER)
            {
                return;
            }
            var headerInfoLen = data.Mid(iptc_iim_length, 1).ToUShort();
            int lenToSkip;

            if (headerInfoLen > 0)
            {
                lenToSkip = 1 + headerInfoLen + 4;
            }
            else
            {
                lenToSkip = 6;
            }
            data.RemoveRange(0, iptc_iim_length + lenToSkip);
            var reader = new IIM.IIMReader(data);
            var tag    = reader.Process();

            if (tag != null)
            {
                ImageTag.AddTag(tag);
            }
        }
Exemple #20
0
        private void ReadApplicationExtensionBlock()
        {
            long       position = Tell;
            ByteVector data     = ReadBlock(12);

            if (data.Count != 12)
            {
                throw new CorruptFileException("");
            }
            if (data.Mid(1, 8) == XMP_IDENTIFIER && data.Mid(9, 3) == XMP_AUTH_CODE)
            {
                long data_start        = Tell;
                long xmp_trailer_start = Find(new byte[] { 0x00 }, data_start) - XMP_MAGIC_TRAILER.Length + 2;
                Seek(data_start, SeekOrigin.Begin);
                if (xmp_trailer_start <= data_start)
                {
                    throw new CorruptFileException("No End of XMP data found");
                }
                int        data_length = (int)(xmp_trailer_start - data_start);
                ByteVector xmp_data    = ReadBlock(data_length);
                ImageTag.AddTag(new XmpTag(xmp_data.ToString(StringType.UTF8), this));
                AddMetadataBlock(position - 2, 14 + data_length + XMP_MAGIC_TRAILER.Length);
                Seek(xmp_trailer_start + XMP_MAGIC_TRAILER.Length, SeekOrigin.Begin);
            }
            else
            {
                SkipSubBlocks();
            }
        }
Exemple #21
0
 public int GetImageInfo(string SID, string imagekey, out ImageTag tag)
 {
     using (new DebugLog())
     {
         return(sv.GetImageInfo(SID, imagekey, out tag));
     }
 }
Exemple #22
0
        /// <summary>
        ///    Reads an zTXt Chunk from file. The current position must be set
        ///    to the start of the Chunk Data. Such a Chunk contains compressed
        ///    keywords.
        /// </summary>
        /// <param name="data_length">
        ///    A <see cref="System.Int32"/> with the length of the Chunk Data.
        /// </param>
        /// <remarks>
        ///    The Chunk may also contain compressed Exif data which is written
        ///    by other tools. But, since the PNG specification does not support
        ///    Exif data, we ignore it here.
        /// </remarks>
        private void ReadzTXtChunk(int data_length)
        {
            long position = Tell;

            // zTXt Chunk
            //
            // N Bytes     Keyword
            // 1 Byte      Null Separator
            // 1 Byte      Compression Method
            // N Bytes     Txt
            //
            // Followed by 4 Bytes CRC data

            ByteVector data = ReadChunkData(data_length);

            CheckCRC(zTXt_CHUNK_TYPE, data, ReadCRC());

            int    terminator_index;
            string keyword = ReadKeyword(data, 0, out terminator_index);

            if (terminator_index + 1 >= data_length)
            {
                throw new CorruptFileException("Compression Method byte expected");
            }

            byte compression_method = data [terminator_index + 1];

            ByteVector plain_data = Decompress(compression_method, data.Mid(terminator_index + 2));

            // ignore unknown compression methods
            if (plain_data == null)
            {
                return;
            }

            string     value      = plain_data.ToString();
            RawProfile rawProfile = null;

            if (keyword.StartsWith("Raw profile type"))
            {
                rawProfile = ProcessRawProfile(value);
                value      = rawProfile.ToString();
            }

            // handle XMP, which has a fixed header
            if (keyword == "xmp" || rawProfile != null && string.Compare(rawProfile.Name, "xmp", StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                ImageTag.AddTag(new XmpTag(string.Join("", rawProfile.Data.ToArray()), this));
            }
            else
            {
                PngTag png_tag = GetTag(TagTypes.Png, true) as PngTag;

                if (png_tag.GetKeyword(keyword) == null)
                {
                    png_tag.SetKeyword(keyword, value);
                }
            }
            AddMetadataBlock(position - 8, data_length + 8 + 4);
        }
        public IEnumerable <Token> ParseLine(string line)
        {
            var result = new List <Token>();

            for (var i = 0; i < line.Length; i++)
            {
                if (DetermineRuleOfSubline(line, i) is null)
                {
                    continue;
                }
                var tag = getFullMarkdownTag.Match(line.Substring(i));
                if (tag.Length == 0)
                {
                    continue;
                }
                var src        = new TagAttribute(tag.Groups[2].Value, "src");
                var alt        = new TagAttribute(tag.Groups[1].Value, "alt");
                var attributes = new List <TagAttribute>()
                {
                    src, alt
                };
                var newTag = new ImageTag
                {
                    Attributes  = attributes,
                    MarkdownTag = tag.Groups[0].Value
                };
                result.Add(new Token(i, newTag));
                i += tag.Length;
            }

            return(result);
        }
Exemple #24
0
        public static ImageProperty LoadProperty(IImageDecoder decoder, ImageTag property)
        {
            if (decoder == null)
            {
                throw new ArgumentNullException();
            }
            PropertyItem item = new PropertyItem();
            uint         cbProp;

            decoder.GetPropertyItemSize(property, out cbProp);
            IntPtr pProp = Marshal.AllocHGlobal((int)cbProp);

            try
            {
                if (decoder.GetPropertyItem(property, cbProp, pProp) != 0)
                {
                    return(null);
                }
                item = (PropertyItem)Marshal.PtrToStructure(pProp, typeof(PropertyItem));
                return(LoadProperty(item));
            }
            finally
            {
                Marshal.FreeHGlobal(pProp);
            }
        }
Exemple #25
0
 public static ImageTagViewModel ToViewModel(this ImageTag obj)
 {
     return(new ImageTagViewModel()
     {
         ImageID = obj.ImageID,
         TagID = obj.TagID
     });
 }
Exemple #26
0
        private void ConvertFromImageTag(ImageTag obTag)
        {
            if (null == obTag)
            {
                throw new ArgumentNullException("obTag", "Null ImageTag object specified");
            }

            base.ConvertFromTag(obTag);
            this.m_strUrl = obTag.ImageURL;
        }
        public List <ImageTag> Filter(List <ImageTag> tags)
        {
            var tagsArray = new ImageTag[tags.Count];

            tags.CopyTo(tagsArray);
            var augmentedTagsList = new List <ImageTag>(tagsArray);

            augmentedTagsList.AddRange(from tag in tags where HumanTags.Contains(tag.Name.Trim().ToLower()) select new ImageTag("human", tag.Probability));
            return(augmentedTagsList);
        }
Exemple #28
0
    public override bool Equals(object obj)
    {
        ImageTag objTag = obj as ImageTag;

        if (objTag != null)
        {
            return(objTag.ImageId.Equals(this.ImageId) && objTag.TagId.Equals(this.TagId));
        }

        return(false);
    }
        public void SetUp()
        {
            _txt = "some text";
            _href = "href";
            _class1 = "class1";
            _class2 = "class2";
            _textLink = new LinkTag(_txt, _href, _class1, _class2);

            _imgTag = new ImageTag("image.jpg", "its an image");
            _imgLink = new LinkTag(_imgTag, _href, _class1, _class2);
        }
Exemple #30
0
        private void ReadCommentBlock()
        {
            long   position = Tell;
            string comment  = ReadSubBlocks();

            if ((TagTypes & TagTypes.GifComment) == 0x00)
            {
                ImageTag.AddTag(new GifCommentTag(comment));
                AddMetadataBlock(position - 2, Tell - position + 2);
            }
        }
        public virtual async Task <IList <ImageTag> > GetBestTags(IList <ImageTag> tags, ImageTag rating = null)
        {
            if (tags.Count < MaxTagGroup && rating != null)
            {
                return(new List <ImageTag>(tags)
                {
                    rating
                });;
            }

            if (tags.Count <= MaxTagGroup)
            {
                return(tags);
            }

            List <Tuple <string, long, ImageTag> > tag_counts =
                new List <Tuple <string, long, ImageTag> >(tags.Count);

            InvokeNewMaximum(tags.Count);

            for (int i = 0; i < tags.Count; i++)
            {
                ImageTag tag = tags[i];
                if (tag.Weight > MaxTagGroup)
                {
                    continue;
                }

                InvokeWorking($"Getting count for tag: {tag}");
                InvokeProgress(i + 1);


                tag_counts.Add(new Tuple <string, long, ImageTag>(tag.TagString, await PostCount(tag), tag));
            }

            InvokeWorking("Estimating best tag combination");

            tag_counts.Sort((e0, e1) => e0.Item2.CompareTo(e1.Item2));

            List <ImageTag> best_tags = tag_counts
                                        .Take(MaxTagGroup)
                                        .Select(kvp => tags.First(t => t.TagString == kvp.Item1))
                                        .ToList();

            InvokeWorkDone();

            if (rating != null && best_tags.Count < MaxTagGroup)
            {
                best_tags.Add(rating);
            }

            return(best_tags);
        }
 public void SaveImgTagInfo(long imageid, string[] tags)
 {
     ImageTag imgtag = new ImageTag
     {
         ImageId = imageid
     };
     long tagid;
     // タグIDを取得
     foreach (string tag in tags)
     {
         tagid = getandWriteTagId(tag);
         imgtag.TagId = tagid;
         _db.Insert(imgtag);
     }
     //long id
     //long id = getandWriteTagId("GMOテスト" + DateTime.Now.Second);
     //long id2 = getandWriteTagId("GMOテスト" + DateTime.Now.Minute);
     // 書き込み
 }
Exemple #33
0
        public int SaveTag(ImageTag tag)
        {
            if (tag != null) {
                ImageTag checktag = GetTagById (tag.ID);

                    if (checktag == null) {
                        conn.Insert (tag);
                        return tag.ID;
                    } else {
                        conn.Update (tag);
                        return tag.ID;
                    }
                }
             else {
                return -1;
            }
        }
Exemple #34
0
 public void DeleteTag(int id)
 {
     ImageTag deleteme = new ImageTag ();
         deleteme.ID = id;
         conn.Delete (deleteme);
 }
 public void SetUp()
 {
     source = "foo.jpg";
     altText = "foo";
     imageTag = new ImageTag(source, altText);
 }