.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

InteropBitmap, GDI bitmaps, and the alpha channel

Posted By:      Posted Date: August 31, 2010    Points: 0   Category :WPF
Hey, After having successfully used InteropBitmap to render Windows Forms bitmaps in WPF scenes, I recently tried the same sort of thing using plain old GDI bitmaps, and I got surprising results.  So I am just doing something like: CBitmap gdiBitmap;gdiBitmap.CreateCompatibleBitmap( (CDC*) &dc, rClient.Width(), rClient.Height() );    and then I select it into a DC and make some GDI calls to fill it, draw a FrameRect, and draw some text.  After that, I do the normal dance to get the bitmap out of the DC, make a BitmapSource from it, and assign that to the Source property of the WPF Image in my scene: CBitmap * resbmp = dcOff.SelectObject( pOldBitmap );   HBITMAP hbmp = (HBITMAP) resbmp->GetSafeHandle();     BitmapSource ^bmpSource = CreateBitmapSourceFromHBitmap( (System::IntPtr) hbmp,       IntPtr::Zero, Int32Rect::Empty, BitmapSizeOptions::FromEmptyOptions() );   InteropBitmap ^ibmp = static_cast<InteropBitmap^>( bmpSource );     m_WPFImage->Source = ibmp;    When I do the above, the bitmap does not display *at all*.  After making some other calls to get the actual bits for the GDI bitmap, I can see that all of the alpha values are 0.  So what I'm getting is a bitmap that is completely transparent, and that is why InteropBitmap displays nothing.  The only way I have found to work around this is to pass the bitmap through GDI+ before creati

View Complete Post

More Related Resource Links

Bypassing image alpha channel


First - Hello.

Second - I am developing a WPF application in C# so I wasn't sure where to post. I've decided to post the question in this forum, sorry if I'm wrong.

The application has a custom GUI (not just a clone of the Windows Shell GUI or Ribbon GUI), so many of the buttons have non-standart shapes. To create the shapes I need, I added PNG images with a transparent backgrounds. They work just fine, but the problem is that most of the images intersect, so clicking a "button" (i.e. image) near it's border will result it actually clicking the adjacent button.

I figured out 2 ways to solve the problem:

1. Using the MouseDown event to bring the current button (image) on top of the Grid. This will disable the adjacent images to overlay the current one. After the MouseUp event is triggered, the object returns to it's original position in the order hierarchy, below the adjacent images, thus achieving the goal. Unfortunetely if hovering the mouse next to the button area, the marginal buttons would be highlighted. It's a minor bug observed even in Windows 7, but I DON'T WANT IT. So:

2. Using the MouseDown event to get the position of the cursor and checking whether the part of the image underneath is opaque or not. If it is not, bypassing the further events. The

Foundations: Bitmaps and Pixel Bits


Charles Petzold takes an inside look at the flexible bitmap pixel formats offered by the retained-mode graphics features of Windows Presentation Foundation.

Charles Petzold

MSDN Magazine June 2008

{ End Bracket }: Tune in to Channel 9


If you fly United Airlines, you can hear what's going on in the cockpit by turning the radio dial to Channel 9. Now if you want to get inside the head of Microsoft you can tune to Channel 9 on the MSDN Web site (see http://channel9.

MSDN Magazine September 2004

Secure It: WS-Security and Remoting Channel Sinks Give Message-Level Security to Your SOAP Packets


As more organizations adopt XML-based Web Services, the need for message-level security has become evident. WS-Security, now supported in the Microsoft .NET Framework, addresses this need. Using the WS-Security framework, developers can implement channel sinks to intercept Remoting messages as they pass through the .NET Remoting infrastructure. The sink can read the message, change it, and pass it along. During this process, the message can be signed for added security. This article explains how to implement a Remoting channel sink that will modify the Remoting message by including a UserName token in the header, then sign the body using the token.

Neeraj Srivastava

MSDN Magazine November 2003

.NET Remoting: Secure Your .NET Remoting Traffic by Writing an Asymmetric Encryption Channel Sink


