2013-01-20 1 views
0

WPF의 CoverFlow 효과와 관련하여 다른 질문이 있다는 것을 알고 있습니다. 내가 가장 좋아하는 사람은 Is there a good iTunes coverflow-type control for WPF?입니다.WPF의 CoverFlow 포함 방법

"Part 7"하나를 다운로드했으며 WPF 및 C#에 있습니다.

이제

그래서, 기본적으로, 어떻게 올바르게 것을 포함 할 수 있습니다 .. 거의 특별히 GUI의 것들에 대한, 타사 라이브러리를 사용하지 않습니다 내 프로젝트에서 해당 템플릿을 사용하는 방법을 모르겠어요 내 계획? References에서 도서관을 가져간 후에는 어떻게해야합니까?

더 나은 CoverFlow 템플릿을 알고 있다면 (무료) 어떤 것을 말할 수 있습니까?

제발 도와주세요 (약간의 팁은, 내 프로젝트는 VB.NET에 있지만 나는 그것이 .DLL 아무것도 중요하지 생각하지 않는다)

답변

1

예 사용중인 CoverFlow 구성 요소, 완전하게 작동하지 않습니다 독립 실행 형 컨트롤로. 구현해야하는 ThumbnailManager이라는 인터페이스가 있습니다. VB에서 작업하려면 먼저 도구 상자에서 오른쪽 버튼을 클릭하고 항목 선택을 선택한 다음 Coverflow 구성 요소 Ded.Tutorial.Wpf.CoverFlow.Part7.FlowComponent.dll이 들어있는 .dll 파일로 이동 한 다음 선택한 후 내 MainWindow에 FlowControl을 놓을 수있었습니다. 도구 상자에서. 그런 다음 저자가 VB에 ThumbnailManager을 만드는 데 사용한 C# 코드를 변환했습니다.

ThumbnailManager.vb

Imports System.IO.IsolatedStorage 
Imports System.IO 
Imports System.Drawing 
Imports System.Drawing.Imaging 
Imports Ded.Tutorial.Wpf.CoverFlow.Part7.FlowComponent 
Imports Ded.Tutorial.Wpf.CoverFlow.Part7.FlowComponent.FlowControl 

Namespace Ded.Tutorial.Wpf.CoverFlow.Part7.FlowComponent 
    Public Class ThumbnailManager : Implements IThumbnailManager 
     Private ReadOnly store As IsolatedStorageFile 

     Private Shared Function AmazonCut(myImage As Image) As Image 
      If (myImage.Width <> myImage.Height) Then 
       Return myImage 
      End If 
      Dim bmp As Bitmap = New Bitmap(myImage) 
      Dim size As Integer = myImage.Height 
      Dim white As Integer = System.Drawing.Color.FromKnownColor(KnownColor.White).ToArgb() 
      Dim i As Integer = 0 
      While (i < size/2) 
       If (Not bmp.GetPixel(i, i).ToArgb().Equals(white)) Then Exit While 
       If (Not bmp.GetPixel(i, size - 1 - i).ToArgb().Equals(white)) Then Exit While 
       If (Not bmp.GetPixel(size - 1 - i, i).ToArgb().Equals(white)) Then Exit While 
       If (Not bmp.GetPixel(size - 1 - i, size - 1 - i).ToArgb().Equals(white)) Then Exit While 
       i += 1 
      End While 
      If (i > 0) Then 
       i += 8 
       Dim zone As Rectangle = New Rectangle(i, i, size - 2 * 1, size - 2 * i) 
       Return bmp.Clone(zone, System.Drawing.Imaging.PixelFormat.DontCare) 
      End If 
      Return bmp 
     End Function 

     Private Function GetThumbnail(path As String) As Byte() 
      Dim source As Image = Image.FromFile(path) 
      source = AmazonCut(source) 
      Dim height As Integer = source.Height 
      Dim width As Integer = source.Width 
      Dim factor As Integer = (height - 1) \ 250 + 1 
      Dim smallHeight As Integer = height \ factor 
      Dim smallWidth As Integer = width \ factor 
      Dim thumb As Image = source.GetThumbnailImage(smallWidth, smallHeight, Nothing, IntPtr.Zero) 
      Using ms As New MemoryStream 
       thumb.Save(ms, ImageFormat.Png) 
       ms.Flush() 
       ms.Seek(0, SeekOrigin.Begin) 
       Dim result(CInt(ms.Length)) As Byte 
       ms.Read(result, 0, CInt(ms.Length)) 
       Return result 
      End Using 

     End Function 

     Public Sub New() 
      store = IsolatedStorageFile.GetUserStoreForAssembly 
     End Sub 

     Public Function GetThumbnail(host As String, filepath As String) As System.Windows.Media.ImageSource Implements IThumbnailManager.GetThumbnail 
      Dim thumbName As String = Path.GetFileName(filepath) 
      If (store.GetFileNames(thumbName).Length = 0) Then 
       Using Stream As New IsolatedStorageFileStream(thumbName, FileMode.CreateNew, store) 
        Dim data() As Byte = GetThumbnail(filepath) 
        Stream.Write(data, 0, data.Length) 
       End Using 
      End If 
      Using Stream As New IsolatedStorageFileStream(thumbName, FileMode.Open, store) 
       Dim myImage As BitmapImage = New BitmapImage() 
       myImage.BeginInit() 
       myImage.CacheOption = BitmapCacheOption.OnLoad 
       myImage.StreamSource = Stream 
       myImage.EndInit() 
       myImage.Freeze() 
       Return myImage 
      End Using 
     End Function 
    End Class 
