0

when i use this code:

        Try
        Dim f As TagLib.File = TagLib.File.Create(FolderBrowser.FileName, GETtypename(FolderBrowser.FileName), TagLib.ReadStyle.None)
        Dim pic As TagLib.IPicture = f.Tag.Pictures(0)
        Dim ms As MemoryStream = New IO.MemoryStream(pic.Data.Data)
        ms.Seek(0, SeekOrigin.Begin)
        Dim bitmap As BitmapImage = New BitmapImage
        bitmap.BeginInit()
        bitmap.StreamSource = ms
        bitmap.EndInit()

        IMAGEsongs.BackgroundImage = Image.FromStream(bitmap.StreamSource)
        IMAGEsongs.Visible = True
    Catch ex As Exception
        IMAGEsongs.Visible = False
    End Try

Form size is reduced by 50% and all lines or texts return to their normal type I tried to use this to return the form size to what it was in form load:

Me.Size = New Size(xxx, xxx)

But it didn't work, how do i fix this problem?

  • 4
    Why are you using a `BitmapImage` here? What is your `MemoryStream` containing? Where are these Images coming from? What is their Format? In relation to the *problem*, see [DPI Awareness - Unaware in one Release, System Aware in the Other](https://stackoverflow.com/a/50276714/7444103). Short version: make your app DpiAware or disable the automatic DpiAwareness introduced when referencing WPF assemblies (as shown at the bottom of those notes). Or, don't reference WPF assemblies and use a `System.Drawing.Bitmap` instead of a BitmapImage/BitmapSource (if possible). – Jimi Sep 13 '20 at 14:43
  • 1
    Well, the question vs the code example makes no sense. What has all this got to do with resizing the form. Don't see any relevance to what you're asking about. When you say it doesn't work, what do you mean? Getting exceptions or undesired results? – Hursey Sep 13 '20 at 20:18
  • 1
    @Hursey This can happens. The app is not DpiAware, so its Windows (Forms here) are virtualized by the System. When the application becomes DpiAware, because WPF assemblies generate automatic DpiAwareness, the Windows (Forms) are not virtualized anymore and assume their *normal* size (also, possibly, not all them). In the WinForms Platform, unlike WPF, there's nothing really built-in that handles this, you have to code for it. Or, you can make the application DpiAware and design it as such. This behavior is described in the notes I linked (because the question itself is exactly about this). – Jimi Sep 13 '20 at 21:40

0 Answers0