Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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);
            }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...