2013-01-20 41 views
0

我知道有關於WPF中CoverFlow效果的其他問題。我最喜歡的是Is there a good iTunes coverflow-type control for WPF?WPF中的CoverFlow如何包含?

我下載了一個「第7部分」,它是在WPF和C#中。現在

,我幾乎從來不使用第三方庫,專爲那些GUI,我不知道如何使用該模板在我的項目..

所以,基本上,我怎麼能包括在正確的我項目?參考文獻中的圖書館應該怎麼做?

如果你知道一個更好的CoverFlow模板(和免費),你能告訴我哪個?

請幫助(稍尖,我的項目是在VB.NET,但我不認爲它重要的.dll文件的任何東西)

回答

1

的例子CoverFlow組件所使用,完全不起作用作爲獨立控制。有一個名爲ThumbnailManager的界面需要實施。我可以通過右鍵單擊工具箱並選擇選擇項然後導航到包含Coverflow組件的.dll文件並選中它,然後我可以將FlowControl放入我的MainWindow從工具箱。然後,我將作者用來創建ThumbnailManager的C#代碼轉換爲VB。

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,他是使用加載方法。組件工作後,我還必須在MainWindow.g.vb中更改Ded.Tutorial.Wpf.CoverFlow.Part7.FlowComponent.FlowControlGlobal.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直接從您的coverflow示例代碼中直接轉換,您只需將其包含在您的引用中。 –

+0

@ user1714647該控件的原始作者使用該系統。爲了使用一些GDI函數而繪製命名空間,這就是爲什麼它被包含在代碼中的原因 –