Esempio n. 1
0
    IEnumerator GetImage()
    {
        WWWForm form = new WWWForm();
        string  id   = jstest.URI;
        //string url = $"http://localhost:3000/games/{id}/image/";
        string          url     = "http://localhost:3000/games/14/image/";
        UnityWebRequest request = UnityWebRequest.Get(url);

        request.SetRequestHeader("Content-Type", "application/json");
        Debug.Log("yield");
        //画像を取得できるまで待つ
        yield return(request.SendWebRequest());

        if (request.isNetworkError || request.isHttpError)
        {
            Debug.Log(request.error);
        }
        else
        {
            //取得した画像のテクスチャ
            // byte[] results = request.downloadHandler.data;
            // CreateSpriteFromBytes(results);
            string    json         = request.downloadHandler.text;
            ImageJson imageJson    = JsonUtility.FromJson <ImageJson>(json);
            Texture2D stageTexture = CreateTextureFromBytes(Convert.FromBase64String(imageJson.stage));
            Texture2D texture      = CreateTextureFromBytes(Convert.FromBase64String(imageJson.player));

            // ステージを作成
            GameObject stage = new GameObject("Stage");
            stage.AddComponent <SpriteRenderer>();
            stage.GetComponent <SpriteRenderer>().sprite = Sprite.Create(stageTexture, new Rect(0, 0, stageTexture.width, stageTexture.height), new Vector2(0.5f, 0.5f));
            stage.AddComponent <PolygonCollider2D>();
            stage.tag = "Ground";

            // プレイヤーを作成
            GameObject     player         = GameObject.Find("Player");
            GameObject     groundCheck    = (GameObject)Resources.Load("GroundCheck");
            GameObject     headCheck      = (GameObject)Resources.Load("HeadCheck");
            SpriteRenderer spriteRenderer = player.GetComponent <SpriteRenderer>();
            spriteRenderer.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            Vector2 startPosition = new Vector2(-10.0f, -3.0f);
            player.transform.position = startPosition;
            player.AddComponent <PolygonCollider2D>();
            player.AddComponent <Rigidbody2D>();
            player.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
            player.AddComponent <Player>();
            // New Spriteプレハブを元に、インスタンスを生成、
            // player = (GameObject)Instantiate(player, new Vector3(0.0f, 4.0f, 0.0f), Quaternion.identity);
            groundCheck = (GameObject)Instantiate(groundCheck, player.transform.position, Quaternion.identity);
            headCheck   = (GameObject)Instantiate(headCheck, player.transform.position, Quaternion.identity);
            groundCheck.transform.parent          = player.transform;
            headCheck.transform.parent            = player.transform;
            player.GetComponent <Player>().ground = groundCheck.GetComponent <GroundCheck>();
            player.GetComponent <Player>().head   = headCheck.GetComponent <GroundCheck>();

            //return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
        }
    }
Esempio n. 2
0
        public IActionResult ShowInformation(string url)
        {
            var       json      = ImageAnalysis.MakeAnalysisRequest(url).Result;
            ImageJson imageJson = new ImageJson()
            {
                JSON = json,
                URL  = url
            };

            return(View(imageJson));
        }
Esempio n. 3
0
        /// <summary>
        /// 根据类型获取图片信息
        /// </summary>
        /// <param name="imgTypeID">图片类型ID</param>
        /// <param name="startImgNumber">起始图片数</param>
        /// <param name="ImgCount">获取图片的数量</param>
        /// <returns></returns>
        public ImageJson getImageInfos(string imgTypeID, string startImgNumber, string ImgCount)
        {
            string curl = @"http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid=" + imgTypeID.ToString() + "&start=" + startImgNumber.ToString() + "&count=" + ImgCount.ToString();

            //创建一个HttpWebRequest对象
            req = (HttpWebRequest)HttpWebRequest.Create(curl);
            //设置它提交数据的方式GET
            req.Method = "GET";
            StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream());
            //获取返回的XML数据
            string Reader            = Unicode2String(sr.ReadToEnd());
            JavaScriptSerializer jss = new JavaScriptSerializer();
            ImageJson            it  = jss.Deserialize <ImageJson>(Reader);

            return(it);
        }
Esempio n. 4
0
        /// <summary>
        /// 搜索图片
        /// </summary>
        /// <param name="words">关键字</param>
        /// <param name="startImgNumber">起始数</param>
        /// <param name="ImgCount">要获取的总数</param>
        /// <returns></returns>
        public ImageJson getImageInfosBySearch(string words, string startImgNumber, string ImgCount)
        {
            //index.php?c=WallPaper&a=search&start=0&count=9&kw=%E4%B8%9D%E8%A2%9C
            string curl = @"http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=search&start=" + startImgNumber.ToString() + "&count=" + ImgCount.ToString() + "&kw=" + words.ToString();

            //创建一个HttpWebRequest对象
            req = (HttpWebRequest)HttpWebRequest.Create(curl);
            //设置它提交数据的方式GET
            req.Method = "GET";
            StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream());
            //获取返回的XML数据
            string Reader            = Unicode2String(sr.ReadToEnd());
            JavaScriptSerializer jss = new JavaScriptSerializer();
            ImageJson            it  = jss.Deserialize <ImageJson>(Reader);

            return(it);
        }
        private (Transaction transaction, ImageJson image) Translate(TransactionInput input)
        {
            var        guidImage       = Guid.NewGuid();
            var        guidTransaction = Guid.NewGuid();
            var        date            = DateTime.Now;
            FormatEnum format          = GetFormat(input.Format);
            var        imgJson         = new ImageJson {
                Id = guidImage, Data = input.File, Format = format
            };
            var transacion = new Transaction
            {
                Title       = input.Title,
                Description = input.Description,
                Cash        = input.Cost,
                Date        = date,
                Id          = guidTransaction,
                File        = guidImage
            };

            return(transacion, imgJson);
        }
