2013-10-08 2 views
0

아마 메모리 스트림에 어떻게 든? 이 경우이미지 크기를 더 빨리 변경할 수있는 방법이 있습니까?

private void satellitesToolStripMenuItem_Click(object sender, EventArgs e) 
{ 
    file_array_satellite = Directory.GetFiles(UrlsPath, "RainImage*.*"); 
    for (int i = 0; i < file_array_satellite.Length; i++) 
    { 
     Image s = new Bitmap(file_array_satellite[i]); 
     s = resizeImage(s, new Size(100, 100)); 
     s.Save(UrlsPath + "Changed" + i.ToString("D6") + ".jpg"); 
    } 
    file_array_satellite = Directory.GetFiles(UrlsPath, "Changed*.*"); 
    if (file_array_satellite.Length > 0) 
    { 
     DateTime[] creationTimes8 = new DateTime[file_array_satellite.Length]; 
     for (int i = 0; i < file_array_satellite.Length; i++) 
      creationTimes8[i] = new FileInfo(file_array_satellite[i]).CreationTime; 
     Array.Sort(creationTimes8, file_array_satellite); 
     file_indxs_satellite = 0; 
     file_indxs_satellite = file_array_satellite.Length - 1; 
     timer1.Enabled = true; 
    } 
} 

public static Image resizeImage(Image imgToResize, Size size) 
{ 
    return (Image)(new Bitmap(imgToResize, size)); 
} 

private void pictureBox1_MouseEnter(object sender, EventArgs e) 
{ 
    file_array_satellite = Directory.GetFiles(UrlsPath, "RainImage*.*"); 
    for (int i = 0; i < file_array_satellite.Length; i++) 
    { 
     Image s = new Bitmap(file_array_satellite[i]); 
     s = resizeImage(s, new Size(500, 500)); 
    } 
    this.pictureBox1.Size = new Size(500, 500); 
    pictureBox1.Location = new Point(this.Bounds.Width/3, 
         this.Bounds.Height/3); 
    this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage; 
    pictureBox1.BringToFront(); 
} 

난의 이미지를 도시하고있어 PictureBox를 그래서이 100,100으로 이미지 크기를 변경하고있는 PictureBox에 표시 100,100 의 크기이다. 그런 다음 그림 상자가 pictureBox 영역 위로 마우스를 이동하면 그림 상자가 양식의 가운데로 이동하고 pictureBox의 크기를 500,500으로 조정하고 이미지 크기를 500,500으로 다시 변경하고 pictureBox에 표시합니다.

하드 디스크의 이미지 크기를 변경하거나 변환 할 때마다 매 3-5 초 정도 걸립니다.

더 빠른 방법으로 크기를 변환 할 수 있습니까?

편집 **

은 현재 디스플레이 이미지 크기를 조정하려고 코드를 변경하지만 pictureBox1의 이미지가 지금 같은 크기에없는과 내가있는 PictureBox에서 애니메이션을 볼 수 없습니다.

private void timer1_Tick(object sender, EventArgs e) 
     { 
      try 
      { 


       Image s = new Bitmap(file_array_satellite[file_indxs_satellite]); 
       s = resizeImage(s, new Size(100, 100)); 
       pictureBox1.Load(file_array_satellite[file_indxs_satellite]); 
       file_indxs_satellite = file_indxs_satellite - 1; 
       if (file_indxs_satellite < 0) 
       { 
        file_indxs_satellite = file_array_satellite.Length - 1; 
       } 
      } 
      catch 
      { 
       timer1.Enabled = false; 
      } 
     } 

     private void satellitesToolStripMenuItem_Click(object sender, EventArgs e) 
     { 
      file_array_satellite = Directory.GetFiles(UrlsPath, "RainImage*.*"); 
      if (file_array_satellite.Length > 0) 
      { 
       DateTime[] creationTimes8 = new DateTime[file_array_satellite.Length]; 
       for (int i = 0; i < file_array_satellite.Length; i++) 
        creationTimes8[i] = new FileInfo(file_array_satellite[i]).CreationTime; 
       Array.Sort(creationTimes8, file_array_satellite); 
       file_indxs_satellite = 0; 
       file_indxs_satellite = file_array_satellite.Length - 1; 
       timer1.Enabled = true; 
      } 
     } 

     public static Image resizeImage(Image imgToResize, Size size) 
     { 
      return (Image)(new Bitmap(imgToResize, size)); 
     } 
+0

미리 이미지를 메모리에로드하십시오. –

+0

이것이 더 빠르면 잘 모르겠지만 더 간단 할 수도 있습니다 ... Image.GetThumbnailImage(); – series0ne

+3

그림 상자에 이미지 파일 중 하나만 표시 할 수있는 경우 전체 디렉터리에 이미지 파일을 반복하고 크기를 조정하는 이유는 분명하지 않습니다. 이것은 느릴 것으로 예상됩니다. 똑똑한 코드를 작성하고 표시된 이미지의 크기 만 조절하십시오. –

답변

3

구현에 몇 가지 문제는, 이러한 첫 번째 수정 : 당신은 당신의 이미지의 500x500> 품질 손실의 뒤쪽으로 100 × 100에 500x500에서 크기를 조정하고있어

  • .
  • 이미지를 삭제하지 않으려 고합니다.
  • 하나의 이미지 만 표시하려면 왜 모든 이미지를로드하고 크기를 조정합니까? 가져온 이미지의 크기를 조정하면 디스크에 저장하지 않아도됩니다.
    • 만 그들이 스크롤 시작하면 더로드, 실제로 GUI에서 볼 그 이미지를로드 : 당신이 이미지를 많이 보여주고 싶은 경우

    일부 일반 힌트.

  • 여전히 느린 경우 백그라운드 스레드에로드하고 완료되면 이미지별로 이미지를 표시하십시오.
+0

카라 오른쪽. 내가 500x500에서 100x100까지 chagning하는 이유는 당신이 pictureBox 위에 마우스를 움직일 때 더 큰 pictureBox와 이미지를 보여주고 싶었 기 때문입니다. 스트레치 또는 다른 것을 사용하면 이미지의 크기를 변환하면 품질도 좋지 않을 것입니다. 500x500으로 변경하면 품질이 상당히 좋습니다. 코드는 어떻게되어야할까요? –

관련 문제