As .NET Remoting gains popularity in the enterprise space, it must meet business demands for trustworthy computing. Remoting traffic can be secured when objects are hosted in IIS, but when they aren't hosted in IIS, custom security solutions can be developed to secure them. This article provides an in-depth look at writing channel sinks for .NET. It also details the flow of data through custom channel sinks and explains the kinds of manipulations that can be performed on that data.

Stephen Toub

MSDN Magazine June 2003

Getting SessionID from channel


I need to set ASP.NET_SessionId in order to dowload a file from server.

I use the following code

IContextChannel mychannel = (IContextChannel)myService;
using (OperationContextScope scope = new OperationContextScope(mychannel))
  res = myService.DoSomething();
  System.ServiceModel.Channels.MessageProperties messageProperties = System.ServiceModel.OperationContext.Current.IncomingMessageProperties;
  if (messageProperties.Count > 0)
    HttpResponseMessageProperty httpResponseMessageProperty = (HttpResponseMessageProperty)messageProperties[HttpResponseMessageProperty.Name];
  if (httpResponseMessageProperty != null)
  sessionCoookie = httpResponseMessageProperty.Headers[System.Net.HttpResponseHeader.SetCookie];

It works fine if I use basicHttpBinder.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

But when I use windows authentication (basicHttpBinder.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;), there are 2 message responses.

The first one HTTP/1.1 401 Unauthorized with "Set-Cookie: ASP.NET_SessionId=sa34zv55sndjgq55fqzaw5ii; path=/; HttpOnly", I can see it in Fiddler and the second one with "WWW-Authenticate: Negotiate oYGgMIGdoAMKAQChCwYJKoZIgvcS

Hands-On Lab: Building Solutions with Access 2010 (Channel 9)

The objectives of this Hands-On Lab are to acquaint you with the new developer related features of Access 2010 with a keen emphasis on understanding the differences between developing database objects that will work in a Web database versus objects that work only in a client database.

Microsoft SharePoint 2010 Developer Training Course (Channel 9)

SharePoint 2010 provides a platform for developers to rapidly build solutions using familiar tools while leveraging a rich set of out-of-the-box features. Visual Studio 2010 and SharePoint Designer 2010 make developers even more productive. Find videos and presentations here to help you get started.

Download: SharePoint 2010 Developer Presentations for Channel 9

Download all of the PowerPoint presentations used in the SharePoint 2010 Learning Course on Channel 9.

Compare 2 WPF bitmaps

Hi I have a question. I have an app which take some snapshots of the screen from time to time(as bitmaps)and compares the current screen with the previous one. This must work very fast and I was curios if I can use BitmapSource to achieve better performance(using GPU). The current solution compares pixel by pixel the 2 GDI+ bitmaps but it doesnt work as desired. Thank you

parsing weather channel xml file using linq

 Hi I never used linq before and i'm having trouble parsing the xml file at  http://xoap.weather.com/search/search?where=" + strCityName.ToString(); I used to use a dataset but since trying to change my site to mvc, i thought i would use linq to xml, but after 2 days have still not found success. i have a class called: public class WeatherCityBLLModel { public string loc { get; set; } public string loc_id { get; set; } } and then a class called public class WeatherCityDALModel { public static List<WeatherCityBLLModel> GetLocation(string strCityName) { XDocument doc = XDocument.Load("http://xoap.weather.com/search/search?where=" + strCityName.ToString()) return doc; <<< Does not work } } How do i get the data from xoap.weather and pass it to my controller Any help appreciatedGeorge        

Need suggestion's and guidelines for designing and creating WCF client channel pool

  What factor's should be considered for creating a WCF client channel pool? 1)Whether it is advisable to create a pool of pre-opened channel's?or create a new channel as an when needed?which one is expensive operation? 2)what should be the pool size? 3)how pool will support if concurrent request's are coming which use different binding's? 4)what should be channel lifetime? 5)If all the connection's in the pool are busy,whether we should wait till the free channel's are available in the pool or create new one's which is expensive?which one is better? if anybody is able to provide some usefull links it will be helpfull.

Graphics Bitmaps & Rectangles

