IImageService.ImageBuffer property
Applies To: IImageService
Image buffer is an array of bytes used for saving the requested image.
[Visual Basic 6.0]
object.ImageBuffer = [ value ]
Access
Read / Write
Type
Integer
Requirements
Platform |
32 bit Windows OS (WinXP) |
Environment |
.NET Framework, COM, ANSI C / C++ Standard compliant |
Dependency |
ESRI.ImageServer.ISClient.dll (.NET Framework), ISClient.dll (COM/C++), ISClientC.dll (C/C++) |
Include |
isclientc.h (ANSI C) |
Example
[Visual Basic 6.0]
‘ See the ISViewer sample code For more details
‘ The client has been instantiated And initialized successfully
‘ The service has been opened As Object theService
‘ theService.SetImageInfo has been called To Set the image dimensions
Dim myImageBuffer() As Byte ' Byte array to store returned image
Dim bufferSize As Long ‘ Size of the image buffer
Dim isImageCreated As Boolean
‘ determine the size of the buffer needed To store the requested image
bufferSize = theService.GetRecommendedBufferSize( )
' Resize the buffer to the recommended size
ReDim myImageBuffer (bufferSize)
' The address of myImageBuffer is stored in the service object
theService.ImageBuffer = VarPtr(myImageBuffer(0))
‘Extract the requested image, store In myImageBuffer
isImageCreated = theService.GetImageByExtent
‘At this point myImageBuffer contains the image values
[Visual C++ 2005]
// See the sample code C_ClientTest_Sample for more details
//
// ISClient_Export.h and ISClient_Export.c define access routines
//
// The client will have been instantiated and initialized successfully using
// IS_CO_Create() and IS_CO_Init()
//
// The image service will have been opened as theService using
// IS_CO_OpenImageService
//
// The image dimensions will have been set using
// IS_IService_SetImageInfo
//
// Buffer and buffer size for the image
unsigned char* myImageBuffer = 0;
long bufferSize = 0;
// determine the size of the buffer needed to store the requested image
bufferSize = IS_IService_BufferSize(theService);
// Allocate enough memory for the buffer
myImageBuffer = (unsigned char*)malloc(bufferSize);
// The address of buffer is stored in the service object, cast as an int
IS_IService_PutImageBuffer(theService, (int)(myImageBuffer));
// Extract the requested image, store in myImageBuffer
int result = IS_IService_ImageByExtent(theService);
// At this point myImageBuffer contains the image values, if result != 0
[C# .NET]
// Instantiate and initialize the client connection
ESRI.ImageServer.ISClient.IClientObject clientConn = new
ESRI.ImageServer.ISClient.CClientObjectClass();
if (!clientConn.Init(""))
{
Console.WriteLine("Error code: " + clientConn.Status);
clientConn.Close(); return;
}
// Use the connection object to open an Image Service
ESRI.ImageServer.ISClient.IImageService theService =
clientConn.OpenImageService("ImageService://isServer/someService", "");
if (theService == null)
{
Console.WriteLine("Error: " + clientConn.Status);
clientConn.Close(); return;
}
// Set image extents. First four are doubles, others are integers
// These values would have been previously determined
theService.SetImageInfo(xMin, yMin, xMax, yMax, cols, rows);
// Get the required buffer size, create a new image buffer
int bufferSize = theService.GetRecommendedBufferSize();
byte[] myImageBuffer = new byte[bufferSize];
// Provide a means for accessing a managed object as unmanaged memory.
// This is defined in System.Runtime.InteropServices
GCHandle gcH;
// Allocate a handle of the specified type for the specified object
// The pinned GC Handle prevents the garbage collector from moving the object.
// Use the free method to free the handle when it is no longer needed.
gcH = GCHandle.Alloc(myImageBuffer, GCHandleType.Pinned);
if (!gcH.IsAllocated) return; // error if allocation fails
// Convert the handle to integer, which is what theService is expecting
int bufAddress = gcH.AddrOfPinnedObject().ToInt32();
if (bufAddress == 0)
{
if (gcH.IsAllocated) gcH.Free(); return;
}
// Now the buffer address can be stored in theService
theService.ImageBuffer = bufAddress;
// A call to GetImageByExtent fills the buffer with imagery
if (!theService.GetImageByExtent())
{
// error condition. Free garbage collection handle and return
if (gcH.IsAllocated) gcH.Free(); return;
}
// myImageBuffer now has the imagery data. Do whatever is desired with it
// when finished, release the garbage collection handle
if (gcH.IsAllocated) gcH.Free();
[VB .NET]
‘assign configuration file and service name to appropriate strings
‘Establish client connection
Dim client as new ImageServerClient.CClientObject
if client.Init(ISCConfigConfigPath) = false Then
MsgBox(client.Status, vbCritical)
goto ErrHandler
End if
‘Open the image service by name
Dim theService as new ImageServerClient.CImageService
theService = client.OpenImageService(ImageServiceFileName, "")
if theService is Nothing Then
MsgBox(client.Status, vbCritical)
goto ErrHandler
End if
‘Define the image to be returned. Parameters set previously
‘ first four parameters are Doubles, last two are Integers
Dim setInfo as Boolean
setInfo = theService.SetImageInfo(Xmin, Ymin, Xmax, Ymax, Cols, Rows)
if setInfo = false Then
MsgBox(client.Status, vbInformation)
goto ErrHandler
End if
‘create a buffer of the appropriate size
Dim bufferSize as Integer
bufferSize = theService.GetRecommendedBufferSize()
Dim myImageBuffer() as byte
ReDim myImageBuffer(bufferSize)
‘set up handle to allow managed memory to be used as unmanaged memory
Dim gcHandle as System.Runtime.InteropServices.GCHandle
gcHandle = System.Runtime.InteropServices.GCHandle.Alloc(myImageBuffer, _
Runtime.InteropServices.GCHandleType.Pinned)
‘copy address to Int32 variable, which is what theService expects
Dim bufAddress as Int32
bufAddress = gcHandle.AddrOfPinnedObject.ToInt32
‘now the address of the image buffer can be stored in theService theService.ImageBuffer = bufAddress
‘fill the buffer with the GetImageByExtent method
if (Not theService.GetImageByExtent()) Then
MsgBox("Failed to get image")
goto ErrHandler
End if
‘use the image data.
‘When finished, free up the garbage collector handle
gcHandle.Free()
For a detailed example, please see the ISViewer Sample in VB 6.0 or the Client Application Sample in ANSI C in [ArcGIS Image Server installation folder]\Developer Kit\Client Applications\Samples\ folder.
Related Topics
See also: GetImageByExtent