[mapguide-users] RenderMap: MgOutOfMemoryException

frieda ruslankutowoj at web.de
Mon Aug 24 07:59:23 PDT 2020


Hello I'm using MapGuide v.2.5.2.7949 in an ASP.NET Application.

I'm facing an out of memory exception throwed by this function (RenderMap):

http://cmnmaps.ca/mapguide/help/webapi/de/dbd/class_mg_rendering_service_a7767628fe456bfd90e9010a19ed83e04.htm#a7767628fe456bfd90e9010a19ed83e04

In my App I'm trying to print the map to a PNG format and if I set 600 DPI I
get the exception. What's wrong here? If I set lower DPI, like 300 it works
fine.

My Code:

<CLSCompliant(False)> Public Sub InitializeMapImage(ByRef pr_objMapGuide As
MapGuide, ByVal pv_Plotbox As MgEnvelope,
                                        ByVal pv_dblPageWidth As Double,
ByVal pv_dblPageHeight As Double, Optional ByVal pv_strFormat As String =
"PNG")
        Try
            Dim Map As MgMap = pr_objMapGuide.Map

            Dim selection As New MgSelection()
            selection.Save(pr_objMapGuide.ResourceService, Map.Name)
            selection.Open(pr_objMapGuide.ResourceService, Map.Name)
            Dim SelXML As String = selection.ToXml
            Dim white As New MgColor(255, 255, 255)

            Dim pxMapWidth As Double = (pv_dblPageWidth / inch) * DPI
            Dim pxMapHeight As Double = (pv_dblPageHeight / inch) * DPI

            Dim byteReader As MgByteReader =
pr_objMapGuide.RenderingService.RenderMap(Map, selection, pv_Plotbox,
pxMapWidth, pxMapHeight, white, "PNG")
            Dim memBuff As New IO.MemoryStream
            Dim byteBuffer(1024 ^ 2) As Byte
            Dim intBytes As Integer = byteReader.Read(byteBuffer, 1024 ^ 2)
            While intBytes > 0
                memBuff.Write(byteBuffer, 0, intBytes)
                intBytes = byteReader.Read(byteBuffer, 1024 ^ 2)
            End While

            Dim BitMap As New Drawing.Bitmap(memBuff)
            BitMap.SetResolution(Convert.ToSingle(DPI),
Convert.ToSingle(DPI))
            Dim imgMap As Image = BitMap

            m_Map = imgMap
        Catch exRange As MgOutOfRangeException
            Throw New Exception("", exRange)
        Catch exMemory As MgOutOfMemoryException
            Throw New Exception("", exMemory)
        Catch ex As Exception
            Throw New Exception("", ex)
        End Try
    End Sub




--
Sent from: http://osgeo-org.1560.x6.nabble.com/MapGuide-Users-f4182607.html


More information about the mapguide-users mailing list