Esempio n. 6
0
        public void BeforeEachTest()
        {
            _imageRepo = new ImageRepo();

            _imageData = "[{\"albumId\": 1,\"id\": 1, \"title\":\"T\",\"url\":\"LOL\",\"thumbnailUrl\":\"LOL\"}]";
            _albumData = "[{\"id\": 1,\"title\": \"TEST\", \"userId\":1}]";

            _resultImage = new ImageJson
            {
                albumId      = 1,
                id           = 1,
                thumbnailUrl = "LOL",
                title        = "T",
                url          = "LOL"
            };

            _resultAlbum = new AlbumJson
            {
                id     = 1,
                title  = "TEST",
                userId = 1
            };
        }
Esempio n. 7
0
 public IEnumerable <ImageModel> ImageData()
 {
     return(ImageJson.GetImages());
 }
        public void ImageRoot_GetJson_SuccessWithoutExceptions()
        {
            // https://derpibooru.org/api/v1/json/images/1384692
            var           uri       = _baseUri.AppendPathSegment("/images/1384692");
            ImageRootJson imageRoot = null;
            ImageJson     image     = null;

            Func <Task> act = async() =>
            {
                var json = await uri.GetStringAsync();

                imageRoot = JsonSerializer.Deserialize <ImageRootJson>(json);
                image     = imageRoot.Image;
            };

            act.Should().NotThrow();
            imageRoot.Should().NotBeNull();

            // Property validation
            image.AspectRatio.Should().BeApproximately(0.7588075880758808, 4);
            image.CommentCount.Should().BeGreaterOrEqualTo(32);
            image.CreatedAt.Should().Be(DateTime.Parse("2017-03-11T20:32:14"));
            image.DeletionReason.Should().BeNull();
            image.Description.Should().Be("Pony in box, inspired by my cat as usual X3 Just quick color sketch)");
            image.DownvoteCount.Should().BeGreaterOrEqualTo(6);
            image.DuplicateOf.Should().BeNull();
            image.Duration.Should().Be(0.04);
            image.FaveCount.Should().BeGreaterOrEqualTo(1408);
            image.FirstSeenAt.Should().Be(DateTime.Parse("2017-03-11T20:32:14"));
            image.Format.Should().Be("PNG");
            image.HasGeneratedThumbnails.Should().BeTrue();
            image.Height.Should().Be(1845);
            image.HiddenFromUsers.Should().BeFalse();
            image.Id.Should().Be(1384692);
            image.IsAnimated.Should().BeFalse();
            image.IsProcessed.Should().BeTrue();
            image.IsSpoilered.Should().BeFalse();
            image.MimeType.Should().Be("image/png");
            image.Name.Should().Be("favorite_place__color_sketch__by_yakovlev_vad-db1ybkb.png");
            image.OriginalSHA512Hash.Should().Be("a5b68e1cb435a818cc15d5a4e8f879d350700ae1dbe9d12b7d9e421abc6d2f6b622318d99d0e5b120c2c59b3df3b9b120e065a507142f48525935cbfd836588d");
            image.Score.Should().Be(image.UpvoteCount - image.DownvoteCount);
            image.SHA512Hash.Should().Be("a5b68e1cb435a818cc15d5a4e8f879d350700ae1dbe9d12b7d9e421abc6d2f6b622318d99d0e5b120c2c59b3df3b9b120e065a507142f48525935cbfd836588d");
            image.SourceUri.Should().Be("http://yakovlev-vad.deviantart.com/art/Favorite-place-Color-Sketch-668408843");
            image.TagCount.Should().Be(image.TagIds.Length);
            image.TagIds.Should().HaveCount(image.TagCount);
            image.Tags.Should().HaveCount(image.TagCount);
            image.UpdatedAt.Should().Be(DateTime.Parse("2020-07-02 11:33:07"));
            image.Uploader.Should().BeNull();
            image.UploaderId.Should().BeNull();
            image.UpvoteCount.Should().Be(image.Score + image.DownvoteCount);
            image.ViewUri.Should().Be("https://derpicdn.net/img/view/2017/3/11/1384692__safe_artist-colon-yakovlev-dash-vad_fluttershy_pegasus_pony_-colon-3_-colon-t_bed_behaving+like+a+cat_box_cheek+fluff_chest+fluff_colored+sketch_cute_d.png");
            image.Width.Should().Be(1400);
            image.WilsonScore.Should().BeGreaterThan(0);

            image.Intensities.Should().NotBeNull();
            image.Intensities.NE.Should().BeGreaterThan(0);
            image.Intensities.NW.Should().BeGreaterThan(0);
            image.Intensities.SE.Should().BeGreaterThan(0);
            image.Intensities.SW.Should().BeGreaterThan(0);

            image.Representations.Should().NotBeNull();
            image.Representations.Full.Should().NotBeNullOrEmpty();
            image.Representations.Large.Should().NotBeNullOrEmpty();
            image.Representations.Medium.Should().NotBeNullOrEmpty();
            image.Representations.Small.Should().NotBeNullOrEmpty();
            image.Representations.Tall.Should().NotBeNullOrEmpty();
            image.Representations.Thumb.Should().NotBeNullOrEmpty();
            image.Representations.ThumbSmall.Should().NotBeNullOrEmpty();
            image.Representations.ThumbTiny.Should().NotBeNullOrEmpty();
        }
Esempio n. 9
0
 public void GivenIHaveTheFollowingImage(Table table)
 {
     _image = table.CreateInstance <ImageJson>();
 }