Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

c# - Loading Canon .CR2 files in .NET

I am trying to process Canon RAW .CR2 files using C#. My code is as follows:

BitmapDecoder bmpDec = BitmapDecoder.Create(new Uri(origFile), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
BitmapEncoder bmpEnc = new BmpBitmapEncoder();
bmpEnc.Frames.Add(bmpDec.Frames[0]);
Stream ms = new MemoryStream();
bmpEnc.Save(ms);
Image srcImage = Bitmap.FromStream(ms);

The first few lines seem to run without a hitch, but the line

bmEnc.Save(ms);

just hangs without completing and without raising any exception.

Has anyone had any success with this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

W8.1 or W7 after applying https://www.microsoft.com/en-us/download/details.aspx?id=26829 seems to work well

var files = Directory.GetFiles(@"D:DCIM","*.CR2");
            for(var i = 0; i < files.Length; i++) {
                Console.Write("{0,-4}: {1} => ", i, files[i]);
                var bmpDec = BitmapDecoder.Create(new Uri(files[i]), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
                var bmpEnc = new JpegBitmapEncoder();
                bmpEnc.QualityLevel = 100;
                bmpEnc.Frames.Add(bmpDec.Frames[0]);
                var oldfn = Path.GetFileName(files[i]);
                var newfn = Path.ChangeExtension(oldfn, "JPG");
                using(var ms = File.Create(Path.Combine(@"D:DCIM100CANON", newfn), 10000000)) {
                    bmpEnc.Save(ms);
                }
                Console.WriteLine(newfn);
            }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...