# Loading images... 101

**URL:** <https://community.thinkgeo.com/t/loading-images-101/7147>\
**Category:** Services\
**Created:** [June 29, 2010, 2:45pm UTC](https://community.thinkgeo.com/t/loading-images-101/7147 "2010-06-29T14:45:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ted](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@Ted](https://community.thinkgeo.com/u/Ted)\
**Post date:** [June 29, 2010, 2:45pm UTC](https://community.thinkgeo.com/t/loading-images-101/7147/1 "2010-06-29T14:45:35Z")

</div>

Ok...&nbsp;we&nbsp;have&nbsp;finally&nbsp;gotten&nbsp;to&nbsp;the&nbsp;point&nbsp;where&nbsp;we&nbsp;are&nbsp;ready&nbsp;to&nbsp;load&nbsp;raster&nbsp;images&nbsp;from&nbsp;our&nbsp;database.&nbsp;&nbsp;&nbsp;We&nbsp;have&nbsp;these&nbsp;stored&nbsp;as&nbsp;blobs,&nbsp;and&nbsp;can&nbsp;readily&nbsp;turn&nbsp;them&nbsp;into&nbsp;binary&nbsp;streams.&nbsp;&nbsp;&nbsp;&nbsp;But&nbsp;I'm&nbsp;at&nbsp;a&nbsp;bit&nbsp;of&nbsp;a&nbsp;loss&nbsp;on&nbsp;how&nbsp;to&nbsp;proceed,&nbsp;depending&nbsp;upon&nbsp;the&nbsp;type&nbsp;of&nbsp;imagery.

We&nbsp;have&nbsp;some&nbsp;images&nbsp;that&nbsp;are&nbsp;small&nbsp;.bmp&nbsp;or&nbsp;.png&nbsp;images,&nbsp;with&nbsp;world&nbsp;files.&nbsp;&nbsp;&nbsp;I&nbsp;can&nbsp;create&nbsp;a&nbsp;stream&nbsp;for&nbsp;the&nbsp;image&nbsp;portion,&nbsp;and&nbsp;I&nbsp;know&nbsp;the&nbsp;world&nbsp;file&nbsp;(or&nbsp;bounding&nbsp;box)&nbsp;information.&nbsp;&nbsp;&nbsp;&nbsp;Looks&nbsp;like&nbsp;I&nbsp;create&nbsp;a&nbsp;GDIPlusRasterSource&nbsp;and&nbsp;provide&nbsp;the&nbsp;stream&nbsp;on&nbsp;the&nbsp;StreamLoading&nbsp;event?&nbsp;&nbsp;&nbsp;But,&nbsp;will&nbsp;I&nbsp;get&nbsp;the&nbsp;loading&nbsp;event&nbsp;twice...&nbsp;once&nbsp;for&nbsp;the&nbsp;image&nbsp;and&nbsp;once&nbsp;for&nbsp;the&nbsp;world&nbsp;file?&nbsp;&nbsp;&nbsp;Or&nbsp;do&nbsp;I&nbsp;need&nbsp;to&nbsp;set&nbsp;the&nbsp;image&nbsp;extent&nbsp;in&nbsp;the&nbsp;constructor.&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;the&nbsp;latter,&nbsp;do&nbsp;you&nbsp;treat&nbsp;the&nbsp;image&nbsp;extent&nbsp;as&nbsp;the&nbsp;outer&nbsp;edge&nbsp;of&nbsp;the&nbsp;pixel&nbsp;(as&nbsp;would&nbsp;be&nbsp;implied),&nbsp;or&nbsp;the&nbsp;center&nbsp;of&nbsp;the&nbsp;pixel,&nbsp;as&nbsp;defined&nbsp;in&nbsp;the&nbsp;world&nbsp;file&nbsp;spec?

Then,&nbsp;we&nbsp;also&nbsp;have&nbsp;some&nbsp;imagery&nbsp;that&nbsp;is&nbsp;ECW,&nbsp;JPG2000,&nbsp;and&nbsp;SID.&nbsp;&nbsp;&nbsp;These&nbsp;have&nbsp;embedded&nbsp;georeferencing.&nbsp;&nbsp;However,&nbsp;I&nbsp;don't&nbsp;see&nbsp;a&nbsp;StreamLoading&nbsp;event&nbsp;on&nbsp;the&nbsp;matching&nbsp;raster&nbsp;data&nbsp;source&nbsp;objects.&nbsp;&nbsp;&nbsp;&nbsp;To&nbsp;load&nbsp;this&nbsp;imagery,&nbsp;will&nbsp;I&nbsp;need&nbsp;to&nbsp;write&nbsp;the&nbsp;data&nbsp;I&nbsp;extract&nbsp;from&nbsp;our&nbsp;database&nbsp;out&nbsp;to&nbsp;a&nbsp;temp&nbsp;file?

I've&nbsp;searched&nbsp;on&nbsp;StreamLoading,&nbsp;and&nbsp;did&nbsp;not&nbsp;find&nbsp;any&nbsp;answer&nbsp;to&nbsp;these&nbsp;questions.&nbsp;&nbsp;&nbsp;And&nbsp;the&nbsp;HowDoI&nbsp;samples&nbsp;don't&nbsp;show&nbsp;loading&nbsp;anything&nbsp;from&nbsp;a&nbsp;stream.&nbsp;&nbsp;&nbsp;I'll&nbsp;be&nbsp;glad&nbsp;to&nbsp;look&nbsp;in&nbsp;other&nbsp;locations&nbsp;for&nbsp;documentation,&nbsp;if&nbsp;you&nbsp;can&nbsp;give&nbsp;me&nbsp;a&nbsp;nudge.

Thanks!

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [June 30, 2010, 12:29am UTC](https://community.thinkgeo.com/t/loading-images-101/7147/2 "2010-06-30T00:29:12Z")

</div>

Ted,&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;good&nbsp;news&nbsp;and&nbsp;bad&nbsp;news&nbsp;is&nbsp;that&nbsp;the&nbsp;streaming&nbsp;works&nbsp;well&nbsp;for&nbsp;all&nbsp;types&nbsp;except&nbsp;MrSid&nbsp;&&nbsp;ECW.&nbsp;&nbsp;The&nbsp;reason&nbsp;is&nbsp;that&nbsp;the&nbsp;libraries&nbsp;the&nbsp;vendors&nbsp;provide&nbsp;us&nbsp;do&nbsp;not&nbsp;have&nbsp;a&nbsp;way&nbsp;to&nbsp;load&nbsp;from&nbsp;a&nbsp;stream.&nbsp;&nbsp;Their&nbsp;API&nbsp;requires&nbsp;a&nbsp;filename&nbsp;so&nbsp;I&nbsp;think&nbsp;in&nbsp;that&nbsp;case&nbsp;you&nbsp;need&nbsp;to&nbsp;write&nbsp;it&nbsp;out&nbsp;to&nbsp;a&nbsp;temp&nbsp;file.&nbsp;  
&nbsp;&nbsp;  
&nbsp;When&nbsp;you&nbsp;set&nbsp;the&nbsp;path&nbsp;and&nbsp;file&nbsp;name&nbsp;for&nbsp;the&nbsp;image&nbsp;file&nbsp;you&nbsp;can&nbsp;use&nbsp;whatever&nbsp;string&nbsp;you&nbsp;want.&nbsp;&nbsp;The&nbsp;stream&nbsp;loading&nbsp;event&nbsp;will&nbsp;fire&nbsp;and&nbsp;pass&nbsp;you&nbsp;back&nbsp;the&nbsp;string&nbsp;you&nbsp;passed&nbsp;in.&nbsp;&nbsp;In&nbsp;the&nbsp;case&nbsp;where&nbsp;you&nbsp;have&nbsp;a&nbsp;world&nbsp;file&nbsp;it&nbsp;will&nbsp;be&nbsp;called&nbsp;twice,&nbsp;once&nbsp;for&nbsp;the&nbsp;image&nbsp;and&nbsp;once&nbsp;for&nbsp;the&nbsp;world&nbsp;file.&nbsp;&nbsp;I&nbsp;wouldn’t&nbsp;bother&nbsp;using&nbsp;the&nbsp;extent&nbsp;in&nbsp;the&nbsp;constructor,&nbsp;I&nbsp;would&nbsp;use&nbsp;the&nbsp;stream&nbsp;for&nbsp;the&nbsp;world&nbsp;file&nbsp;as&nbsp;well.&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;We&nbsp;will&nbsp;create&nbsp;a&nbsp;code&nbsp;community&nbsp;sample&nbsp;to&nbsp;show&nbsp;how&nbsp;to&nbsp;load&nbsp;from&nbsp;a&nbsp;stream.&nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;David

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [July 1, 2010, 4:39am UTC](https://community.thinkgeo.com/t/loading-images-101/7147/3 "2010-07-01T04:39:07Z")

</div>

&nbsp;Ted,

&nbsp;&nbsp;Here&nbsp;is&nbsp;an&nbsp;example&nbsp;if&nbsp;the&nbsp;stream&nbsp;loading.&nbsp;&nbsp;We&nbsp;have&nbsp;a&nbsp;code&nbsp;community&nbsp;project&nbsp;that&nbsp;is&nbsp;going&nbsp;to&nbsp;be&nbsp;posted&nbsp;soon&nbsp;but&nbsp;wanted&nbsp;to&nbsp;share&nbsp;the&nbsp;code&nbsp;with&nbsp;you&nbsp;first.

`        private void TestForm_Load(object sender, EventArgs e)        {            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;            winformsMap1.CurrentExtent = new RectangleShape(-180, 90, 180, -90);            GdiPlusRasterLayer worldImageLayer = new GdiPlusRasterLayer(@"world.tif");            ((GdiPlusRasterSource)(worldImageLayer.ImageSource)).StreamLoading += new EventHandler<StreamLoadingEventArgs>(MainForm_StreamLoading);            worldImageLayer.UpperThreshold = double.MaxValue;            worldImageLayer.LowerThreshold = 0;            worldImageLayer.IsGrayscale = false;            LayerOverlay testOverlay = new LayerOverlay();            testOverlay.Layers.Add("worldImageLayer", worldImageLayer);            winformsMap1.Overlays.Add("testOverlay", testOverlay);            winformsMap1.Refresh();        }        void MainForm_StreamLoading(object sender, StreamLoadingEventArgs e)        {            if (e.AlternateStreamName.Contains(".TIF"))            {                Stream stream = new FileStream(@"..\..\Data\world.tif", FileMode.Open, FileAccess.Read);                e.AlternateStream = stream;            }            if (e.AlternateStreamName.Contains(".TFW"))            {                Stream stream = new FileStream(@"..\..\Data\world.tfw", FileMode.Open, FileAccess.Read);                e.AlternateStream = stream;            }        }`

David

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [July 1, 2010, 9:23pm UTC](https://community.thinkgeo.com/t/loading-images-101/7147/4 "2010-07-01T21:23:16Z")

</div>

Ted,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;We&nbsp;also&nbsp;added&nbsp;this&nbsp;as&nbsp;a&nbsp;code&nbsp;community&nbsp;item.&nbsp;&nbsp;You&nbsp;can&nbsp;find&nbsp;it&nbsp;at&nbsp;the&nbsp;link&nbsp;below.&nbsp;  
&nbsp;&nbsp;  
&nbsp;[code.thinkgeo.com/projects/show/imagestreamloading](http://code.thinkgeo.com/projects/show/imagestreamloading)&nbsp;  
&nbsp;&nbsp;  
&nbsp;David

---

<div class="post-metadata">

**Author:** ![Ted](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@Ted](https://community.thinkgeo.com/u/Ted)\
**Post date:** [July 1, 2010, 9:42pm UTC](https://community.thinkgeo.com/t/loading-images-101/7147/5 "2010-07-01T21:42:40Z")

</div>

Thank&nbsp;you,&nbsp;David.&nbsp;&nbsp;But,&nbsp;as&nbsp;we&nbsp;let&nbsp;the&nbsp;user&nbsp;load&nbsp;imagery&nbsp;of&nbsp;their&nbsp;choice,&nbsp;we&nbsp;can’t&nbsp;be&nbsp;sure&nbsp;that&nbsp;it&nbsp;won’t&nbsp;be&nbsp;ECW,&nbsp;JPG2000,&nbsp;or&nbsp;SID.&nbsp;&nbsp;&nbsp;So,&nbsp;we&nbsp;are&nbsp;going&nbsp;to&nbsp;follow&nbsp;your&nbsp;recommendation&nbsp;to&nbsp;extract&nbsp;two&nbsp;blobs&nbsp;from&nbsp;the&nbsp;database&nbsp;for&nbsp;each&nbsp;image…&nbsp;the&nbsp;image,&nbsp;&nbsp;and&nbsp;our&nbsp;own&nbsp;structure&nbsp;that&nbsp;contains&nbsp;the&nbsp;requisite&nbsp;georeferencing&nbsp;information&nbsp;(as&nbsp;a&nbsp;world&nbsp;file&nbsp;has&nbsp;no&nbsp;embedded&nbsp;projection&nbsp;info).&nbsp;  
&nbsp;&nbsp;  
&nbsp;And&nbsp;that&nbsp;leads&nbsp;back&nbsp;to&nbsp;the&nbsp;first&nbsp;question.&nbsp;&nbsp;&nbsp;You&nbsp;recommended&nbsp;against&nbsp;constructing&nbsp;the&nbsp;image&nbsp;with&nbsp;an&nbsp;extent&nbsp;rectangle.&nbsp;&nbsp;&nbsp;Can&nbsp;you&nbsp;elaborate&nbsp;on&nbsp;that?&nbsp;&nbsp;And,&nbsp;if&nbsp;we&nbsp;did&nbsp;decide&nbsp;to&nbsp;do&nbsp;that,&nbsp;can&nbsp;you&nbsp;answer&nbsp;the&nbsp;question&nbsp;about&nbsp;whether&nbsp;the&nbsp;rectangle&nbsp;should&nbsp;extent&nbsp;to&nbsp;the&nbsp;edges&nbsp;of&nbsp;the&nbsp;pixels,&nbsp;or&nbsp;the&nbsp;middles?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks!

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [July 1, 2010, 10:06pm UTC](https://community.thinkgeo.com/t/loading-images-101/7147/6 "2010-07-01T22:06:14Z")

</div>

Ted,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;How&nbsp;did&nbsp;I&nbsp;know&nbsp;you&nbsp;wanted&nbsp;answers&nbsp;to&nbsp;those&nbsp;questions.&nbsp;&nbsp;The&nbsp;reason&nbsp;I&nbsp;led&nbsp;you&nbsp;away&nbsp;from&nbsp;that&nbsp;was&nbsp;I&nbsp;am&nbsp;not&nbsp;sure&nbsp;about&nbsp;the&nbsp;pixel&nbsp;stuff&nbsp;relating&nbsp;to&nbsp;the&nbsp;bounding&nbsp;box.&nbsp;&nbsp;I&nbsp;just&nbsp;figured&nbsp;that&nbsp;if&nbsp;you&nbsp;had&nbsp;the&nbsp;world&nbsp;file&nbsp;information&nbsp;handy&nbsp;it&nbsp;was&nbsp;easier&nbsp;to&nbsp;just&nbsp;create&nbsp;that&nbsp;file.&nbsp;&nbsp;I&nbsp;will&nbsp;find&nbsp;out&nbsp;about&nbsp;exactly&nbsp;how&nbsp;the&nbsp;rectangle&nbsp;bounding&nbsp;box&nbsp;relates&nbsp;to&nbsp;the&nbsp;pixel&nbsp;width&nbsp;etc…&nbsp;&nbsp;Dig,&nbsp;dig…&nbsp;  
&nbsp;&nbsp;  
&nbsp;David

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [July 6, 2010, 10:43pm UTC](https://community.thinkgeo.com/t/loading-images-101/7147/7 "2010-07-06T22:43:12Z")

</div>

Ted,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;checked&nbsp;in&nbsp;the&nbsp;code&nbsp;and&nbsp;I&nbsp;checked&nbsp;visually&nbsp;on&nbsp;the&nbsp;map&nbsp;using&nbsp;the&nbsp;World.tiff.&nbsp;The&nbsp;result&nbsp;is&nbsp;that&nbsp;the&nbsp;RectangleShape&nbsp;passed&nbsp;in&nbsp;the&nbsp;constructor&nbsp;needs&nbsp;to&nbsp;be&nbsp;for&nbsp;the&nbsp;overall&nbsp;bounding&nbsp;box&nbsp;of&nbsp;the&nbsp;image.&nbsp;This&nbsp;means&nbsp;that&nbsp;the&nbsp;upper&nbsp;left&nbsp;point&nbsp;of&nbsp;the&nbsp;RectangleShape&nbsp;is&nbsp;for&nbsp;the&nbsp;upper&nbsp;left&nbsp;part&nbsp;of&nbsp;the&nbsp;upper&nbsp;left&nbsp;pixel&nbsp;of&nbsp;the&nbsp;image.&nbsp;And&nbsp;the&nbsp;lower&nbsp;right&nbsp;point&nbsp;of&nbsp;the&nbsp;rectangleShape&nbsp;is&nbsp;for&nbsp;the&nbsp;lower&nbsp;right&nbsp;part&nbsp;of&nbsp;the&nbsp;lower&nbsp;right&nbsp;part&nbsp;of&nbsp;the&nbsp;image.&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;For&nbsp;example:&nbsp;&nbsp;  
&nbsp;&nbsp;  
&nbsp;GdiPlusRasterLayer&nbsp;gdiPlusRasterLayer&nbsp;=&nbsp;new&nbsp;GdiPlusRasterLayer(@"C:\ThinkGeo\Support\MapData\World.tif",&nbsp;new&nbsp;RectangleShape(-180,90,180,-90));&nbsp;  
&nbsp;&nbsp;  
&nbsp;Is&nbsp;the&nbsp;same&nbsp;as:&nbsp;  
&nbsp;&nbsp;  
&nbsp;GdiPlusRasterLayer&nbsp;gdiPlusRasterLayer&nbsp;=&nbsp;new&nbsp;GdiPlusRasterLayer(@"C:\ThinkGeo\Support\MapData\World.tif");&nbsp;  
&nbsp;&nbsp;  
&nbsp;With&nbsp;the&nbsp;world&nbsp;fie&nbsp;World.tfw:&nbsp;  
&nbsp;&nbsp;  
&nbsp;0.36000&nbsp;  
&nbsp;0&nbsp;  
&nbsp;0&nbsp;  
&nbsp;-0.36000&nbsp;  
&nbsp;-179.82000&nbsp;  
&nbsp;89.8199999999999872&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;get&nbsp;exactly&nbsp;the&nbsp;same&nbsp;result&nbsp;from&nbsp;the&nbsp;GetBoundingBox,&nbsp;although&nbsp;there&nbsp;seem&nbsp;to&nbsp;be&nbsp;some&nbsp;precision&nbsp;issues:&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;double&nbsp;ulX&nbsp;=&nbsp;gdiPlusRasterLayer.GetBoundingBox().UpperLeftPoint.X;&nbsp;//-180.00000733137131&nbsp;  
&nbsp;&nbsp;double&nbsp;ulY&nbsp;=&nbsp;gdiPlusRasterLayer.GetBoundingBox().UpperLeftPoint.Y;[//89.999999701976776](https://89.999999701976776)&nbsp;  
&nbsp;&nbsp;double&nbsp;lrX&nbsp;=&nbsp;gdiPlusRasterLayer.GetBoundingBox().LowerRightPoint.X;[//180.00000697374344](https://180.00000697374344)&nbsp;  
&nbsp;&nbsp;double&nbsp;lrY&nbsp;=&nbsp;gdiPlusRasterLayer.GetBoundingBox().LowerRightPoint.Y;//-90.0000074505806&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;hope&nbsp;that&nbsp;helps.&nbsp;  
&nbsp;&nbsp;  
&nbsp;David

---

<div class="post-metadata">

**Author:** ![Ted](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@Ted](https://community.thinkgeo.com/u/Ted)\
**Post date:** [July 7, 2010, 4:36am UTC](https://community.thinkgeo.com/t/loading-images-101/7147/8 "2010-07-07T04:36:10Z")

</div>

That's&nbsp;perfect,&nbsp;David.&nbsp;&nbsp;&nbsp;Exactly&nbsp;how&nbsp;I&nbsp;hoped&nbsp;it&nbsp;worked.

Thank&nbsp;you.

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [July 7, 2010, 11:47pm UTC](https://community.thinkgeo.com/t/loading-images-101/7147/9 "2010-07-07T23:47:23Z")

</div>

Ted,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;Excellent.&nbsp;&nbsp;Let&nbsp;me&nbsp;know&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;other&nbsp;issues.&nbsp;  
&nbsp;&nbsp;  
&nbsp;David
