Represents a LEADTOOLS control for the remote interactive browsing, loading and displaying of JPEG2000 images using the JPEG2000 Interactive Protocol (JPIP) protocol.
[ToolboxBitmapAttribute()]public class JpipRasterImageViewer : Leadtools.Winforms.Leadtools.WinForms.RasterImageViewer, System.ComponentModel.IComponent, System.ComponentModel.ISynchronizeInvoke, System.IDisposable, System.Windows.Forms.IBindableComponent, System.Windows.Forms.IDropTarget, System.Windows.Forms.IWin32Window
<ToolboxBitmapAttribute()>Public Class JpipRasterImageViewerInherits Leadtools.Winforms.Leadtools.WinForms.RasterImageViewerImplements System.ComponentModel.IComponent, System.ComponentModel.ISynchronizeInvoke, System.IDisposable, System.Windows.Forms.IBindableComponent, System.Windows.Forms.IDropTarget, System.Windows.Forms.IWin32Window
[ToolboxBitmapAttribute()]public ref class JpipRasterImageViewer : public Leadtools.Winforms.Leadtools.WinForms.RasterImageViewer, System.ComponentModel.IComponent, System.ComponentModel.ISynchronizeInvoke, System.IDisposable, System.Windows.Forms.IBindableComponent, System.Windows.Forms.IDropTarget, System.Windows.Forms.IWin32Window
The JpipRasterImageViewer is a JPIP client that can establish a connection with a JPIP server, access images on the server side, and load them interactively as the user pans, views or scrolls the image. When a file is first opened, the JpipRasterImageViewer control loads the lowest resolution that fits the viewer window and loads more data as the user starts panning, zooming or scrolling. If the image has multiple color components (Red, Green, Blue), browsing can be done for the desired component only.
This example creates an instance of the JpipRasterImageViewer and requests an image, zooms in, specifies a component and copies the image to a local file.
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.JpipImports Leadtools.Jpip.Client.WinFormsImports Leadtools.Jpip.Client.InteractiveDecoderImports Leadtools.Jpip.ServerPrivate Const SERVER_NAME As String = "LEAD JPIP Server - Test Server"Private Const ENUMERATION_SERVER_PORT As Integer = 109Private Const JPIP_SERVER_PORT As Integer = 108Private Const LOCAL_IP_ADDRESS As String = "127.0.0.1"Private CLIENT_CACHE_DIRECTORY As String = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000")Private SERVER_CACHE_DIRECTORY As String = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000")Private SERVER_IMAGES_FOLDER As String = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000")Private IMAGE_FILE_EXTENSIONS As String = "*.j2k;*.jp2;*.jpx"Private CLIENT_SAVED_FILE_NAME As String = Path.Combine(LEAD_VARS.ImagesDir, "test.bmp")Private _jpipServer As JpipServerPrivate _imageFileExtensions As List(Of String)Private _listener As HttpListenerPublic _serverImagesList As List(Of String) = New List(Of String)()Public Sub New()#If LEADTOOLS_V175_OR_LATER ThenLeadtools.Examples.Support.SetLicense()#ElseLeadtools.Examples.Support.Unlock()#End If ' #If LEADTOOLS_V175_OR_LATER Then_imageFileExtensions = New List(Of String)()_jpipServer = New JpipServer()End SubPublic Sub ClientRequestReceived(ByVal ar As IAsyncResult)Dim context As HttpListenerContextIf Nothing Is _listener OrElse (Not _listener.IsListening) ThenReturnEnd IfTrycontext = _listener.EndGetContext(ar)CatchReturnEnd TryTryDim formattedImages As StringDim sendBuffer As Byte()_listener.BeginGetContext(AddressOf ClientRequestReceived, Nothing)formattedImages = GetFormattedServerImagesString()sendBuffer = Encoding.ASCII.GetBytes(formattedImages)context.Response.OutputStream.Write(sendBuffer, 0, sendBuffer.Length)context.Response.Close()Catch e1 As ExceptionIf Not Nothing Is context Thencontext.Response.Close()End IfEnd TryEnd SubPublic Function GetFormattedServerImagesString() As StringDim serverImageFile As StringDim formattedServerImagesString As String = String.EmptyDim searchImages As List(Of String) = New List(Of String)()Dim serverImages As List(Of String) = New List(Of String)()For Each extension As String In _imageFileExtensionssearchImages.AddRange(Directory.GetFiles(_jpipServer.Configuration.ImagesFolder, extension, SearchOption.AllDirectories))Next extensionFor Each file As String In searchImagesserverImageFile = file.Replace(_jpipServer.Configuration.ImagesFolder, String.Empty)serverImageFile = serverImageFile.TrimStart("\"c)formattedServerImagesString &= serverImageFile & ";"Next filesearchImages.Clear()For Each aliasFolder As KeyValuePair(Of String, String) In _jpipServer.Configuration.AliasFoldersIf (Not Directory.Exists(aliasFolder.Value)) ThenContinue ForEnd IfFor Each extension As String In _imageFileExtensionssearchImages.AddRange(Directory.GetFiles(aliasFolder.Value, extension, SearchOption.AllDirectories))Next extensionFor Each imageFile As String In searchImagesserverImageFile = imageFile.Replace(aliasFolder.Value, aliasFolder.Key)serverImageFile = serverImageFile.TrimStart("\"c)formattedServerImagesString &= serverImageFile & ";"Next imageFilesearchImages.Clear()Next aliasFolderReturn formattedServerImagesString.TrimEnd(";"c)End FunctionPublic Sub StartFileEnumerationServer()Try_imageFileExtensions.Clear()_imageFileExtensions.AddRange(IMAGE_FILE_EXTENSIONS.Split(";"c))If Not _listener Is Nothing Then 'if _listner is already created, then do not create againReturnEnd If_listener = New HttpListener()_listener.Prefixes.Add(String.Format("http://{0}:{1}/", LOCAL_IP_ADDRESS, ENUMERATION_SERVER_PORT))_listener.Start()_listener.BeginGetContext(AddressOf ClientRequestReceived, Nothing)Catch ex As ExceptionDebug.Fail("Error in server enumeration: " & Constants.vbLf + ex.Message)End TryEnd SubPublic Sub StopFileEnumerationServer()TryIf Not _listener Is Nothing Then_listener.Stop()End IfCatch ex As ExceptionDebug.Fail("Error in server enumeration: " & Constants.vbLf + ex.Message)End TryEnd SubPublic Sub GetEnumeratedFiles(ByVal filename As String)Dim request As HttpWebRequest = CType(HttpWebRequest.Create(String.Format("http://{0}:{1}/", LOCAL_IP_ADDRESS, ENUMERATION_SERVER_PORT)), HttpWebRequest)If Not Nothing Is request.Proxy Thenrequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentialsEnd Ifrequest.UseDefaultCredentials = TrueDim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)Dim receivedStream As System.IO.Stream = response.GetResponseStream()Dim reader As System.IO.StreamReader = New System.IO.StreamReader(receivedStream)Dim read As Char() = New Char(255) {}' Reads 256 characters at a time.Dim count As Integer = reader.Read(read, 0, 256)Dim imageNames As String = ""Do While count > 0' Dumps the 256 characters on a string and displays the string to the console.Dim temp As String = New String(read, 0, count)imageNames &= tempcount = reader.Read(read, 0, 256)Loop' Releases the resources of the response.response.Close()' Releases the resources of the Stream.reader.Close()Dim imageFileNames As String() = imageNames.Split(";"c)Dim counter As Integer = 0For Each image As String In imageFileNamescounter += 1Debug.Assert(image.Trim().Length > 0, "There is no image to enumerate")Debug.WriteLine("Image " & counter & ": " & image)_serverImagesList.Add(image)Next imageFile.WriteAllLines(filename, _serverImagesList.ToArray())End SubPublic Sub StartJpipServer()If (Not _jpipServer.IsRunning) Then'Server Settings_jpipServer.Configuration.ServerName = SERVER_NAME_jpipServer.Configuration.IPAddress = LOCAL_IP_ADDRESS_jpipServer.Configuration.Port = JPIP_SERVER_PORT_jpipServer.Configuration.ImagesFolder = SERVER_IMAGES_FOLDER_jpipServer.Configuration.CacheFolder = SERVER_CACHE_DIRECTORY_jpipServer.Configuration.MaxServerBandwidth = _jpipServer.Configuration.MaxServerBandwidth_jpipServer.Configuration.CacheSize = 200_jpipServer.Configuration.DivideSuperBoxes = True_jpipServer.Configuration.ChunkSize = 512_jpipServer.Configuration.MaxClientCount = 5_jpipServer.Configuration.ConnectionIdleTimeout = New TimeSpan(0, 0, 9100)_jpipServer.Configuration.MaxSessionLifetime = New TimeSpan(0, 0, 9900)_jpipServer.Configuration.MaxConnectionBandwidth = _jpipServer.Configuration.MaxConnectionBandwidth'Communication Settings_jpipServer.Configuration.MaxTransportConnections = 15_jpipServer.Configuration.HandshakeTimeout = New TimeSpan(0, 0, 9600)_jpipServer.Configuration.RequestTimeout = New TimeSpan(0, 0, 920)_jpipServer.Configuration.ChunkSize = 512'Images Settings_jpipServer.Configuration.ImageParsingTimeout = New TimeSpan(0, 0, 9180)_jpipServer.Configuration.PartitionBoxSize = 40_jpipServer.Configuration.DivideSuperBoxes = True'Logging Settings_jpipServer.Configuration.LogInformation = False_jpipServer.Configuration.LogWarnings = False_jpipServer.Configuration.LogDebug = False_jpipServer.Configuration.LogErrors = False'Start server and delegates_jpipServer.Start()Debug.Assert(_jpipServer.IsRunning, "Server did not start.")End IfEnd SubPublic Sub StopJpipServer()If _jpipServer.IsRunning Then_jpipServer.Stop()End IfEnd SubPublic Sub SetJpipViewer(ByVal viewer As JpipRasterImageViewer)' Initialize JPIP viewerviewer.CacheDirectoryName = CLIENT_CACHE_DIRECTORYviewer.PortNumber = JPIP_SERVER_PORTviewer.IPAddress = LOCAL_IP_ADDRESSviewer.PacketSize = 16384viewer.RequestTimeout = New TimeSpan(0, 1, 0)viewer.ChannelType = JpipChannelTypes.HttpChannelEnd SubPublic Sub SaveJpipViewerImageToFile(ByVal viewer As JpipRasterImageViewer, ByVal fileName As String)Dim rc As RasterCodecs = New Leadtools.Codecs.RasterCodecs()rc.Save(viewer.Image, fileName, RasterImageFormat.Bmp, 24)End SubPrivate Sub OnClientError(ByVal sender As Object, ByVal e As ErrorEventArgs)Debug.WriteLine(e.GetException().Message)End SubPrivate Sub OnBytesLoaded(ByVal sender As Object, ByVal e As TotalBytesLoadedEventArgs)Debug.WriteLine(" Total Bytes: " & e.ByteCount.ToString())End SubPrivate Sub FileOpened(ByVal sender As Object, ByVal e As EventArgs)Dim jpipViewer As JpipRasterImageViewer = DirectCast(sender, JpipRasterImageViewer)Dim deleteCacheFilePriorTo As DateTime = New DateTime(2008, 8, 8)Debug.WriteLine(Constants.vbLf & " FullImageSize: " & jpipViewer.FullImageSize.ToString())Debug.WriteLine(" NumberOfColorComponents: " & jpipViewer.NumberOfColorComponents.ToString())Debug.WriteLine(" NumberOfResolutions: " & jpipViewer.NumberOfResolutions.ToString())Debug.WriteLine(" InteractiveMode: " & jpipViewer.InteractiveMode.ToString())Debug.WriteLine(" PaintProperties: " & jpipViewer.PaintProperties.ToString())Debug.WriteLine(" current CodeStreamIndex " & jpipViewer.CodeStream)Debug.WriteLine(" NumberOfCodeStreams " & jpipViewer.CodeStreamCount)Debug.WriteLine(" Available Resolutions")Dim i As Integer = 0Do While i < jpipViewer.NumberOfResolutionsDebug.WriteLine(" Resolution (" & i.ToString() & ") Size" & jpipViewer.GetResolutionSize(i).ToString())i += 1LoopDebug.WriteLine(Constants.vbLf & "Open Image")Debug.WriteLine(" CurrentImageSize: " & jpipViewer.CurrentImageSize.ToString())Debug.WriteLine(" ComponentIndex: " & jpipViewer.ComponentIndex.ToString())Debug.WriteLine(" CurrentResolutionIndex: " & jpipViewer.CurrentResolutionIndex.ToString())jpipViewer.ZoomIn()Debug.WriteLine(Constants.vbLf & " Zoomed in")Debug.WriteLine(" CurrentImageSize: " & jpipViewer.CurrentImageSize.ToString())Debug.WriteLine(" ComponentIndex: " & jpipViewer.ComponentIndex.ToString())Debug.WriteLine(" CurrentResolutionIndex: " & jpipViewer.CurrentResolutionIndex.ToString())jpipViewer.ZoomIn()Debug.WriteLine(Constants.vbLf & " Zoomed in")Debug.WriteLine(" CurrentImageSize: " & jpipViewer.CurrentImageSize.ToString())Debug.WriteLine(" ComponentIndex: " & jpipViewer.ComponentIndex.ToString())Debug.WriteLine(" CurrentResolutionIndex: " & jpipViewer.CurrentResolutionIndex.ToString())jpipViewer.ComponentIndex = 0Debug.WriteLine("Component Index value set to 1 ")Debug.WriteLine(" CurrentImageSize: " & jpipViewer.CurrentImageSize.ToString())Debug.WriteLine(" ComponentIndex: " & jpipViewer.ComponentIndex.ToString())Debug.WriteLine(" CurrentResolutionIndex: " & jpipViewer.CurrentResolutionIndex.ToString())jpipViewer.ZoomOut()Debug.WriteLine(Constants.vbLf & " ZoomOut ")Debug.WriteLine(" CurrentImageSize: " & jpipViewer.CurrentImageSize.ToString())Debug.WriteLine(" ComponentIndex: " & jpipViewer.ComponentIndex.ToString())Debug.WriteLine(" CurrentResolutionIndex: " & jpipViewer.CurrentResolutionIndex.ToString())jpipViewer.ComponentIndex = -1Debug.WriteLine("Component Index value set to 1 ")Debug.WriteLine(" CurrentImageSize: " & jpipViewer.CurrentImageSize.ToString())Debug.WriteLine(" ComponentIndex: " & jpipViewer.ComponentIndex.ToString())Debug.WriteLine(" CurrentResolutionIndex: " & jpipViewer.CurrentResolutionIndex.ToString())jpipViewer.Zoom(jpipViewer.GetResolutionSize(2))Debug.WriteLine(" Resolution size set to 2")Debug.WriteLine(" CurrentImageSize: " & jpipViewer.CurrentImageSize.ToString())Debug.WriteLine(" ComponentIndex: " & jpipViewer.ComponentIndex.ToString())Debug.WriteLine(" CurrentResolutionIndex: " & jpipViewer.CurrentResolutionIndex.ToString())SaveJpipViewerImageToFile(jpipViewer, CLIENT_SAVED_FILE_NAME)'Client side function to delete cached files of type LCCACHE File (Not LTCACHE File) prior to given date from CACHE_DIRECTORYDim count As Integer = jpipViewer.DeleteCacheFiles(deleteCacheFilePriorTo)Debug.WriteLine(count.ToString() & " Cache File Deleted....")If jpipViewer.IsActive ThenDebug.WriteLine(" JpipRasterImageViewer.IsActive Test ")Debug.WriteLine(" CurrentImageSize: " & jpipViewer.CurrentImageSize.ToString())End IfjpipViewer.Close()If jpipViewer.IsActive ThenDebug.WriteLine(" JpipRasterImageViewer.IsActive Test (this should not happen becaue no image is loaded at this point")Debug.WriteLine(" CurrentImageSize: " & jpipViewer.CurrentImageSize.ToString())End If'Server sideStopJpipServer()End Sub<TestMethod>Public Sub ClientExample()'Server sideStartJpipServer()'Client requesting enumerated images from serverStartFileEnumerationServer()GetEnumeratedFiles(Path.Combine(LEAD_VARS.ImagesDir, "Client_Enumerated_Images.txt"))StopFileEnumerationServer()'Client requests an image, copies to local file, then deletes cached files prior to given date from CACHE_DIRECTORYDim jpipViewer As JpipRasterImageViewer = New JpipRasterImageViewer()SetJpipViewer(jpipViewer)AddHandler jpipViewer.StreamingError, AddressOf OnClientErrorAddHandler jpipViewer.TotalBytesLoaded, AddressOf OnBytesLoadedAddHandler jpipViewer.FileOpened, AddressOf FileOpenedDebug.WriteLine(Constants.vbLf & " Open File: " & _serverImagesList(0))jpipViewer.Open(_serverImagesList(0))End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
using Leadtools;using Leadtools.Codecs;using Leadtools.Jpip;using Leadtools.Jpip.Client.WinForms;using Leadtools.Jpip.Client.InteractiveDecoder;using Leadtools.Jpip.Server;using Leadtools.Drawing;private const string SERVER_NAME = "LEAD JPIP Server - Test Server";private const int ENUMERATION_SERVER_PORT = 109;private const int JPIP_SERVER_PORT = 107;private const string LOCAL_IP_ADDRESS = "127.0.0.1";private string CLIENT_CACHE_DIRECTORY = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000");private string SERVER_CACHE_DIRECTORY = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000");private string SERVER_IMAGES_FOLDER = Path.Combine(LEAD_VARS.ImagesDir, "jpeg2000");private const string IMAGE_FILE_EXTENSIONS = "*.j2k;*.jp2;*.jpx";private string CLIENT_SAVED_FILE_NAME = Path.Combine(LEAD_VARS.ImagesDir, "test.bmp");private JpipServer _jpipServer;private List<string> _imageFileExtensions;private HttpListener _listener;public List<string> _serverImagesList = new List<string>();public JpipClientExample(){#if LEADTOOLS_V175_OR_LATERLeadtools.Examples.Support.SetLicense();#elseLeadtools.Examples.Support.Unlock();#endif // #if LEADTOOLS_V175_OR_LATER_imageFileExtensions = new List<string>();_jpipServer = new JpipServer();}public void ClientRequestReceived(IAsyncResult ar){HttpListenerContext context;if (null == _listener || !_listener.IsListening){return;}try{context = _listener.EndGetContext(ar);}catch{return;}try{string formattedImages;byte[] sendBuffer;_listener.BeginGetContext(ClientRequestReceived, null);formattedImages = GetFormattedServerImagesString();sendBuffer = Encoding.ASCII.GetBytes(formattedImages);context.Response.OutputStream.Write(sendBuffer, 0, sendBuffer.Length);context.Response.Close();}catch (Exception){if (null != context){context.Response.Close();}}}public string GetFormattedServerImagesString(){string serverImageFile;string formattedServerImagesString = string.Empty;List<string> searchImages = new List<string>();List<string> serverImages = new List<string>();foreach (string extension in _imageFileExtensions){searchImages.AddRange(Directory.GetFiles(_jpipServer.Configuration.ImagesFolder,extension,SearchOption.AllDirectories));}foreach (string file in searchImages){serverImageFile = file.Replace(_jpipServer.Configuration.ImagesFolder,string.Empty);serverImageFile = serverImageFile.TrimStart('\\');formattedServerImagesString += serverImageFile + ";";}searchImages.Clear();foreach (KeyValuePair<string, string> aliasFolder in _jpipServer.Configuration.AliasFolders){if (!Directory.Exists(aliasFolder.Value)){continue;}foreach (string extension in _imageFileExtensions){searchImages.AddRange(Directory.GetFiles(aliasFolder.Value,extension,SearchOption.AllDirectories));}foreach (string imageFile in searchImages){serverImageFile = imageFile.Replace(aliasFolder.Value, aliasFolder.Key);serverImageFile = serverImageFile.TrimStart('\\');formattedServerImagesString += serverImageFile + ";";}searchImages.Clear();}return formattedServerImagesString.TrimEnd(';');}public void StartFileEnumerationServer(){try{_imageFileExtensions.Clear();_imageFileExtensions.AddRange(IMAGE_FILE_EXTENSIONS.Split(';'));if (_listener != null)//if _listner is already created, then do not create againreturn;_listener = new HttpListener ( ) ;_listener.Prefixes.Add ( string.Format ( "http://{0}:{1}/", LOCAL_IP_ADDRESS, ENUMERATION_SERVER_PORT ) ) ;_listener.Start ( ) ;_listener.BeginGetContext ( ClientRequestReceived, null ) ;}catch (Exception ex){Debug.Fail("Error in server enumeration: \n" + ex.Message);}}public void StopFileEnumerationServer(){try{if (_listener != null)_listener.Stop();}catch (Exception ex){Debug.Fail("Error in server enumeration: \n" + ex.Message);}}public void GetEnumeratedFiles(string filename){HttpWebRequest request = ( HttpWebRequest ) HttpWebRequest.Create ( string.Format ( "http://{0}:{1}/", LOCAL_IP_ADDRESS, ENUMERATION_SERVER_PORT ) ) ;if (null != request.Proxy){request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;}request.UseDefaultCredentials = true;HttpWebResponse response = (HttpWebResponse)request.GetResponse();System.IO.Stream receivedStream = response.GetResponseStream();System.IO.StreamReader reader = new System.IO.StreamReader(receivedStream);Char[] read = new Char[256];// Reads 256 characters at a time.int count = reader.Read(read, 0, 256);string imageNames = "";while (count > 0){// Dumps the 256 characters on a string and displays the string to the console.String temp = new String(read, 0, count);imageNames += temp;count = reader.Read(read, 0, 256);}// Releases the resources of the response.response.Close();// Releases the resources of the Stream.reader.Close();string[] imageFileNames = imageNames.Split(';');int counter = 0;foreach (string image in imageFileNames){counter++;Debug.Assert(image.Trim().Length > 0, "There is no image to enumerate");Debug.WriteLine("Image " + counter + ": " + image);_serverImagesList.Add(image);}File.WriteAllLines(filename, _serverImagesList.ToArray());}public void StartJpipServer(){if (!_jpipServer.IsRunning){//Server Settings_jpipServer.Configuration.ServerName = SERVER_NAME;_jpipServer.Configuration.IPAddress = LOCAL_IP_ADDRESS;_jpipServer.Configuration.Port = JPIP_SERVER_PORT;_jpipServer.Configuration.ImagesFolder = SERVER_IMAGES_FOLDER;_jpipServer.Configuration.CacheFolder = SERVER_CACHE_DIRECTORY;_jpipServer.Configuration.MaxServerBandwidth = _jpipServer.Configuration.MaxServerBandwidth;_jpipServer.Configuration.CacheSize = 200;_jpipServer.Configuration.DivideSuperBoxes = true;_jpipServer.Configuration.ChunkSize = 512;_jpipServer.Configuration.MaxClientCount = 5;_jpipServer.Configuration.ConnectionIdleTimeout = new TimeSpan(0, 0, 9100);_jpipServer.Configuration.MaxSessionLifetime = new TimeSpan(0, 0, 9900);_jpipServer.Configuration.MaxConnectionBandwidth = _jpipServer.Configuration.MaxConnectionBandwidth;//Communication Settings_jpipServer.Configuration.MaxTransportConnections = 15;_jpipServer.Configuration.HandshakeTimeout = new TimeSpan(0, 0, 9600);_jpipServer.Configuration.RequestTimeout = new TimeSpan(0, 0, 920);_jpipServer.Configuration.ChunkSize = 512;//Images Settings_jpipServer.Configuration.ImageParsingTimeout = new TimeSpan(0, 0, 9180);_jpipServer.Configuration.PartitionBoxSize = 40;_jpipServer.Configuration.DivideSuperBoxes = true;//Logging Settings_jpipServer.Configuration.LogInformation = false;_jpipServer.Configuration.LogWarnings = false;_jpipServer.Configuration.LogDebug = false;_jpipServer.Configuration.LogErrors = false;//Start server and delegates_jpipServer.Start();Debug.Assert(_jpipServer.IsRunning, "Server did not start.");}}public void StopJpipServer(){if (_jpipServer.IsRunning)_jpipServer.Stop();}public void SetJpipViewer(JpipRasterImageViewer viewer){// Initialize JPIP viewerviewer.CacheDirectoryName = CLIENT_CACHE_DIRECTORY;viewer.PortNumber = JPIP_SERVER_PORT;viewer.IPAddress = LOCAL_IP_ADDRESS;viewer.PacketSize = 16384;viewer.RequestTimeout = new TimeSpan(0, 1, 0);viewer.ChannelType = JpipChannelTypes.HttpChannel;}public void SaveJpipViewerImageToFile(JpipRasterImageViewer viewer, string fileName){RasterCodecs rc = new Leadtools.Codecs.RasterCodecs();rc.Save(viewer.Image, fileName, RasterImageFormat.Bmp, 24);}private void OnClientError(object sender, ErrorEventArgs e){Debug.WriteLine(e.GetException().Message);}private void OnBytesLoaded(object sender, TotalBytesLoadedEventArgs e){Debug.WriteLine(" Total Bytes: " + e.ByteCount.ToString());}[TestMethod]public void ClientExample(){/*Server side*/StartJpipServer();/*Client requesting enumerated images from server*/StartFileEnumerationServer();GetEnumeratedFiles(Path.Combine(LEAD_VARS.ImagesDir, "Client_Enumerated_Images.txt"));StopFileEnumerationServer();JpipRasterImageViewer jpipViewer = new JpipRasterImageViewer();SetJpipViewer(jpipViewer);jpipViewer.StreamingError += OnClientError;jpipViewer.TotalBytesLoaded += OnBytesLoaded;jpipViewer.FileOpened += new EventHandler(jpipViewer_FileOpened);Debug.WriteLine("\n Open File: " + _serverImagesList[0] );jpipViewer.Open(_serverImagesList[0]);}void jpipViewer_FileOpened(object sender, EventArgs e){JpipRasterImageViewer jpipViewer = ( JpipRasterImageViewer) sender ;/*Client requests an image, copies to local file, then deletes cached files prior to given date from CACHE_DIRECTORY*/DateTime deleteCacheFilePriorTo = new DateTime(2008, 8, 8);Debug.WriteLine("\n FullImageSize: " + jpipViewer.FullImageSize.ToString());Debug.WriteLine(" NumberOfColorComponents: " + jpipViewer.NumberOfColorComponents.ToString());Debug.WriteLine(" NumberOfResolutions: " + jpipViewer.NumberOfResolutions.ToString());Debug.WriteLine(" InteractiveMode: " + jpipViewer.InteractiveMode.ToString());Debug.WriteLine(" PaintProperties: " + jpipViewer.PaintProperties.ToString());Debug.WriteLine(" current CodeStreamIndex " + jpipViewer.CodeStream );Debug.WriteLine(" NumberOfCodeStreams " + jpipViewer.CodeStreamCount ) ;Debug.WriteLine(" Available Resolutions");for (int i = 0; i < jpipViewer.NumberOfResolutions; i++){Debug.WriteLine(" Resolution (" + i.ToString() + ") Size" + jpipViewer.GetResolutionSize(i).ToString());}Debug.WriteLine("\nOpen Image");Debug.WriteLine(" CurrentImageSize: " + jpipViewer.CurrentImageSize.ToString());Debug.WriteLine(" ComponentIndex: " + jpipViewer.ComponentIndex.ToString());Debug.WriteLine(" CurrentResolutionIndex: " + jpipViewer.CurrentResolutionIndex.ToString());jpipViewer.ZoomIn();Debug.WriteLine("\n Zoomed in");Debug.WriteLine(" CurrentImageSize: " + jpipViewer.CurrentImageSize.ToString());Debug.WriteLine(" ComponentIndex: " + jpipViewer.ComponentIndex.ToString());Debug.WriteLine(" CurrentResolutionIndex: " + jpipViewer.CurrentResolutionIndex.ToString());jpipViewer.ZoomIn();Debug.WriteLine("\n Zoomed in");Debug.WriteLine(" CurrentImageSize: " + jpipViewer.CurrentImageSize.ToString());Debug.WriteLine(" ComponentIndex: " + jpipViewer.ComponentIndex.ToString());Debug.WriteLine(" CurrentResolutionIndex: " + jpipViewer.CurrentResolutionIndex.ToString());jpipViewer.ComponentIndex = 0;Debug.WriteLine("Component Index value set to 1 ");Debug.WriteLine(" CurrentImageSize: " + jpipViewer.CurrentImageSize.ToString());Debug.WriteLine(" ComponentIndex: " + jpipViewer.ComponentIndex.ToString());Debug.WriteLine(" CurrentResolutionIndex: " + jpipViewer.CurrentResolutionIndex.ToString());jpipViewer.ZoomOut();Debug.WriteLine("\n ZoomOut ");Debug.WriteLine(" CurrentImageSize: " + jpipViewer.CurrentImageSize.ToString());Debug.WriteLine(" ComponentIndex: " + jpipViewer.ComponentIndex.ToString());Debug.WriteLine(" CurrentResolutionIndex: " + jpipViewer.CurrentResolutionIndex.ToString());jpipViewer.ComponentIndex = -1;Debug.WriteLine("Component Index value set to 1 ");Debug.WriteLine(" CurrentImageSize: " + jpipViewer.CurrentImageSize.ToString());Debug.WriteLine(" ComponentIndex: " + jpipViewer.ComponentIndex.ToString());Debug.WriteLine(" CurrentResolutionIndex: " + jpipViewer.CurrentResolutionIndex.ToString());jpipViewer.Zoom(jpipViewer.GetResolutionSize(2));Debug.WriteLine(" Resolution size set to 2");Debug.WriteLine(" CurrentImageSize: " + jpipViewer.CurrentImageSize.ToString());Debug.WriteLine(" ComponentIndex: " + jpipViewer.ComponentIndex.ToString());Debug.WriteLine(" CurrentResolutionIndex: " + jpipViewer.CurrentResolutionIndex.ToString());SaveJpipViewerImageToFile(jpipViewer, CLIENT_SAVED_FILE_NAME );/*Client side function to delete cached files of type LCCACHE File (Not LTCACHE File) prior to given date from CACHE_DIRECTORY*/int count = jpipViewer.DeleteCacheFiles(deleteCacheFilePriorTo);Debug.WriteLine(count.ToString() + " Cache File Deleted....");if (jpipViewer.IsActive){Debug.WriteLine(" JpipRasterImageViewer.IsActive Test ");Debug.WriteLine(" CurrentImageSize: " + jpipViewer.CurrentImageSize.ToString());}jpipViewer.Close();if (jpipViewer.IsActive){Debug.WriteLine(" JpipRasterImageViewer.IsActive Test (this should not happen becaue no image is loaded at this point");Debug.WriteLine(" CurrentImageSize: " + jpipViewer.CurrentImageSize.ToString());}/*Server side*/StopJpipServer();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
|
Products |
Support |
Feedback: JpipRasterImageViewer Class - Leadtools.Jpip.Client.WinForms |
Introduction |
Help Version 19.0.2017.3.22
|

Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.