|
May
20
Written by:
Jeremiah Morrill
5/20/2007 5:27 PM
Native Pointer to Bitmapsource's Buffer Last post I covered how to get reference to the WPF DirectShow graph and inject your own filter chain. Like I stated, I think this approach is sort of dirty. I say that because it still lacks the control and flexibility needed. So what if we could get direct access a BitmapSource's native image buffer? You know one exists, though the WPF API hides it (probably for good reason). If we could efficiently update a BitmapSource's buffer, we could do fast image processing (brightness, contrast, hue, etc) or even make our own MediaPlayer in WPF without having to even use DirectShow! Well Friday night, after the bar, I set out with the goal of getting that BitmapSource's buffer. After about six hours and a hangover later, I got what I was looking for. Let me tell you, it was a crash course in Reflection and WIC APIs. Let me give a short explaination on how this is done. WPF uses the unmanaged WIC in the backend for imaging, so it would make sense that WPF keeps reference somewhere to the WIC handle. At least this is what I was guessing. Poking around with Reflection, I found the WIC handle I was looking for in a private field in the BitmapSource class. I then did some research into WIC on how to lock the bitmap's pixels and get the native buffer. Plugging in all the pieces, I was able to get the pixel's pointer! Doing some tests, writing to the buffer, I found that my xaml Image that held my hacked BitmapSource, was not changing. :(. I ran a Image.InvalidateVisual() and the change rendered! I did some tests, writing a 640x480 at 30 times/sec resolution buffer to the BitmapSource's buffer. There were zero page faults, RAM usage didn't move at all, but the CPU usage was around 7%. This leads me to believe that I am indeed copying over the same buffer each time and the CPU usage is due to either my lack of WIC/WPF knowledge or that is the hit at which WPF rendering takes for doing such operations. Now we can create high-performance imaging routines in WPF. We can make custom DirectShow renderers that take our native BitmapSource buffer and write to it. We can implement our own players w/o DirectShow. So many implementations! The only caveat as of now is I seem to only be able to make this work with RGB32 pixel format. **UPDATE: Other's have claimed to be able to use other color spaces. Play around, you might get lucky Also DO NOT FORGET TO RUN Image.InvalidateVisual() after you update the BitmapSource's buffer or you will not see anything change! **UPDATE: After Image.InvalidateVisual, make sure you get the pointer from the BitmapBuffer.BufferPointer property. The get{} relocks the bitmap pixels. Here is the example usage of the class (Source for WPFUtil.BitmapBuffer class in file attached at the bottom) int width = 640;
int height = 480;
int bpp = 4;
//These are 'dummy' pixels
//only used to create our bitmap
//further editing after bitmap creation
//of these pixels does nothing, that is
//what this hack is for
byte[] pixels = new byte[width*height*bpp];
//Create a new bitmap source
BitmapSource bmpsrc = BitmapSource.Create(width,
height,
96,
96,
PixelFormats.Bgr32,
null,
pixels,
width * bpp);
//Set our Image in our Xaml to our
//new bitmap
TestImage.Source = bmpsrc;
//Create our helper class
buf = new WPFUtil.BitmapBuffer(bmpsrc);
//Woo a pointer!
IntPtr buffPointer = buf.BufferPointer;
BitmapBuffer.cs - Get native pointer to BitmapSource's buffer
Tags:
64 comment(s) so far...
Re: WPF Hackery! Part II
There is another way.
You can derive from BitmapSource, and write your own code to compute the output image on the fly.
Such an object could be very lightweight, so instead of manual invalidating, you can just overwrite the pointer to the BitmapSource to a new one. You are required to write three copy-out functions, you must make the object clonable. You must be prepared to run your code from another thread than the UI thread (i consider this an advantage).
By Jan de Vaan on
6/28/2007 1:00 PM
|
Re: WPF Hackery! Part II
Congratulation for this fantastic trick. I'm playing with a webcam and with a DTV on Windows XP SP2, and I'm getting some tearing (vsync) issues :(
Here my frame update code: unsafe int ISampleGrabberCB.BufferCB(double sampleTime, IntPtr buffer, int bufferLength) { System.Windows.Controls.Image image = this.hostingControl.WPFImage; image.Dispatcher.BeginInvoke(DispatcherPriority.Render, new ThreadStart(delegate { CopyMemory(wpfBitmapBuffer.BufferPointer, buffer, bufferLength); image.InvalidateVisual(); })); return 0; }
Do you no a way to synchronize the "InvalidateVisual()" with the monitor vsync?
By Dgis on
8/3/2007 4:00 AM
|
Re: WPF Hackery! Part II
Under Vista it seems to be synchronised!!! No vsync issue on vista.
By Dgis on
8/3/2007 5:28 AM
|
Re: WPF Hackery! Part II
Under Vista it seems to be synchronised!!! No vsync issue on vista.
By Dgis on
8/3/2007 5:29 AM
|
Re: WPF Hackery! Part II
Under Vista it seems to be synchronised!!! No vsync issue on vista.
By Dgis on
8/3/2007 5:29 AM
|
Re: WPF Hackery! Part II
Under Vista it seems to be synchronised!!! No vsync issue on vista.
By Dgis on
8/3/2007 5:29 AM
|
Re: WPF Hackery! Part II
I have not tested this on XP, but others using this code on XP have not reported any issues. If you are using a DirectShow based solution, maybe you should try the WPF Media Bridge (http://jmorrill.hjtcentral.com/Home/tabid/428/EntryID/15/Default.aspx). It provides the best performance and (sometimes) the best compatibility. Can you describe the tearing? Is it flickering on you?
By Jeremiah Morrill on
8/3/2007 12:01 PM
|
Re: WPF Hackery! Part II
I understood what's happen. Basically the issue is not from your trick, this is WPF which is not vertically synchronized on Windows XP SP2. On Vista, WPF is well synchronized. By "not vertically synchronized", I mean the WPF animation can be updated in the middle of the screen, inducing abreaking in the picture (like a game with the vsync switched off) . So maybe the fact of waiting for the vertical blank before calling InvalidateVisual() could solve this issue. I'm investigating the WaitForVerticalBlank() directx function to fix it. I do not try your "WPF Media Bridge" which seems to be another good idea, but I think it will produce the same issue, because the problem is in WPF.
By Dgis on
8/4/2007 2:45 PM
|
Re: WPF Hackery! Part II
This is a nice hack, but it still requires you to copy an entire bitmap to the BitmapSource. Has anyone found a way to invalidate just a portion of the bitmap so you don't have to move all that data every frame? I incorporated this technique in a project, and it works like a charm. But, even with the smallest changes in the bitmap, there's a lag caused by all the copying going on in the background. If the user wants feedback, for instance, if you have icons on a background image, and wanted a mouseover selection rectangle to show up, it takes about a second for it to appear. Right now, making each icon a WPF image object is not an option, so I was wondering if anyone here has found a way to do GDI-speed drawing (and region invalidation) in WPF.
By d on
8/22/2007 11:23 AM
|
Re: WPF Hackery! Part II
This hack does not require you to copy an entire bitmap. That is only done once on initialization.
You can update portions of the bitmap if you want. The greatest overhead is with WPF when you run the Invalidate() on the image.
By Jeremiah Morrill on
8/22/2007 11:45 AM
|
Re: WPF Hackery! Part II
This example shows me rendering directly on to a bitmap:
http://jmorrill.hjtcentral.com/Home/tabid/428/EntryID/72/Default.aspx
By Jeremiah Morrill on
8/22/2007 11:53 AM
|
Re: WPF Hackery! Part II
Ok, obviously I need to take another look at my code. The way I wrote the code was probably based on some wrong assumptions about what WPF was doing with its internal image buffer after an invalidate. I'll have to do more investigating. Thanks for the input.
Yes, I saw the water demo. It's very impressive, especially given WPF's limitations. But I wonder how well it would perform on, say, a 1280x1024 backdrop... In one of my tests, I'm blitting a 4000x4000 image to ~1500x900 sized wpf Image, and dragging it around with a mouse. I'm getting around 5 fps or so on my P4 3ghz laptop.
By d on
8/22/2007 2:24 PM
|
Re: WPF Hackery! Part II
Jeremiah, may I ask you how you are drawing to the buffer? The way I'm doing it is by creating a Bitmap using the IntPtr to the internal buffer, and then creating a graphics object out of that. When you're just calling DrawImage, it works perfectly. However, when you call functions like Clear or FillRect before you call DrawImage, there are times when the Image doesn't draw at all. This occurs more often the larger the window you're trying to draw on. I hope it's just the method I'm using to create the Graphics object. Otherwise, this technique might not be usable in most general use cases. Has anyone else noticed this behavior?
By d on
8/22/2007 8:34 PM
|
Re: WPF Hackery! Part II
Out of curiousity, when pixels are copied to the image's buffer and InvalidateVisual is called, would the buffer then be copied up to the graphics card (or some other location) for blitting? You mentioned that 7% CPU usage, and I'm wondering if that's caused by the full buffer being copied to the graphics card. Not sure if anyone here would know the details of how WPF handles its buffers, but just throwing the question out there.
By Dan on
8/28/2007 1:31 PM
|
Re: WPF Hackery! Part II
I'm only going to guess here...I THINK I heard on a Channel9 video that WPF keeps two copies of the media. In ram and on the video ram. I think that copying it to the GPU on Invalidate() might be where the overhead is. [Guessing again,] I think that the MediaElement renders directly to the the video card and is why it uses less CPU.
By Jeremiah Morrill on
8/28/2007 1:38 PM
|
Re: WPF Hackery! Part II
Jeremiah,
I've been using the bitmap hack for several months now and it's been working OK (although I really wish I could improve the performance a little more).
I've just discovered that the latest .NET 3.0 makes InteropBitmap a public class. I'm pretty sure you can now accomplish much the same thing as your bitmap hack without resorting to reflection. The basic steps are as follows:
1.) You need to create an unmanaged memory buffer to store the bitmap data. Create a memory section using the API call CreateFileMapping, and then get a pointer to the buffer using MapViewOfFile. The resultant pointer will always be the location of the bitmap data.
2.) Create a bitmap from the buffer using System.Windows.Interop.Imaging.CreateBitmapSourceFromMemorySection. This returns a BitmapSource which will store it's pixel data at the address you specify. It can never move the buffer on you.
3.) The BitmapSource is actually an InteropBitmap. Calling the Invalidate function on InteropBitmap forces the display to update. Copy your frame data into the memory you allocated, and call Invalidate on the InteropBitmap and it all works.
...the resultant performance seems identical to your bitmap hack...but it's nice not to have to resort to reflection and internals that we have no control over.
If you search the WPF forums you'll find a more detailed example.
By Todd on
12/8/2007 10:17 AM
|
Re: WPF Hackery! Part II
Jeremiah,
I've been using the bitmap hack for several months now and it's been working OK (although I really wish I could improve the performance a little more).
I've just discovered that the latest .NET 3.0 makes InteropBitmap a public class. I'm pretty sure you can now accomplish much the same thing as your bitmap hack without resorting to reflection. The basic steps are as follows:
1.) You need to create an unmanaged memory buffer to store the bitmap data. Create a memory section using the API call CreateFileMapping, and then get a pointer to the buffer using MapViewOfFile. The resultant pointer will always be the location of the bitmap data.
2.) Create a bitmap from the buffer using System.Windows.Interop.Imaging.CreateBitmapSourceFromMemorySection. This returns a BitmapSource which will store it's pixel data at the address you specify. It can never move the buffer on you.
3.) The BitmapSource is actually an InteropBitmap. Calling the Invalidate function on InteropBitmap forces the display to update. Copy your frame data into the memory you allocated, and call Invalidate on the InteropBitmap and it all works.
...the resultant performance seems identical to your bitmap hack...but it's nice not to have to resort to reflection and internals that we have no control over.
If you search the WPF forums you'll find a more detailed example.
By Todd on
12/8/2007 10:17 AM
|
Re: WPF Hackery! Part II
Hi, I wanted to develop a WPF project that has very intense performance requirements, and I thought it was best to consult you on this before designing the app.
The application would be rendering data obtained from a medical hardware as charts. For this, the requirements are:
1) Requires rendering of almost 250 points every 4 milliseconds in a chart (to be connected by a line or Bezier curve). The rendered points will also have a spectrum of colors (as in a heatmap). 2) The rendered points would move when new data is pumped by the hardware and rendered (as in a ECG) 3) At any given point there could be over a 150,000 moving points on the chart (because the chart window would display data of 3-5 seconds). 4) Also later we would like to retain the history of data points of past 60 seconds or so. 5) There could be upto 12 such chart displays running parallel at the same time in a window on the application.
I seek your thoughts on what could be the best approach for rendering these points and animating them. Some kind of selectively invalidating the UI would be desirable here. Also what are the recommended options for storing this much data for history purpose. The problem demands something at a very low level in the WPF stack.
Any Help would be highly appreciated, Thanks in Advance
By Nirupama on
5/6/2008 5:53 AM
|
Re: WPF Hackery! Part II
Hi..
Thsi is a gentle reminder..for the above query... Please do give in your inputs...That would be of great help..
Thanks and Regards, Nirupama
By Nirupama on
5/26/2008 6:13 AM
|
|
Re: WPF Hackery! Part II
Beware of the first sight conclusions, often they can be wrong.tramadol
By mesa on
7/25/2008 5:49 AM
|
Re: WPF Hackery! Part II
I think you worry too much on this subject but you posted a good question there ! acomplia
By acomplia on
8/18/2008 5:18 AM
|
Re: WPF Hackery! Part II
2008popularsitesonline.com
By Hellos on
10/2/2008 9:12 PM
|
Re: WPF Hackery! Part II
I have tried this code for rendering frames decoded by ffmpeg, and can only get the first frame to actually display. I have obtained the memory pointer and copy my rgb image buffer to it. If I destroy and recreate the BitmapSource in every iteration, then it works, but with obviously terrible performance - Can anyone tell me why the update doesnt occur? I am invalidating the image correctly...
By Adam Langley on
3/22/2009 12:10 PM
|
Re: WPF Hackery! Part II
Thank you! I was wanting to port a GDI+ app to WPF, and I couldn't find any way to access the individual pixels of a rendered bitmap (it's a Genetic Algorithm that uses the pixel values to calculate the fitness function). Now I know how to do it!
By John on
6/2/2009 5:53 AM
|
|
Re: WPF Hackery! Part II
this is something i have been very interested in lately. thanks.
By replica fendi scarf on
1/5/2010 11:23 PM
|
Standard WPF: WriteableBitmap
Please use standard API: WriteableBitmap (I am not sure whether it requires 3.5 SP1)
By Michał on
1/20/2010 5:42 PM
|
Re: WPF Hackery! Part II
I agree Michael. But check the date on the original post ;)
By Jeremiah Morrill on
1/20/2010 5:46 PM
|
Re: WPF Hackery! Part II
Christian Louboutin sets casual pace for new millenniumChristian Louboutin 's view of change, however, does not include the shock fashion seen on some of the runways this week, from sequined dresses to corsets. "It's all about good taste," said Christian Louboutin , noting that a kilt can be very fashionable in the right circumstances.
The most daring act of the Christian Louboutin Shoes show was to put the tie and shirt in the back drawer. Except for a few cameo appearances, these staples of classic womenswear were replaced by pullovers, from a close fitting V-neck to a cassock-length turtle neck.
hot online store:クリスチャンルブタン靴|クリスチャンルブタン 通販|クリスチャンルブタン 販売
565shop:クリスチャンルブタン|Christian Louboutin 通販|Christian Louboutin 新作
At the new Hugo Boss store in King Street, store wowomenager Eric Fink advocates a three- or four-button suit for weddings that can be worn for other occasions or as separates. The Boss look is a charcoal-hued shirt with a black tie or a white shirt with a gold or silver tie. White suits are a no-no. And so, too, Rabbitohs' sock
Far from the rigidity of the uniform blazer, the latest Christian Louboutin jacket is elongated, has Velcro or snaps in the place of buttons, and a minimalist lapel. At times it is so light that it can be worn with nothing underneath.
hot online store:クリスチャンルブタン靴|クリスチャンルブタン 通販|クリスチャンルブタン 販売
565shop:クリスチャンルブタン|Christian Louboutin 通販|Christian Louboutin 新作
Colors are strictly Christian Louboutin from pewter to gray green. Only the younger Emporio line had spurts of bright red and yellow.His evening wear also dared to move ahead. Instead of the stiff tuxedo, he presented models in velvet pajama suits, whose at-home mood was underlined by the slippers on their feet.
By Christian Louboutin 通販 on
1/22/2010 12:49 AM
|
Re: WPF Hackery! Part II
Shares of Abercrombie & Fitch Co. fell Monday after a Caris & Co. analyst issued a downbeat report and lowered her estimates for the clothing retailer's fourth-quarter and full-year profit.
Ads:discount Abercrombie|abercrombie new arrival|abercrombie store|カップル Tシャツアバクロ 激安
Ads:abercrombie shop|アバクロ セール|アバクロ レディース|アバクロ ダウンベストアバクロ ダウン
Caris analyst Dorothy Lakner said Abercrombie's sales were worse than expected in November and December, and that left investors to "wonder where the light at the end of this tunnel might be."
Abercrombie shares fell $1.19, or 3.5 percent, to $32.39 in afternoon trading. The company is based in New Albany, Ohio.
Lakner said the chain's performance has been suffering mostly in the U.S.
An international expansion is providing some good news. She said Abercrombie had attractive products for the holidays but sparse inventory. She said its Hollister brand fared worst of all.
Lakner now sees Abercrombie earning 81 cents per share in the fourth quarter, compared with her earlier forecast for 97 cents and an average estimate from analysts polled by Thomson Reuters for 91 cents.
Ads:abercrombie clothing|アバクロ アウトレット|アバクロ カップル|激安カップル|abercrombie shop
Ads:abercrombie online store|abercrombie online shop|abercrombie online shop|abercrombie store
Caris lowered her annual profit estimate for 2009 to 89 cents from $1.06 and for 2010 to $1.50 per share from $1.60.
Analysts on average expect Abercrombie to earn 95 cents per share in 2009 and $1.71 per share in 2010.
By Christian Louboutin 通販 on
1/22/2010 12:50 AM
|
Re: WPF Hackery! Part II
Police on Wednesday were tracking a series of car break-ins, during the past month.
"The whole passenger front window had been shattered, and we knew immediately that my purse had been taken. It was on the passenger floor," said Shannon Reed, who was victimized by thieves.
Reed's purse was in plain view and the thieves took advantage of the easy target, 10TV's Tino Ramos reported.
Ads:クラシックトール,アグ 梨花,UGG ショート,腕時計コピー,ルイヴィトンコピー,コピールイヴィトン
Ads:アバクロ ホリスター,アバクロ 通販,アバクロ レディース,アバクロ 通販,アグ 店舗,UGG アグReed said she knew better. "Frustration, violation," she said. "You feel stupid for doing something like that."
Police said Reed is not the only victim; during the past several weeks more than a dozen cars have been broken into, with thieves stealing everything from cell phones to cameras.
The thefts have happened in parking lots around the city and businesses are now posting signs reminding people to secure their valuables, Ramos reported.
pop:ファッショントール,UGG 通販,UGG ショート,アバクロ メンズ,アバクロ ジャケット,人気 ブランド靴
pop:UGG キッズ,アグ 激安,UGG 取扱店,アグ 販売店,UGGブーツ,UGG 新作,UGG メンズ,IWC時計
It only took Westerville Detective Larry French minutes to find exposed valuables and said people have to use common sense to protect themselves, which means keeping those things out of sight.
hot:ブランドコピー,アバクロ キッズ,アバクロ アウトレット,アバクロ 店舗,アバクロ ダウン
fashon:アバクロ キッズ,アバクロ 新作,アバクロ 激安,アバクロ コピー,アバクロ セール,アバクロ 日本
"Here's some Ugg boots - those are $200 a pair," French said.
French also found keys left in one vehicle. "All someone has to do is shatter one of these windows, take those keys and drive away in this town car," French said.
Police are still trying to identify the men seen using one of the stolen credit cards in a store surveillance video, but have not yet identified any suspects.
Watch 10TV News HD and refresh 10TV.com for additional information.
By Christian Louboutin 通販 on
1/22/2010 12:51 AM
|
Re: WPF Hackery! Part II
Your blog is so educationally based that I was just afraid to read it as not to feel unqualified.
By flash development on
2/8/2010 1:07 AM
|
|
Re: WPF Hackery! Part II
Guy Beard didn't invent jewelry. The early inhabitants of the South African coast beaded Nassarius shells over 100,000 years ago. It wasn't long after that Guy started to look for better ways to handcraft fine jewelry. Now, with dozens of patents and trademarks to his credit, every handmade piece is noted for its creative custom design, superior artistry and durable beauty. Guy Beard Jewelry Collections are made to last a lifetime and designed to reflect the unique lifestyle of their owner. Check out our website's handcrafted jewelry page for the latest gold cable, Turk's Head, nouveau braid, laser engraved and cast jewelry designs. It's easy to see why over 900 retailers across the United States have sold designer jewelry pieces handcrafted by Guy Beard.
By Handcrafted Jewelry on
2/25/2010 7:36 AM
|
|
Re: WPF Hackery! Part II
By replicawatches on
3/7/2010 6:43 PM
|
|
|
|
|
|
|
|
ed hardy
ED Hardy Hoodies ED Hardy Hoodies Ed Hardy Swimwear Ed Hardy Swimwear ed hardy tops ed hardy tops ed hardy shoes ed hardy shoes ed hardy t shirt ed hardy t shirt ed hardy shirts ed hardy shirts christian audigier christian audigier ed hardy kids ed hardy kids Ed Hardy Sunglasses Ed Hardy Sunglasses ED Hardy belts ED Hardy belts ed hardy Bags ed hardy Bags ed hardy purse ed hardy purse ed hardy mens ed hardy mens ed hardy womens d hardy womens ed hardy mens shirts ed hardy mens shirts ed hardy mens tops ed hardy mens tops ed hardy mens hoodies d hardy mens hoodies ed hardy mens swim trunks ed hardy mens swim trunks ed hardy mens shoes ed hardy mens shoes ed hardy womens swimwear ed hardy womens swimwear ed hardy womens t shirt ed hardy womens t shirt ed hardy womens tops ed hardy womens tops ed hardy womens pants ed hardy womens pants ed hardy womens hoodies ed hardy womens hoodies ed hardy womens shoes ed hardy womens shoes ed hardy womens clothing ed hardy womens clothing
By ed hardy on
3/15/2010 9:22 PM
|
Re: WPF Hackery! Part II
「GUCCI(グッチ)」の歴史を象徴するアイコン的存在でもある「bamboo(バンブー)」。そのヒストリーやアーカイブが揃う「THE BAMBOO」展がグッチ銀座6階ギャラリーにて行われる。
store:グッチ バッグ|グッチ 財布|ミュウミュウ バッグ|ミュウミュウ 財布|ルイヴィトン バッグ|グッチ
shop:ルイヴィトン 直営店|ルイヴィトン 激安|ブランド コピー|ブランド 激安 コピー|グッチ コピー
1940年代後半にフィレンツェの職人達によって考案され誕生したバンブーバッグ。戦時下の物資不足に対応しながらグッチのエクスクルーシブな品質を守るために職人達が考えだしたバンブーハンドルは、当時革新的なアイデアだった。第二次世界大戦後、イタリアのクラフトマンシップとデザインは世界の注目を集め、バンブーバッグもその象徴的存在となった。バンブーからインスピレーションを得たデザインは、スカーフや傘の持ち手、ウォッチ、ジュエリーなど、幅広く展開され、バンブーを模ったウィットに富んだゴールドのスティレットヒールも登場した。時代を超え、その時々のファッションの中で新しいデザインとして存在感を主張し続ける、グッチの象徴的アイテムとして今もなお愛され続けている。
fashion:09年新作·バッグ|09年新作·財布|エルメス[Hermes] バッグ|エルメス 財布|グッチバッグ
hot:グッチ 店舗|グッチ コピー|ルイヴィトン 財布|GUCCI グッチ|グッチ バッグ|グッチ キーケース
同展では世界のセレブリティに愛されてきたヒストリーやアーカイブの展示をはじめ、映像にてバンブーバッグの製作工程を初公開する。同時に、グッチ銀座1階ではイタリアフィレンツェにあるレザーグッズファクトリーのクラフトマンシップを直接目にすることができる「アルチザン コーナー」が2010年3月14日(日)まで開催されている。 グッチが誇るクラフトマンシップ、メイド?イン?イタリーへのこだわりを体感してほしい。
Ads:グッチ 財布|COACH コーチ|コーチ バッグ|コーチ 財布|ルイヴィトン 質屋|GUCCI グッチ キーケース
new:エルメス[Hermes]|ルイヴィトン 通販|ルイヴィトン コピー|ルイヴィトン 財布 コピー|ミュウミュウ
By ルイヴィトン 財布 コピー on
3/15/2010 11:55 PM
|
Re: WPF Hackery! Part II
abercrombie, abercrombie and fitch, abercrombie and fitch uk, abercrombie fitch uk, Abercrombie outlet, Abercrombie and fitch outlet, Abercrombie online, Abercrombie and fitch online, Abercrombie clothing, Abercrombie and fitch clothing, ed hardy uk, ed hardy clothing, Christian Audigier, abercrombie, アバクロ 銀座, アバクロ 通販, アバクロ, アバクロ 激安, アバクロ 店舗, アバクロ コンセント abercrombie milano, abercrombie italia, abercrombie london, abercrombie fitch london, abercormbie and fitch london, Abercrombie and fitch outlet, Abercrombie online, Abercrombie and fitch online, Abercrombie clothing, Abercrombie and fitch clothing
By abercrombie on
3/16/2010 6:15 PM
|
Re: WPF Hackery! Part II
[url=http://www.ebags-replica.com]replica handbags[/url][url=http://www.ebags-replica.com]louis vuitton replica handbags[/url][url=http://www.ebags-replica.com]replica purses[/url] [url=http://www.ebags-replica.com/LOUIS-VUITTON.htm]Replica LOUIS VUITTON[/url][url=http://www.ebags-replica.com/Replica-Handbags/GUCCI-Gucci-Handbags-53-1.htm]Gucci Handbags[/url][url=http://www.ebags-replica.com/Replica-Handbags/PRADA-Prada-Handbags-65-1.htm]Prada Handbags[/url][url=http://www.ebags-replica.com/Replica-Handbags/BURBERRY-Burberry-Handbag-161-1.htm]Burberry Handbag[/url][url=http://www.ebags-replica.com/Replica-Handbags/HERMES-Hermes-Handbags-71-1.htm]Hermes Handbags[/url][url=http://www.ebags-replica.com/Replica-Handbags/BELTS-Hermes-Belts-96-1.htm]Hermes Belts[/url][url=http://www.ebags-replica.com/Replica-Handbags/BELTS-Gucci-Belts-196-1.htm]Gucci Belts[/url][url=http://www.ebags-replica.com/Replica-Handbags/BELTS-Louis-Vuitton-Belts-93-1.htm]Louis Vuitton Belts[/url] [url=http://www.ebags-replica.com/Replica-Handbags/WALLETS-Louis-Vuitton-Wallets-197-1.htm]Louis Vuitton Wallets[/url] [url=http://www.ebags-replica.com/Replica-Handbags/WALLETS-Hermes-Wallets-198-1.htm]Hermes Wallets[/url][url=http://www.ebags-replica.com/Replica-Handbags/WALLETS-Gucci-Wallets-199-1.htm]Gucci Wallets[/url][url=http://www.ebags-replica.com/Replica-Handbags/SCARF-Burberry-Scarf-251-1.htm]Burberry Scarf[/url] [url=http://www.ebags-replica.com/Replica-Handbags/SCARF-Louis-Vuitton-Scarf-210-1.htm]Louis Vuitton Scarf[/url] [url=http://www.ebags-replica.com/Replica-Handbags/SCARF-Hermes-Scarf-211-1.htm]Hermes Scarf[/url][url=http://www.ebags-replica.com/Replica-Handbags/JEWELRY-Louis-Vuitton-Bracelets-270-1.htm]Louis Vuitton Bracelets[/url][url=http://www.ebags-replica.com/Replica-Handbags/JEWELRY-Hermes-Bracelets-271-1.htm]Hermes Bracelets[/url]
By ebags replica on
3/16/2010 7:34 PM
|
|
|
|
|
|
|
Re: WPF Hackery! Part II
I just tried it awhile ago and it works great! We needed alphablending so I changed the PixelFormats.Bgr32 to PixelFormats.Bgra32 and it worked like perfectly.
I wish we didn't need to do hacks like this, but until Microsoft gives us better access to what is under the covers we are going to have to.
-Eric
By Eric Meyer on
5/21/2007 10:13 AM
|
Re: WPF Hackery! Part II
I have a co-worker who showed me how you could access private fields in C# via reflection. I come mostly from a Java background were this would be a security violation, is this really allowed by the CLR, you have acess to any private fields if you use reflection?
By Augusto on
5/21/2007 11:23 AM
|
Re: WPF Hackery! Part II
Nice code, here's something that might improve performance, you're doing a call to SetBufferInfo within your BufferPointer getter. Also, you should store your MethodInfo and Type objects in static variables so you only need to initialize them once. Other than that really great.
Also, the only security concern with reflection is having code that is not privileged reflecting and executing a function that is. (For instance a service that is running with rights allowing it for instance to reset user passwords for your application). Like Jeremiah noted, this can be prevented using CAS.
Java does indeed allow reflection, it's how EJBs and JavaBeans in general are done. Indeed there were a few interesting quirks in the first version of J2EE where code installed in an EJB container would be able to use it to raise its privileges through reflection.
By Mike Brown on
5/22/2007 2:53 PM
|
Re: WPF Hackery! Part II
We want to make sure that the platform let's you do what you want without having to resort to things like this. It cannot be guaranteed that non-publc API access will continue to work compatibly in future versions. I'll make sure that I point this out to the right people on our team so that we can handle your scenarios better in the futre. Thanks, Rob Relyea Program Manager, WPF Team http://rrelyea.spaces.live.com
By Rob Relyea on
5/22/2007 3:38 PM
|
Re: WPF Hackery! Part II
I was wondering if you were able to post an actual example of this in use (ie following on from getting the pointer to the buffer). I am struggling to get it working.
By Steve Cassidy on
6/2/2007 10:09 PM
|
Re: WPF Hackery! Part II
I make use of this class in the other project I posted about putting Win32 controls in the WPF compositing engine. It should provide for a decent example.
Here is the URL.
http://jmorrill.hjtcentral.com/Home/tabid/428/EntryID/20/Default.aspx
By JMoney on
6/4/2007 8:47 AM
|
Re: WPF Hackery! Part II
Hi Rob,
I frequent your blog quite often!
I know this type of code isn't really condoned, but I felt the functionality is so important and necessary that I had to share.
Thanks for listening to this "cry-for-help". I think there are a lot of people out there starving for low-level access to WPF/MIL. Before I wrote this code, I think I would have sold my soul for a buffer pointer.
-Jer
By JMoney on
5/22/2007 8:29 PM
|
Re: WPF Hackery! Part II
I'm not really a Java expert, but quick Google search shows that Java has the same behavior with reflection.
I do not believe this to be a security violation (unless you see it as an application level security violation for 3rd party libraries). DotNet (and presumably Java), seem to treat access modifiers as language constructs, not a runtime principal.
In any case, I think you can configure CAS to turn off reflection, disallowing such access (or not, I know very little about CAS and probably shouldn't be remarking about it).
By JMoney on
5/21/2007 5:52 PM
|
Re: WPF Hackery! Part II
I'm glad it worked for you Eric! I would double check my work a little and make sure there is no memory/handle leak. 90% of that class was done via guess-and-check, so there's no guarentees.
-Jer
By JMoney on
5/21/2007 5:58 PM
|
|
|
|
|