wpf2017. 8. 7. 11:29

일반적으로 Grid라든지 컨트롤들은 자동으로 해상도에 맞게 조절해주지만


이미지는 크기가 정해져 있어서 이미지 크기가 유동적으로 변하지 않는다.


그래서 만약 Grid를 사용할때 퍼센트를 이용해서 분할하였다면 이미지를 사용한 Row나 column은 이미지가 짤릴경우가 있다.


이럴때는 ViewBox로 그 Row를 감싸면 깔끔해진다.



Posted by 동동(이재동)
iPhone App2011. 8. 24. 13:54

간단하다...

그냥 프로젝트에 Default.png 파일을 넣으면 자동으로 해준다.

참고 : http://ekle.us/index.php/2008/10/iphone-application-splash-screens

Posted by 동동(이재동)
wcf2011. 6. 16. 11:55

일단 WCF에서 보자

[WebInvoke(UriTemplate = "FileUpload?FileName={fileName}", Method = "PUT")]
       public void FileUpLoad(string fileName, Stream fileStream)
       {
           FileStream fileToupload = new FileStream("d:\\" + fileName, FileMode.Create);
 
           byte[] byteArray = new byte[10000];
           int byteRead, totalByteRead = 0;
           do
           {
               byteRead = fileStream.Read(byteArray, 0, byteArray.Length);
               totalByteRead += byteRead;
           } while (byteRead > 0);
 
           fileToupload.Write(byteArray, 0, byteArray.Length);
           fileToupload.Close();
           fileToupload.Dispose();
       }

 

일단 이렇게 메소드를 작성해서 file 이름과 stream을 받아서 파일을 경로에 쓴다.

 

method는 put으로 한다.

 

자 이제 끝이다. 이제 WPF에서 호출해보자.

 

 

 

public void ImageUpload(string fileName, string filePath)
        {
            using (WebClient webclient = new WebClient())
            {
                webclient.UploadData(new Uri(string.Format(serverUri + "/FileUpload?FileName={0}",fileName)), "put", GetData(filePath));
            }
        }
 
        private byte[] GetData(string filePath)
        {
            FileStream stream = File.OpenRead(filePath);
 
            byte[] data = new byte[stream.Length];
 
            stream.Read(data, 0, data.Length);
 
            stream.Close();
 
            return data;
        }

 

이렇게 filename과 byte로 변환된 스트림을 WCF로 날려주기만 하면 된다.

Posted by 동동(이재동)
Windows Phone 72011. 3. 15. 17:44

이번에 할려는 일은 About 페이지에 앱 리스트를 쭉 등록시키는일이다.

 

근데 서버로부터 앱리스트를 받고 그걸 뿌려줘야 하는데 xml을 이용하기로 했다.

 

앱은 이렇게 이미지가 나와야 한다.

 

 

description등 과 같은 string이야 xml에서 받아서 파싱하면 땡이지만

 

이미지는? 그래서 테스트 어플을 하나 만들었다.

 

일단 버튼을 하나 만들고

 

Webclient로부터 이미지를 하나 다운 받게 하였다.

 

private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var url = "http://4.bp.blogspot.com/_HfTuDK39Rv4/SAjoBeqcFtI/AAAAAAAAAbo/UaXaUjD6yTY/s400/cuty.jpg";
            //var url = "http://fc07.deviantart.net/fs27/i/2008/139/9/9/Cuty_Rabbit_by_Willow_San.jpg";
        
            WebClient webClient = new WebClient();
            webClient.OpenReadAsync(new Uri(url));
            webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
        }

 

다운로드가 완료되면

 

 

void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            var resInfo = new StreamResourceInfo(e.Result, null);
            var reader = new StreamReader(resInfo.Stream);
 
            byte[] contents;
            using (BinaryReader bReader = new BinaryReader(reader.BaseStream))
            {
                contents = bReader.ReadBytes((int)reader.BaseStream.Length);
            }            
            
            using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isf.FileExists("file.jpg") == true)
                {
                    isf.DeleteFile("file.jpg");
                }
                IsolatedStorageFileStream  stream = new IsolatedStorageFileStream("file.jpg", FileMode.OpenOrCreate, isf);                
                stream.Write(contents, 0, contents.Length);                
                stream.Close();
                MessageBox.Show("Finish Download");
            }
        }

 

다운로드가 완료되면 file.jpg를 하나 만들어서 IsolatedStorageFile에 저장을 한다. 그전에 저렇게 StreamResouceInfo와 StreamReader로 파일을 읽는다.

 

private void Button_Click_2(object sender, RoutedEventArgs e)
       {
           using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
           {
               IsolatedStorageFileStream stream = new IsolatedStorageFileStream("file.jpg", FileMode.Open, isf);
               var image = new BitmapImage();
               image.SetSource(stream);
 
               stream.Close();
               xImage.Source = image;
           }
       }

 

자 이제 아까 저장했던 파일을 읽어서 Image Control에 출력해보자…


참고  : http://dotnet.dzone.com/articles/operating-image-files-windows?mz=27249-windowsphone7 

대충 소스 보면 알겠지만 혹시나 모르니 소스를 첨부 한다.



Posted by 동동(이재동)
Windows Phone 72011. 2. 10. 13:41

Resource로 했을 때는 처음에 로딩을 다 하기 때문에 속도가 느려진다.

 

그래서 웬만하면 Content로 하자…더 나은 퍼포먼스가 난다.

 

그리고 Content와 했을때와 Resource로 했을때 이미지 source를 정의 할때

 

차이점 이 있다.

 

Content로 했을때에는

 

 

<Image Stretch="None" Source="/images/appbar.cancel.rest.png"/>

 

이렇게

 

Resource로 했을때 에는

 

<Image Source="/WP7SampleProject3;component/images/appbar.feature.email.rest.png"/>

 

이렇게 정의 한다.

 

behind코드도 마찬가지이다.

 

참고

http://www.windowsphonegeek.com/tips/wp7-working-with-images-content-vs-resource-build-action

Posted by 동동(이재동)
Windows Phone 72011. 1. 5. 13:15
난 처음에 Image를 넣어야 하는줄 알았더니 BitMapImage를 넣어야 하는것이였다.
 
사용하는 부분은 이렇게 이고
ItemImageSource = new BitmapImage(new Uri("/HugeFlow.FortuneCoins;component/Images/item/Coins_9.png", UriKind.RelativeOrAbsolute));            
 
 
 private BitmapImage _ItemImageSource;
        /// <summary>
        /// TODO:아이템 이미지 변경
        /// </summary>
        public BitmapImage ItemImageSource
        {
            get
            {
                return _ItemImageSource;
            }
            set
            {
                _ItemImageSource = value;

                OnPropertyChanged("ItemImageSource");
            }
        }
 
xaml코드에는
<Image Source="{Binding ItemImageSource}"  Stretch="Fill"/>
 
바인딩해서 사용하였다.
 
Posted by 동동(이재동)