I am trying to draw 2 bitmap images on top of each other. 1 is a background image that only changes occasionally and the other is a foreground image the moves around a lot. The foreground image is usually an ellipse. But when I show it I always end up with the corners of the constraining rectangle being shown! I have included some basic code that demonstrates what I mean. How can I show two bit maps with the top one only showing the exact shape I require (without gray corners). Also if I want to remove the foreground image from being seen do I need to redraw the entire background? or can I just redraw the bit where the foreground image was. or can I just hide the foreground image somehow? This maybe a basic question - Graphics are a new area to me! Many thanks in advance!   using   System; using   System.Collections.Generic; using   System.ComponentModel; using   System.Data; using   System.Drawing; using   System.Drawing.Drawing2D; using   System.Text; using   System.Windows.Forms; namespace   TEST200 {   public partial class Form1 : Form {   private Bitmap bmpBACKGROUND;   private Bitmap bmpFOREGROUND;   public Form1() { InitializeComponent(); }   private void Form1_Load(object sender, EventArgs e) { bmpBACKGROUND = new Bitmap(this.ClientRectangle.Width,

disabling alpha input to a text box

how to disable alpha input to text box..?? thnks in advance 

PollingDuplexHttpBinding Client Channel Faults unexpectedly after few seconds

Hello, i have a Silverlight 4 application which communicates using Http Polling Duplex to an IIS 7, .NET 4 WCF Service (actually two of them, in the same app). I am obviously taking advantage of the callback features provided by this type of solution. Setup has been performed by following these documents: Service setup: http://msdn.microsoft.com/en-us/library/cc645027%28v=VS.95%29.aspx Silverlight setup: http://msdn.microsoft.com/en-us/library/ee844557%28v=VS.95%29.aspx All has been working fine until yesterday, when i went on upgrading the Silverlight Tools for VS2010 to version 10.0.30319.352 which has also upgraded my Silverlight runtime to 4.0.50826.0 . Running my app now, after few seconds from the first call to the services, the client inner-channel faulted event fires on both proxies without an apparent motivation (exception, user interaction, etc.). What i have been able to notice, by analyzing connections with Fiddler, is that as soon as the open connection to the service which holds a callback channel receives a response, the client-side proxies fail. I'll try to show how the HTTP connections appear to behave: Call to the first service, callback channel retreived, immediate response 200 OK, no content Call to the second service, business logic performed, immediate response 200 OK, no content Call to the first service, no response for a few seconds, response 200 OK

Problem with IPC Channel "Port is busy: All pipe instances are busy"

Hi all. Sometimes, some of our remote objects when invoked throw an exception "Port is busy: All pipe instances are busy". Putting the code in a while(true) loop and catching the exception, after some loops everything goes fine. Does anyone know the meaning of that exception? I've been googling a lot but found no clue.   Thanks, regards Cristian Mori

Assembly versioning best practice question wrt alpha, beta, etc

We'd like to employ some best practices with respect to versioning in our assemblies.  Since I'm coming from a Java+Maven+OSGi background, I'll share its way of doing versioning. Versioning in Java is arbitrary; there are no platform-dictated schemes.  However, for quite some time now, versions have the typical form major.minor.revision[.qualifier] where major & minor are pretty self-explanatory, revision is used to indicate very minor updates like bug fixes/hot fixes, etc, and qualifier is used at the publisher's convenience.  Almost always, the major, minor & revision elements are numeric values, but they don't have to be.  Ordering is as you might expect:  major versions are the most signficant element and are compared by the string's order unless their all numeric, in which case they're compared numerically, then minor, then revision, then qualifier, if present.  So, to give an example of the versioning scheme that a newly created library might go through, consider the following versions with descriptions: 1.0.0.A1 -- alpha 1 1.0.0.A2 -- alpha 2 1.0.0.B1 -- beta 1 1.0.0.M1 -- milestone 1 1.0.0.M2 -- milestone 2 1.0.0.RC1 -- release candidate 1 1.0.0.RC2 -- release candidate 2 1.0.0.RELEASE -- golden release to manufacturing, aka "official" release Notice that the version string for the version considered gol
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend