# Transparent GeoImages

**URL:** <https://community.thinkgeo.com/t/transparent-geoimages/1751>\
**Category:** WinForms\
**Created:** [July 1, 2011, 12:57am UTC](https://community.thinkgeo.com/t/transparent-geoimages/1751 "2011-07-01T00:57:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul2](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/paul2/32/24982_2.png) [@Paul2](https://community.thinkgeo.com/u/Paul2)\
**Post date:** [July 1, 2011, 12:57am UTC](https://community.thinkgeo.com/t/transparent-geoimages/1751/1 "2011-07-01T00:57:27Z")

</div>

&nbsp;We&nbsp;are&nbsp;trying&nbsp;to&nbsp;use&nbsp;transparent&nbsp;icons&nbsp;as&nbsp;GeoImages&nbsp;in&nbsp;ValueStyles.&nbsp;Bascially,&nbsp;we&nbsp;have&nbsp;a&nbsp;set&nbsp;of&nbsp;icons&nbsp;that,&nbsp;based&nbsp;on&nbsp;a&nbsp;ValueStyle,&nbsp;we&nbsp;want&nbsp;to&nbsp;display.&nbsp;When&nbsp;constructing&nbsp;the&nbsp;ValueStyle,&nbsp;we&nbsp;want&nbsp;to&nbsp;set&nbsp;a&nbsp;transparent&nbsp;color&nbsp;on&nbsp;the&nbsp;image,&nbsp;like&nbsp;this&nbsp;thread:&nbsp;[gis.thinkgeo.com/Support/Dis...fault.aspx](http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/6753/afv/topic/Default.aspx)

The&nbsp;sample&nbsp;code&nbsp;in&nbsp;that&nbsp;thread&nbsp;doesn't&nbsp;dispose&nbsp;of&nbsp;the&nbsp;stream,&nbsp;and&nbsp;if&nbsp;the&nbsp;stream&nbsp;is&nbsp;disposed,&nbsp;the&nbsp;icons&nbsp;do&nbsp;not&nbsp;show&nbsp;up.&nbsp;When&nbsp;using&nbsp;a&nbsp;large&nbsp;number&nbsp;of&nbsp;GeoImages,&nbsp;memory&nbsp;consumption&nbsp;grows&nbsp;until&nbsp;the&nbsp;application&nbsp;crashes&nbsp;with&nbsp;an&nbsp;OutOfMemory&nbsp;exception.

Any&nbsp;suggestions&nbsp;on&nbsp;how&nbsp;to&nbsp;construct&nbsp;a&nbsp;GeoImage&nbsp;from&nbsp;a&nbsp;MemoryStream&nbsp;and&nbsp;then&nbsp;dispose&nbsp;of&nbsp;the&nbsp;stream?

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [July 1, 2011, 1:26pm UTC](https://community.thinkgeo.com/t/transparent-geoimages/1751/2 "2011-07-01T13:26:51Z")

</div>

Paul,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;question!&nbsp;  
&nbsp;&nbsp;  
&nbsp;Actually,&nbsp;if&nbsp;you&nbsp;dispose&nbsp;the&nbsp;geoimage’s&nbsp;stream&nbsp;obviously&nbsp;it&nbsp;would&nbsp;dispose&nbsp;the&nbsp;associate&nbsp;images&nbsp;also.&nbsp;For&nbsp;this&nbsp;issue&nbsp;I&nbsp;really&nbsp;don’t&nbsp;have&nbsp;any&nbsp;good&nbsp;solution&nbsp;for&nbsp;you,&nbsp;the&nbsp;stream&nbsp;is&nbsp;associated&nbsp;to&nbsp;the&nbsp;GeoImage&nbsp;object,&nbsp;if&nbsp;you&nbsp;dispose&nbsp;the&nbsp;stream,&nbsp;obviously&nbsp;the&nbsp;image&nbsp;would&nbsp;be&nbsp;dispose&nbsp;also.&nbsp;So&nbsp;if&nbsp;you&nbsp;have&nbsp;a&nbsp;large&nbsp;number&nbsp;fo&nbsp;GeoImages&nbsp;need&nbsp;to&nbsp;display,&nbsp;I&nbsp;suggest&nbsp;to&nbsp;draw&nbsp;a&nbsp;part&nbsp;of&nbsp;the&nbsp;geoimages&nbsp;first&nbsp;them&nbsp;dispose&nbsp;them&nbsp;and&nbsp;draw&nbsp;the&nbsp;other&nbsp;GeoImages&nbsp;then.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Scott,

---

<div class="post-metadata">

**Author:** ![Paul2](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/paul2/32/24982_2.png) [@Paul2](https://community.thinkgeo.com/u/Paul2)\
**Post date:** [July 1, 2011, 1:35pm UTC](https://community.thinkgeo.com/t/transparent-geoimages/1751/3 "2011-07-01T13:35:59Z")

</div>

I&nbsp;did&nbsp;some&nbsp;additional&nbsp;testing&nbsp;this&nbsp;morning.&nbsp;It&nbsp;doesn’t&nbsp;look&nbsp;like&nbsp;it&nbsp;is&nbsp;related&nbsp;to&nbsp;the&nbsp;number&nbsp;of&nbsp;streams&nbsp;after&nbsp;all.&nbsp;  
&nbsp;&nbsp;  
&nbsp;If&nbsp;I&nbsp;add&nbsp;1000&nbsp;Features&nbsp;to&nbsp;the&nbsp;InMemoryFeatureLayer,&nbsp;all&nbsp;with&nbsp;the&nbsp;same&nbsp;value&nbsp;in&nbsp;the&nbsp;FeatureColumn&nbsp;that&nbsp;points&nbsp;to&nbsp;my&nbsp;ValueStyle&nbsp;with&nbsp;my&nbsp;one&nbsp;GeoImage,&nbsp;I&nbsp;can&nbsp;watch&nbsp;memory&nbsp;consumption&nbsp;of&nbsp;the&nbsp;application&nbsp;grow&nbsp;to&nbsp;nearly&nbsp;1GB.&nbsp;The&nbsp;image&nbsp;file&nbsp;pointed&nbsp;to&nbsp;be&nbsp;the&nbsp;stream&nbsp;used&nbsp;by&nbsp;the&nbsp;GeoImage&nbsp;is&nbsp;only&nbsp;1K.&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;don’t&nbsp;see&nbsp;anywhere&nbsp;else&nbsp;along&nbsp;this&nbsp;code&nbsp;path&nbsp;that&nbsp;I&nbsp;could&nbsp;be&nbsp;consuming&nbsp;large&nbsp;amounts&nbsp;of&nbsp;memory.&nbsp;When&nbsp;the&nbsp;OutOfMemory&nbsp;exception&nbsp;occurs,&nbsp;this&nbsp;is&nbsp;the&nbsp;stack:&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;System.OutOfMemoryException:&nbsp;Out&nbsp;of&nbsp;memory.&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Drawing.Graphics.CheckErrorStatus(Int32&nbsp;status)&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Drawing.Graphics.DrawImage(Image&nbsp;image,&nbsp;Int32&nbsp;x,&nbsp;Int32&nbsp;y)&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;System.Drawing.Graphics.DrawImageUnscaled(Image&nbsp;image,&nbsp;Int32&nbsp;x,&nbsp;Int32&nbsp;y)&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.WinformsMap.NRY=(Graphics&nbsp;NhY=,&nbsp;RectangleShape&nbsp;NxY=)&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.WinformsMap.3xU=(Boolean&nbsp;4BU=,&nbsp;RectangleShape&nbsp;4RU=)&nbsp;  
&nbsp;&nbsp;&nbsp;&nbsp;at&nbsp;ThinkGeo.MapSuite.DesktopEdition.WinformsMap.3RU=(RectangleShape&nbsp;3hU=)&nbsp;  
&nbsp;&nbsp;  
&nbsp;Any&nbsp;thoughts?

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [July 4, 2011, 10:48am UTC](https://community.thinkgeo.com/t/transparent-geoimages/1751/4 "2011-07-04T10:48:27Z")

</div>

&nbsp;Hi&nbsp;Paul,

&nbsp;

I&nbsp;created&nbsp;a&nbsp;sample&nbsp;that&nbsp;wants&nbsp;to&nbsp;reproduce&nbsp;your&nbsp;problem&nbsp;but&nbsp;with&nbsp;no&nbsp;luck,&nbsp;the&nbsp;memory&nbsp;usage&nbsp;is&nbsp;not&nbsp;increased,&nbsp;could&nbsp;you&nbsp;look&nbsp;at&nbsp;it?

`            Bitmap bitmap = new Bitmap(@"..\..\SampleData\Data\United States.png");            bitmap.MakeTransparent(Color.Black);            MemoryStream stream = new MemoryStream();            bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);            GeoImage geoimage = new GeoImage(stream);            InMemoryFeatureLayer bitmapLayer = new InMemoryFeatureLayer();            bitmapLayer.Open();            bitmapLayer.Columns.Add(new FeatureSourceColumn("key"));            bitmapLayer.Close();            PointStyle pointStyle = new PointStyle(geoimage);            ValueStyle valueStyle = new ValueStyle();            valueStyle.ColumnName = "key";            valueStyle.ValueItems.Add(new ValueItem("value", pointStyle));            bitmapLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);            bitmapLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;            byte[] wkb = new PointShape(-95.2806, 38.9554).GetWellKnownBinary();            for (int i = 0; i < 1000; i++)            {                Feature feature = new Feature(wkb, Guid.NewGuid().ToString(), new string[] { "key:value" });                bitmapLayer.InternalFeatures.Add(Guid.NewGuid().ToString(), feature);            }            LayerOverlay overlay = new LayerOverlay();            overlay.Layers.Add(bitmapLayer);            winformsMap1.Overlays.Add(overlay);            winformsMap1.CurrentExtent = new RectangleShape(-165.946875, 86.4359375, -35.86875, -6.3765625);            winformsMap1.Refresh();`

Thanks,

&nbsp;

James
