Click here to Skip to main content
15,905,967 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: C is a better language than any language you care to name. Pin
PIEBALDconsult3-Jun-14 10:34
mvePIEBALDconsult3-Jun-14 10:34 
GeneralRe: C is a better language than any language you care to name. Pin
Kenneth Kasajian3-Jun-14 6:35
Kenneth Kasajian3-Jun-14 6:35 
GeneralRe: C is a better language than any language you care to name. Pin
PIEBALDconsult3-Jun-14 8:31
mvePIEBALDconsult3-Jun-14 8:31 
GeneralRe: C is a better language than any language you care to name. Pin
Kenneth Kasajian3-Jun-14 9:50
Kenneth Kasajian3-Jun-14 9:50 
GeneralRe: C is a better language than any language you care to name. Pin
PIEBALDconsult3-Jun-14 10:49
mvePIEBALDconsult3-Jun-14 10:49 
GeneralRe: C is a better language than any language you care to name. Pin
Colborne_Greg30-May-14 7:15
Colborne_Greg30-May-14 7:15 
GeneralRe: C is a better language than any language you care to name. Pin
PIEBALDconsult30-May-14 16:20
mvePIEBALDconsult30-May-14 16:20 
GeneralRe: C is a better language than any language you care to name. Pin
Colborne_Greg31-May-14 15:15
Colborne_Greg31-May-14 15:15 
Which is more readable to everyone, and which uses less lines?

Public Shared Function RotateStream(stream As IsolatedStorageFileStream, angle As Int16) As WriteableBitmap
    stream.Position = 0

    Dim bitmap = New BitmapImage()

    bitmap.SetSource(stream)

    Dim WriteableBitmapSource = New WriteableBitmap(bitmap)
    Dim WriteableBitmapTarget As WriteableBitmap
    Dim Target As Int64

    With WriteableBitmapSource

        Select Case angle
            Case 360 : Return WriteableBitmapSource
            Case 180 : WriteableBitmapTarget = New WriteableBitmap(.PixelWidth, .PixelHeight)
            Case Else : WriteableBitmapTarget = New WriteableBitmap(.PixelHeight, .PixelWidth)
        End Select

        For xAxis = 0 To .PixelWidth
            For yAxis = 0 To .PixelHeight
                Select Case angle
                    Case 90
                        Target = (.PixelWidth - yAxis - 1) + (xAxis * WriteableBitmapTarget.PixelHeight)
                        WriteableBitmapTarget.Pixels(Target) = .Pixels(xAxis + yAxis * .PixelWidth)
                    Case 180
                        Target = (.PixelWidth - xAxis - 1) + (.PixelHeight - yAxis - 1) * .PixelWidth
                        WriteableBitmapTarget.Pixels(Target) = .Pixels(xAxis + yAxis * .PixelWidth)
                    Case 270
                        Target = yAxis + (.PixelWidth - xAxis - 1) * WriteableBitmapTarget.PixelWidth
                        WriteableBitmapTarget.Pixels(Target) = .Pixels(xAxis + yAxis * .PixelWidth)
                End Select
            Next
        Next

    End With

    Return WriteableBitmapTarget
End Function


versus without

public static WriteableBitmap RotateStream(IsolatedStorageFileStream stream, int angle)
       {
           stream.Position = 0;
           if (angle % 90 != 0 || angle < 0) throw new ArgumentException();

           int target;
           BitmapImage bitmap = new BitmapImage();

           bitmap.SetSource(stream);

           WriteableBitmap wbSource = new WriteableBitmap(bitmap);

           if (angle % 360 == 0) return wbSource;
           WriteableBitmap wbTarget = null;

           if (angle % 180 == 0)
           {
               wbTarget = new WriteableBitmap(wbSource.PixelWidth, wbSource.PixelHeight);
           }

           else
           {
               wbTarget = new WriteableBitmap(wbSource.PixelHeight, wbSource.PixelWidth);
           }
           for (int x = 0; x < wbSource.PixelWidth; x++)
           {
               for (int y = 0; y < wbSource.PixelHeight; y++)
               {
                   switch (angle % 360)
                   {
                       case 90:
                           target = (wbSource.PixelHeight - y - 1) + x * wbTarget.PixelWidth;
                           wbTarget.Pixels[target] = wbSource.Pixels[x + y * wbSource.PixelWidth];
                           break;
                       case 180:
                           target = (wbSource.PixelWidth - x - 1) + (wbSource.PixelHeight - y - 1) * wbSource.PixelWidth;
                           wbTarget.Pixels[target] = wbSource.Pixels[x + y * wbSource.PixelWidth];
                           break;
                       case 270:
                           target = y + (wbSource.PixelWidth - x - 1) * wbTarget.PixelWidth;
                           wbTarget.Pixels[target] = wbSource.Pixels[x + y * wbSource.PixelWidth];
                           break;
                   }
               }
           }
           return wbTarget;
       }


Visual basic is better
GeneralRe: C is a better language than any language you care to name. Pin
PIEBALDconsult31-May-14 17:25
mvePIEBALDconsult31-May-14 17:25 
GeneralRe: C is a better language than any language you care to name. Pin
Colborne_Greg1-Jun-14 15:38
Colborne_Greg1-Jun-14 15:38 
GeneralRe: C is a better language than any language you care to name. Pin
PIEBALDconsult1-Jun-14 17:08
mvePIEBALDconsult1-Jun-14 17:08 
GeneralRe: C is a better language than any language you care to name. Pin
Colborne_Greg1-Jun-14 20:46
Colborne_Greg1-Jun-14 20:46 
GeneralRe: C is a better language than any language you care to name. Pin
PIEBALDconsult2-Jun-14 3:18
mvePIEBALDconsult2-Jun-14 3:18 
GeneralRe: C is a better language than any language you care to name. Pin
Colborne_Greg2-Jun-14 5:44
Colborne_Greg2-Jun-14 5:44 
GeneralRe: C is a better language than any language you care to name. Pin
Stefan_Lang2-Jun-14 2:59
Stefan_Lang2-Jun-14 2:59 
GeneralRe: C is a better language than any language you care to name. Pin
Colborne_Greg2-Jun-14 5:41
Colborne_Greg2-Jun-14 5:41 
GeneralRe: C is a better language than any language you care to name. Pin
Stefan_Lang2-Jun-14 20:36
Stefan_Lang2-Jun-14 20:36 
GeneralRe: C is a better language than any language you care to name. Pin
Colborne_Greg3-Jun-14 15:07
Colborne_Greg3-Jun-14 15:07 
GeneralRe: C is a better language than any language you care to name. Pin
Stefan_Lang3-Jun-14 20:29
Stefan_Lang3-Jun-14 20:29 
GeneralRe: C is a better language than any language you care to name. Pin
Charles Wolfe30-May-14 13:08
Charles Wolfe30-May-14 13:08 
GeneralRe: C is a better language than any language you care to name. Pin
jschell30-May-14 13:22
jschell30-May-14 13:22 
GeneralRe: C is a better language than any language you care to name. Pin
Stefan_Lang2-Jun-14 2:38
Stefan_Lang2-Jun-14 2:38 
GeneralRe: C is a better language than any language you care to name. Pin
Br.Bill2-Jun-14 11:04
Br.Bill2-Jun-14 11:04 
GeneralRe: C is a better language than any language you care to name. Pin
Al Chak5-Jun-14 1:42
Al Chak5-Jun-14 1:42 
GeneralRe: C is a better language than any language you care to name. Pin
BotReject20-Jun-14 23:30
BotReject20-Jun-14 23:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.