//string imgurl에서 다운받아와 이미지를 얻어낸다. //그리고 flyingbox의 x 위치, y 위치가 생성 위치에 영향을 준다. public static void addDatas(ILwin.ShowScreen showscreen, WebItem thisitem, string imgurl, int box_posX, int box_posY) { //download image from url via internet thisitem.xPos = box_posX; thisitem.yPos = box_posY; //image(BitmapImage)를 URL로부터 얻어온다. thisitem.img = HTMLhandler.downloadImageFromURL(imgurl); thisitem.imgBr = new ImageBrush(thisitem.img); //********freezable 문제가 발생. 이미지 리소스에 freeze를 시행해 주자! thisitem.img.Freeze(); thisitem.imgBr.Freeze(); //이제 이미지를 연결하고 화면에 나타나도록 하여라 showscreen.getMWinReference().Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { thisitem.imgrec.Width = thisitem.img.Width; thisitem.imgrec.Height = thisitem.img.Height; //이미지의 가로나 세로가 100보다 큰 게 있다면 그 부분은 100으로 줄인다. if (thisitem.imgrec.Width > 100) thisitem.imgrec.Width = 100; if (thisitem.imgrec.Height > 100) thisitem.imgrec.Height = 100; thisitem.imgrec.Margin = new Thickness(thisitem.xPos, thisitem.yPos, thisitem.imgrec.Margin.Right, thisitem.imgrec.Margin.Bottom); thisitem.imgrec.Fill = thisitem.imgBr; thisitem.imgrec.Visibility = Visibility.Visible; //이제 표시한다. })); //************************************// System.Drawing.Bitmap abit; using(MemoryStream outStream = new MemoryStream()) { BitmapEncoder enc = new BmpBitmapEncoder(); enc.Frames.Add(BitmapFrame.Create(thisitem.img)); enc.Save(outStream); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream); abit = new System.Drawing.Bitmap(bitmap); } abit.Save("temimg.png"); }
//webImage를 생성한다. 하나의 query에 대해 주어진 개수만큼 이미지를 가져올 것이다. public static void generateWebImageThread(Datas datas, flyingBox flyingbox, string query, int start, int num, ILwin.ShowScreen showscreen) { List<string> urls = new List<string>(); //string 리스트에 url을 필요한 개수만큼 받아온다. HTMLhandler.getImages(urls, num, query); //*************위 urlgetThread가 모두 끝날 때까지 기다린다. 그리고 나서 webitems를 추가하라. //박스 이미지를 변경. 열린 박스로 만든다 flyingBox.changeImg(flyingbox, showscreen.getMWinReference(), true); for(int i = 0; i < num; i++) { //현재 플라잉 박스의 위치 int flyingbox_x = 0; int flyingbox_y = 0; //마지막 web item인지를 확인 bool isFinal = false; if (i == (num - 1)) isFinal = true; showscreen.getMWinReference().Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { flyingbox_x = (int)flyingbox.boximg.Margin.Left; flyingbox_y = (int)flyingbox.boximg.Margin.Top; })); //가져온 string 리스트의 url을 하나하나 넣어 webItem를 생성한다. WebItem.addDatas(showscreen, datas.webItems.ElementAt(start + i), urls[i], flyingbox_x, flyingbox_y); WebItem.fallingItem(showscreen, datas.webItems.ElementAt(start + i), isFinal); } }
//이제 그 이미지를 화면에 표시하고, 아래로 추락시키는 스레드를 연결시킨다. public static void fallingItem(ILwin.ShowScreen showscreen, WebItem thisitem, bool isFinal) { int item_y = 0; while (true) { //현재 webitem의 margin top 값을 가져온다 showscreen.getMWinReference().Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { item_y = (int)thisitem.imgrec.Margin.Top; })); Thread.Sleep(50); if (item_y > thisitem.FallYpos) { break; } else { showscreen.getMWinReference().Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate { thisitem.imgrec.Margin = new Thickness(thisitem.imgrec.Margin.Left, thisitem.imgrec.Margin.Top + 8, thisitem.imgrec.Margin.Right, thisitem.imgrec.Margin.Bottom); })); } } //마지막 webitem이라면 다 떨어질때까지 더 webitem을 호출하지 못하도록 블록을 시킨 걸 해제한다. if (isFinal == true) { showscreen.doingWebitem = false; //박스 이미지를 일반 이미지로 바꾼다. flyingBox.changeImg(showscreen.getFlyingboxReference(), showscreen.getMWinReference(), false); } }