<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://communities.bentley.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>[V8i MDL] White as transparent color for mdlImage_extCreateFileFromRGB</title><link>https://communities.bentley.com/products/programming/microstation_programming/f/bdn-mdl-c-c/105869/v8i-mdl-white-as-transparent-color-for-mdlimage_extcreatefilefromrgb</link><description>I&amp;#39;m using mdlImage_extCreateFileFromRGB to export design file as image with setting Preferences -&amp;gt; Black background -&amp;gt; White set to true. So I have white background in my view. What I need is to set white background to be transparent when exported to</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: [V8i MDL] White as transparent color for mdlImage_extCreateFileFromRGB</title><link>https://communities.bentley.com/thread/319191?ContentTypeID=1</link><pubDate>Fri, 03 Apr 2015 07:21:26 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:f88d45bc-7cec-4a83-a8b1-d4bf80136a75</guid><dc:creator>Mantas Unknown</dc:creator><description>Thanks Mathieu, this seems to be a working solution. &lt;br /&gt;
&lt;br /&gt;
Finally this week&amp;#39;s headache is gone. Cheers!&lt;br /&gt;
&lt;br /&gt;
Mantas&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [V8i MDL] White as transparent color for mdlImage_extCreateFileFromRGB</title><link>https://communities.bentley.com/thread/319141?ContentTypeID=1</link><pubDate>Thu, 02 Apr 2015 16:39:51 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:6bee4ae2-4ffc-467f-8a94-4d0c6a0d4a4d</guid><dc:creator>Mathieu St-pierre</dc:creator><description>&lt;p&gt;Hi Mantas,&lt;/p&gt;
&lt;p&gt;The crash was because the mdlImage_extCreateFileFromRGB expected an RGBA image. The transparency parameter seems to work with PNG and RGB buffer, but whatever the value black is always seem to be considered as the alpha value.&lt;/p&gt;
&lt;p&gt;Another solution is to manually convert the RGB view screenshot buffer into an RGBA buffer.&lt;/p&gt;
&lt;p&gt;Here is the code that is working on my computer :&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;pre class="brush: cpp; fontsize: 100; first-line: 1; "&gt;int g_fileFormat = IMAGEFILE_PNG;

int g_Compression = COMPRESSTYPE_DEFLATE;

int g_colorMode = COLORMODE_RGBA;




Point2d imageSize;

imageSize.x = 500;

imageSize.y = 500;

byte *inputMap = (byte*)malloc(3 * imageSize.x * imageSize.y);




mdlImage_saveViewToRGB( &amp;amp;inputMap, &amp;amp;imageSize, WIREFRAME, FALSE, 0, 0);

//Convert RGB to RGBA

byte *inputMapWithAlpha = (byte*)malloc(4 * imageSize.x * imageSize.y);

size_t nbPixels = (size_t)imageSize.x * imageSize.y;

for (size_t lineInd = 0; lineInd &amp;lt; (size_t)imageSize.x; lineInd++)

{

size_t inputRedInd = lineInd * imageSize.y * 3;

size_t inputBlueInd = inputRedInd + imageSize.y;

size_t inputGreenInd = inputBlueInd + imageSize.y;




size_t redInd = lineInd * imageSize.y * 4;

size_t blueInd = redInd + imageSize.y;

size_t greenInd = blueInd + imageSize.y;

size_t alphaInd = greenInd + imageSize.y;

for (size_t colInd = 0; colInd &amp;lt; (size_t)imageSize.y; colInd++)

{

inputMapWithAlpha[redInd] = inputMap[inputRedInd];

inputMapWithAlpha[blueInd] = inputMap[inputBlueInd];

inputMapWithAlpha[greenInd] = inputMap[inputGreenInd];

if (inputMap[inputRedInd] == 0xFF &amp;amp;&amp;amp; inputMap[inputBlueInd] == 0xFF &amp;amp;&amp;amp; inputMap[inputGreenInd] == 0xFF)

{

inputMapWithAlpha[alphaInd] = 0x00;

}

else

{

inputMapWithAlpha[alphaInd] = 0xFF;

}




inputRedInd++;

inputBlueInd++;

inputGreenInd++;

redInd++;

blueInd++;

greenInd++;

alphaInd++;

}

}

