2012-07-27 4 views
1

Q> 60 * 66 PNG 이미지의 모든 RGB 픽셀 값을 표시하는 데 10-34 초가 소요되는 경우 이미지 뷰어에서 이미지를 즉시 보여주는 방법은 무엇입니까?이미지의 픽셀 값을 읽는 중

 Dim clr As Integer ' or string 
     Dim xmax As Integer 
     Dim ymax As Integer 
     Dim x As Integer 
     Dim y As Integer 
     Dim bm As New Bitmap(dlgOpen.FileName) 

     xmax = bm.Width - 1 
     ymax = bm.Height - 1 

     For y = 0 To ymax 
      For x = 0 To xmax 
       With bm.GetPixel(x, y) 
        clr = .R & .G & .B 
        txtValue.AppendText(clr) 
       End With 
      Next x 
     Next y 

편집

첫번째 코드 10초 및 AMD A6에 59 * 66 PNG 이미지에 대한 텍스트 박스의 모든 값을 나타내는 주변 34초 2를 얻어
Dim bmp As New Bitmap(dlgOpen.FileName) 
Dim rect As New Rectangle(0, 0, bmp.Width, bmp.Height) 
Dim bmpData As System.Drawing.Imaging.BitmapData = bmp.LockBits(rect,Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat) 
Dim ptr As IntPtr = bmpData.Scan0 
Dim bytes As Integer = Math.Abs(bmpData.Stride) * bmp.Height 
Dim rgbValues(bytes - 1) As Byte 

System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes) 

For counter As Integer = 0 To rgbValues.Length - 1 
     txtValue.AppendText(rgbValues(counter)) 
Next 

System.Runtime.InteropServices.Marshal.Copy(rgbValues, 0, ptr, bytes) 
bmp.UnlockBits(bmpData) 

4GB RAM이있는 3500!

파일을 읽고 텍스트 상자에 쓰는 것이 같은 시간에 일어날 때 문제가 있습니다!

+0

이미지의 크기는 얼마나됩니까? –

+0

600 * 600 이미지의 경우 AMD A6에서 약 1 분 이상 소요됩니다! – Sourav

답변

1

많은 픽셀에 액세스해야하는 경우 GetPixel을 사용하는 기능이 매우 느립니다. LockBits을 사용해보세요. 이를 사용하면 거의 즉시 이미지 데이터를 수집 할 수 있습니다.

Using the LockBits method to access image data.

+0

@sourav이 도움을 받았습니까? –

+0

몇 가지 코드를 추가했지만 원본보다 느립니다. plz 편집을 봅니다! – Sourav

관련 문제