Usually when you try to use BitmapImage, Image, WriteableImage in other than UI thread, you'll get exception. This is because these classes are derived from System.Windows.Threading.DispatcherObject, which is blocked access from other than UI thread. There exists an extension to WriteableBitmap, LoadJpeg, which is works fine in thread, but you have to create WriteableBitmap object on main UI thread.
- using System.Windows;
- using System.Windows.Media.Imaging;
- using System.IO;
- using System.Threading;
- namespace ImageHelpers
- {
- public delegate void ImageLoadedDelegate(WriteableBitmap wb, object argument);
- public class ImageThread
- {
- public event ImageLoadedDelegate ImageLoaded;
- public ImageThread()
- {
- }
- public void LoadThumbAsync(Stream src, WriteableBitmap bmp, object argument)
- {
- ThreadPool.QueueUserWorkItem(callback =>
- {
- bmp.LoadJpeg(src);
- src.Dispose();
- if (ImageLoaded != null)
- {
- Deployment.Current.Dispatcher.BeginInvoke(() =>
- {
- ImageLoaded(bmp, argument);
- });
- }
- });
- }
- }
- }
Using scenario:
- ImageThread imageThread = new ImageThread();
- private void Init()
- {
- imageThread.ImageLoaded += LoadFinished;
- }
- void LoadFinished(WriteableBitmap bmp, object arg)
- {
- Imgage1.Source = bmp;
- }
- void DeferImageLoading( Stream imgStream )
- {
- // we have to give size
- var bmp = new WriteableBitmap(80, 80);
- imageThread.LoadThumbAsync(imgStream, bmp, this);
- }
great
ReplyDeleteHi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from .Net Core Training in Chennai. or learn thru .Net Core Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
ReplyDeleteor Es6 Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.
With the Internet, nearly everything has been a great deal simpler. Correspondences were streamlined. Examining for articles and answers is less demanding than it was previously.best background investigation service
ReplyDeleteI found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work... JPEG Optimizer
ReplyDeleteAfter reading this web site I am very satisfied simply because this site is providing comprehensive knowledge for you to audience.
ReplyDeleteThank you to the perform as well as discuss anything incredibly important in my opinion. We loose time waiting for your next article writing in addition to I beg one to get back to pay a visit to our website in
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
I am really enjoyed a lot when reading your well-written posts. It shows like you spend more effort and time to write this blog. I have saved it for my future reference. Keep it up the good work.
ReplyDeletehonor mobile service center
honor mobile service centre in Chennai
honor service center near me
honor service
honor service centres in chennai
This is an awesome blog for the people who are really seeking information for this technology.
ReplyDeleteTOEFL Coaching in Chennai
TOEFL Center in Chennai
Best Spoken English Classes in Chennai
French Language Classes in Chennai
pearson vue exam centers in chennai
German Classes in Chennai
IELTS Coaching in Tnagar
IELTS Coaching in OMR
The article is so informative. This is more helpful for our
ReplyDeletesoftware testing training courses
selenium classes
software testing course fees in chennai
Thanks for sharing.
This is the first & best article to make me satisfied by presenting a good content. I feel so happy and delighted. I thank you so much for this article.
ReplyDeleteBest Big Data Analytics and Hadoop Online Certification Course Training and Placement in Chennai
Best Data Science Online Certification Course Training and Placement in Chennai
Learn Best Android Application Development Programming Online Course Training and Placement Institute in Chennai
Learn Best AngularJS 4 and 2 Course Online Training and Placement Institute in Chennai
Learn Digital Marketing Course Training and Placement Institute in Chennai
Learn Seo Course Training Institute Center in Chennai for Beginners
IT Company in Ahmedabad
ReplyDeleteThank you for this informative blog
ReplyDeleteTop 5 Data science training in chennai
Data science training in chennai
Data science training in velachery
Data science training in OMR
Best Data science training in chennai
Data science training course content
Data science syllabus
Data science courses in chennai
Data science training institute in chennai
Data science online course
Data science with python training
Data science with R training
Superb blog! I loved this blog. This content was very valuable for freshers and definitely, it will use in my future. Keep sharing...
ReplyDeleteOracle DBA Training in Chennai
oracle dba training institutes in chennai
Job Openings in Chennai
Linux Training in Chennai
Power BI Training in Chennai
Oracle Training in Chennai
Unix Training in Chennai
Social Media Marketing Courses in Chennai
Tableau Training in Chennai
Oracle DBA Training in Tambaram
thanks for your information really good and very nice web design company in velachery
ReplyDeleteFlying Shift - Packers & Movers in Bhopal
ReplyDeleteBest Catering Services in Chennai | Best Catering Service in Chennai | Best Catering Services Chennai | Best Catering Service Chennai | Best Catering Services | Best Catering Service
ReplyDeletenice blog
ReplyDeleteget best placement at VSIPL
digital marketing services
web development company
seo network point
Learned a lot from your post and it is really good. Share more tech updates regularly.web design company in velachery
ReplyDeleteThanks for sharing valuable information.
ReplyDeletedigital marketing training
digital marketing in Chennai
digital marketing training in Chennai
digital marketing course in Chennai
digital marketing course training in omr
digital marketing certification
digital marketing course training in velachery
digital marketing training and placement
digital marketing courses with placement
digital marketing course with job placement
digital marketing institute in Chennai
digital marketing certification course in Chennai
digital marketing course training in Chennai
Digital Marketing course in Chennai with placement
Soma pill is very effective as a painkiller that helps us to get effective relief from pain. This cannot cure pain. Yet when it is taken with proper rest, it can offer you effective relief from pain.
ReplyDeleteThis painkiller can offer you relief from any kind of pain. But Soma 350 mg is best in treating acute pain. Acute pain is a type of short-term pain which is sharp in nature. Buy Soma 350 mg online to get relief from your acute pain.
https://globalonlinepills.com/product/soma-350-mg/
Buy Soma 350 mg
Soma Pill
Buy Soma 350 mg online
Buy Soma 350 mg online
Soma Pill
Buy Soma 350 mg
Nice information, want to know about Selenium Training In Chennai
ReplyDeleteSelenium Training In Chennai
Data Science Training In Chennai
Protractor Training in Chennai
jmeter training in chennai
Rpa Training Chennai
Rpa Course Chennai
Selenium Training institute In Chennai
Python Training In Chennai
Rpa Training in Chennai
ReplyDeleteRpa Course in Chennai
Blue prism training in Chennai
Data Science Training In Chennai
ReplyDeleteData Science Course In Chennai
Data Science Course In Chennai
Your articles really impressed for me,because of all information so nice.sap tm training in bangalore
ReplyDeleteLinking is very useful thing.you have really helped lots of people who visit blog and provide them use full information.sap simple logistics training in bangalore
ReplyDeleteBeing new to the blogging world I feel like there is still so much to learn. Your tips helped to clarify a few things for me as well as giving.sap wm training in bangalore
ReplyDeleteReally it was an awesome article,very interesting to read.You have provided an nice article,Thanks for sharing.sap ewm training in bangalore
ReplyDeleteThis is really an awesome post, thanks for it. Keep adding more information to this.sap mm training in bangalore
ReplyDeleteThanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts.hadoop training institutes in bangalore
ReplyDeleteNice infromation
ReplyDeleteSelenium Training In Chennai
Selenium course in chennai
Selenium Training
Selenium Training institute In Chennai
Best Selenium Training in chennai
Selenium Training In Chennai
I think this is one of the most significant information for me. And i’m glad reading your article. Thanks for sharing!
ReplyDeleteUpgrade your career Learn AWS Training from industry experts get Complete hands-on Training, Interview preparation, and Job Assistance at Bangalore Training Academy Located in BTM Layout.
Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck…
ReplyDeleteUpgrade your career Learn SharePoint Developer Training in Bangalore from industry experts get Complete hands-on Training, Interview preparation, and Job Assistance at Softgen Infotech.