int results = mdlImage_extCreateFileFromRGB (&amp;quot;D:\\BeCommunities\\Transparency\\out.png&amp;quot;, g_fileFormat, g_colorMode, &amp;amp;imageSize, inputMapWithAlpha, g_Compression, 0/*white*/, NULL);




assert(results == SUCCESS);

free(inputMap);

free(inputMapWithAlpha);
&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Mathieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [V8i MDL] White as transparent color for mdlImage_extCreateFileFromRGB</title><link>https://communities.bentley.com/thread/319066?ContentTypeID=1</link><pubDate>Thu, 02 Apr 2015 07:00:20 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:70e1e4c5-3f3e-4d26-9c25-89fc09cbb499</guid><dc:creator>Mantas Unknown</dc:creator><description>&lt;p&gt;Thanks for quick response and sorry for not including parameters, but I still can get it to work. Probably the reason it failed before is because I was using COLORMODE_RGB not RGBA. But if I set colormode to COLORMODE_RGBA I get &amp;quot;PNG warning: invalid TRNS&amp;quot; and it crashes with System Fault: 5 error on mdlImage_extCreateFileFromRGB.&lt;/p&gt;
&lt;p&gt;&lt;a href="/cfs-file/__key/communityserver-discussions-components-files/53216/2015_2D00_04_2D00_02-09_5F00_46_5F00_47_2D00_MicroStation-V8i-_2800_SELECTseries-3_2900_-_2D00_-Text-Window.jpg"&gt;&lt;img src="/resized-image/__size/940x0/__key/communityserver-discussions-components-files/53216/2015_2D00_04_2D00_02-09_5F00_46_5F00_47_2D00_MicroStation-V8i-_2800_SELECTseries-3_2900_-_2D00_-Text-Window.jpg" width="487" height="158" alt=" " /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now my code is:&lt;/p&gt;
&lt;pre class="brush: cpp; collapse: true; fontsize: 100; first-line: 1; "&gt;Private int g_fileFormat = IMAGEFILE_PNG;
Private int g_Compression = COMPRESSTYPE_DEFLATE;
Private int g_colorMode = COLORMODE_RGBA;

...

byte *transp = NULL;
byte white[] = {255, 255, 255};
transp = (byte*)white;

mdlImage_saveViewToRGB( &amp;amp;inputMap, &amp;amp;imageSize, WIREFRAME, FALSE, 0, viewIdx);

results = mdlImage_extCreateFileFromRGB (fn, g_fileFormat, g_colorMode, &amp;amp;imageSize, inputMap, g_Compression, transp, NULL);&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: [V8i MDL] White as transparent color for mdlImage_extCreateFileFromRGB</title><link>https://communities.bentley.com/thread/319019?ContentTypeID=1</link><pubDate>Wed, 01 Apr 2015 17:09:00 GMT</pubDate><guid isPermaLink="false">6dad98f5-dbc9-4c4d-a9ba-e9da8dc6aa8e:c5b8f435-8e96-48d9-bc3d-ba2cc8004372</guid><dc:creator>Mathieu St-pierre</dc:creator><description>Hi Mantas, &lt;br /&gt;
&lt;br /&gt;
The transparency parameter is only use with the PNG file format. &lt;br /&gt;
&lt;br /&gt;
I guess if your color mode is RGBA the value of the transparency should be :&lt;br /&gt;
&lt;br /&gt;
transp[0] = 255;&lt;br /&gt;
transp[1] = 255;&lt;br /&gt;
transp[2] = 255;&lt;br /&gt;
&lt;br /&gt;
HTH, &lt;br /&gt;
&lt;br /&gt;
Mathieu&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>