End Namespace 

나는 다음 MainWindow.xaml.vb 그가 사용 된로드 방법에 추가 클래스를 추가했습니다. 구성 요소가 작동 한 후에 Ded.Tutorial.Wpf.CoverFlow.Part7.FlowComponent.FlowControl을 으로 변경해야했습니다.

MainWindow.xaml.vb

Imports System.IO 
Imports System.Drawing.Imaging 
Imports WpfApplication1.Ded.Tutorial.Wpf.CoverFlow.Part7 


Class MainWindow 

    Public Sub New() 

     ' This call is required by the designer. 
     InitializeComponent() 

     FlowControl1.Cache = New FlowComponent.ThumbnailManager 
     Load("C:\Users\Marks-6520\Pictures\Alaska Trip") 
     slider.Minimum = 0 
     slider.Maximum = FlowControl1.Count - 1 
    End Sub 

    Public Sub Load(imagePath As String) 
     Dim imageDir As DirectoryInfo = New DirectoryInfo(imagePath) 
     Dim images As List(Of FileInfo) = New List(Of FileInfo)(imageDir.GetFiles("*.jpg")) 
     images.Sort(New FileInfoComparer) 
     For Each f As FileInfo In images 
      FlowControl1.Add(Environment.MachineName, f.FullName) 
     Next 
    End Sub 


    Private Sub slider_ValueChanged(sender As System.Object, e As System.Windows.RoutedPropertyChangedEventArgs(Of System.Double)) 

     FlowControl1.Index = Convert.ToInt32(slider.Value) 

    End Sub 
End Class 

Public Class FileInfoComparer : Implements IComparer(Of FileInfo) 

    Public Function Compare(x As System.IO.FileInfo, y As System.IO.FileInfo) As Integer Implements System.Collections.Generic.IComparer(Of System.IO.FileInfo).Compare 
     Return String.Compare(x.FullName, y.FullName) 
    End Function 
End Class 
+0

내가 "그리기 시스템의 구성원이 아닌"와 같은 오류가 "FROMFILE"는 "System.Windows.Controls.Image의 구성원이 아닌 얻을. 당신에게 WPF 프레임 워크 코드가 아닌 오래된 Windows.Forms를 사용하는 것 같습니다. – user1714647

+0

@ user1714647 그것은 커버 플로우 예제 코드에서 직접 변환되었으므로 참조에 포함하면됩니다. –

+0

@ user1714647 컨트롤의 원 작성자가 시스템을 사용했습니다. 일부 GDI 함수를 사용하기 위해 네임 스페이스 그리기.이 때문에 코드에 포함되어 있습니다. –