Monday, July 29, 2013

Silverlight Convert Tiff to Bitmap Image File

I know you all have had the issue of working with tiff image files in Silverlight. I wanted to share some code today that may help you all in this process. In the SilverlightApp.Web Project please add a silverlight enabled web service and add the following code.

 <OperationContract()> _
    Public Function ConvertTiffToJpegBinary(ByVal imageData As Byte()) As List(Of Byte())
        Using ms As New System.IO.MemoryStream(imageData)
 
            Using imagefile As System.Drawing.Image = System.Drawing.Image.FromStream(ms)
 
                Dim PictureList As New List(Of Byte())
 
                Dim frameDimensions As FrameDimension = New FrameDimension(imagefile.FrameDimensionsList(0))
 
                Dim frameNum As Integer = imagefile.GetFrameCount(frameDimensions)
 
                For frame As Integer = 0 To frameNum - 1
 
                    imagefile.SelectActiveFrame(frameDimensions, frame)
        
                    Using bmp As Bitmap = New Bitmap(imagefile.GetThumbnailImage(768, 1024, Nothing, System.IntPtr.Zero))
 
                        Using bmpStream As New System.IO.MemoryStream
 
                            bmp.Save(bmpStream, System.Drawing.Imaging.ImageFormat.Jpeg)
 
                            bmpStream.Position = 0
 
                            PictureList.Add(bmpStream.ToArray)
 
                        End Using
 
                    End Using
 
                    frame += 1
 
                Next
 
                Return PictureList
 
            End Using
        End Using
    End Function

After adding this code to the service below is the code on how to convert that binary data to a bitmap object to be rendered within Silverlight.

This code actually calls a service to receive the tiff byte array it then sends that information to the service specified above.

  Private Sub btnclick_Click(sender As Object, e As RoutedEventArgsHandles btnclick.Click
        Dim oasisSrv As New OasisSrv.oasiswsObjClient
        AddHandler oasisSrv.testsalesorderCompleted, Sub(Sender1 As Object, e1 As OasisSrv.testsalesorderCompletedEventArgs)
 
                                                         Dim service1client As New ServiceReference1.PortalTiffConversionServiceClient
 
                                                         AddHandler service1client.ConvertTiffToJpegBinaryCompleted, Sub(sender11 As Object, e11 As ServiceReference1.ConvertTiffToJpegBinaryCompletedEventArgs)
 
                                                                                                                         For Each rec In e11.Result
 
                                                                                                                             Using ms As New MemoryStream(rec)
 
                                                                                                                                 Dim bmp As New BitmapImage()
 
                                                                                                                                 bmp.SetSource(ms)
 
                                                                                                                                 Dim image As New Image With {.Source = bmp}
 
                                                                                                                                 Dim scroll As New ScrollViewer
 
                                                                                                                                 Dim panel As New StackPanel
 
                                                                                                                                 scroll.Content = panel
 
                                                                                                                                 panel.Children.Add(image)
 
                                                                                                                                 LayoutRoot.Children.Add(scroll)
 
                                                                                                                             End Using
 
 
                                                                                                                         Next
                                                                                                                     End Sub
                                                         service1client.ConvertTiffToJpegBinaryAsync(e1.opImage)
 
                                                     End Sub
        oasisSrv.testsalesorderAsync("")

Monday, April 25, 2011

Accessing SSRS throught Web Services

Hi,

This is a simple article explaining how to run reports off SQL server through WebServices.
Please take a look at the example and Ask questions if necessary. It is truly a simple process.

Imports System.IO Imports WEBWMS.ReportExecutionService   Public Class ReportingServices     Dim rsExec As New WEBWMS.ReportExecutionService.ReportExecutionService       Public Sub GenReport(ByVal FolderName As String, ByVal ReportName As String, ByVal ReportParameters As ParameterValue())         ' setup report connection         Dim deviceInfo As String = Nothing         Dim extension As String = [String].Empty         Dim mimeType As String = [String].Empty         Dim encoding As String = [String].Empty         Dim warnings As Warning() = Nothing         Dim streamIDs As String() = Nothing         Dim historyId As String = Nothing         Dim ExecHeader As New ExecutionHeader         Dim TrustUserHeader As New TrustedUserHeader         Dim Results As [Byte]() = Nothing         Dim ExecInfo As ExecutionInfo = New ExecutionInfo         Dim ServInfo As ServerInfoHeader = New ServerInfoHeader           My.User.InitializeWithWindowsUser()         rsExec.ExecutionHeaderValue = ExecHeader         rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials         rsExec.Url = "http://Wedge/reportserver/reportexecution2005.asmx"         ' pass parameters         rsExec.LoadReport("/" & FolderName & "/" & ReportName, historyId)         If ReportParameters.Count = 0 Then         Else             rsExec.SetExecutionParameters(ReportParameters, "en-us")         End If         ' get pdf of report          Results = rsExec.Render("PDF", deviceInfo, extension, mimeType, encoding, warnings, streamIDs)         PrintReport(Results)     End Sub       Private Sub PrintReport(ByVal Data As Byte())         Dim Path As String = "C:\Temp\Reference" & Date.Now.Millisecond.ToString & ".PDF"         Dim LabelFile As FileStream = New FileStream(Path, FileMode.Create)         LabelFile.Write(Data, 0, Data.Length)         LabelFile.Close()         RawPrinterHelper.SendFileToPrinter(My.Settings.UserLaserPrinter, Path)     End Sub End Class 

Friday, February 11, 2011

Load Operation Get User failed silvelright ria services


This post is only for users using windows authentication for silverlight and having issues.

ok first. make sure your webconfig file is similar to the one below.


Make sure on IIS that the only authentication scheme you have selected is
Windows authentication for you application and the site it is contained withing. This is because WCF and RIA doesn't support multiple authentication schemes within the same site.

Next for your application in IIS

Make sure that the default document is setup to point to the aspx page that your application created when published. Once that is setup browse to your site like this. http://Sitename/Application name if you don't browse to the site like that you might receive the same error. I had hell getting this setup and I hope this makes it easier for other users that have came across this same issue.

Please feel free to leave comments or add to this Post other steps that can deviate from the frustration in deploying your new silverlight app.