Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
Go Back  Xtreme Visual Basic Talk > > > Resizing an image using bitmapdecoder


Reply
 
Thread Tools Display Modes
  #1  
Old 04-03-2013, 06:13 PM
MarcD2K12 MarcD2K12 is offline
Newcomer
 
Join Date: May 2012
Posts: 9
Default Resizing an image using bitmapdecoder


Hi,

I am trying to resize any image to 150x150 using the code below, but when I use it, the resulting image is the right size but is completely corrupted, it is just a series of horizontal lines through which you can just about make out the image. Please could someone have a look at this code and see where i've gone wrong?

Many thanks

Marc

Code:
 Dim Squarefile As Windows.Storage.StorageFile = Await StorageFile.GetFileFromPathAsync(txtSquareImage.Text)

            Dim newfile = Await Squarefile.CopyAsync(ApplicationData.Current.LocalFolder, sb.ToString & Squarefile.FileType, NameCollisionOption.ReplaceExisting)


            Dim sourceStream = Await newfile.OpenAsync(FileAccessMode.Read)
            Dim decoder = Await BitmapDecoder.CreateAsync(sourceStream)

            Dim transform = New BitmapTransform
            Dim pixelData = Await decoder.GetPixelDataAsync

            Dim destinationStream = Await newfile.OpenAsync(FileAccessMode.ReadWrite)

            Dim encoder = Await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, destinationStream)
            encoder.SetPixelData(decoder.BitmapPixelFormat, decoder.BitmapAlphaMode, 150, 150, decoder.DpiX, decoder.DpiY, pixelData.DetachPixelData)
            Await encoder.FlushAsync()
Reply With Quote
  #2  
Old 04-04-2013, 10:12 AM
MarcD2K12 MarcD2K12 is offline
Newcomer
 
Join Date: May 2012
Posts: 9
Default

I have resolved this myself using a different approach:

Code:
Dim sourceFileStream = Await sourceImage.OpenAsync(Windows.Storage.FileAccessMode.Read)
        Dim destFileStream = Await destImage.OpenAsync(FileAccessMode.ReadWrite)
        '
        Dim decoder = Await BitmapDecoder.CreateAsync(sourceFileStream)
        Dim enc = Await BitmapEncoder.CreateForTranscodingAsync(destFileStream, decoder)

        Debug.WriteLine(TileType)
        '  scale the bitmap to fit
        If TileType = "square" Then

            enc.BitmapTransform.ScaledHeight = 150
            enc.BitmapTransform.ScaledWidth = 150
        End If

        If TileType = "wide" Then
            enc.BitmapTransform.ScaledHeight = 150
            enc.BitmapTransform.ScaledWidth = 310
        End If


        ' write out to the stream
        Await enc.FlushAsync

        Await destFileStream.FlushAsync

        sourceFileStream.Dispose()
        destFileStream.Dispose()
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
 
Resizing an image using bitmapdecoder
Resizing an image using bitmapdecoder
 
-->