Einlesen tu ich das ganze momentan mit diesem Code:
BitmapImage bmi = new BitmapImage();
bmi.UriSource = new Uri(@"C:\test\raw\jimten_1_02.DCR");
using (MemoryStream outStream = new MemoryStream())
{
BitmapEncoder enc = new BmpBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(bmi));
enc.Save(outStream);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(outStream);
bmp.Save(@"C:\test\raw\work.JPG", ImageFormat.Jpeg);
}Wenn ich das ganze dann ausführe bekomme ich bei
enc.Frames.Add(BitmapFrame.Create(bmi));
folgende Fehlermeldung:
InvalidOperationException wurde nicht behandelt / Das Objekt muss zum Durchführen des Vorgangs zunächst initialisiert werden.
Für die .cr2 Files benutze ich folgende Methode:
public Bitmap convert()
{
using (Stream stm = File.Open(@"C:\test\raw\jimten_1_01.DCR", FileMode.Open, FileAccess.Read))
{
System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Media.Imaging.BitmapFrame.Create(
stm, System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad);
double newWidthRatio = pictureBox1.Width / (double)bitmapSource.PixelWidth;
double newHeightRatio = ((pictureBox1.Width * bitmapSource.PixelHeight) / (double)bitmapSource.PixelWidth) / (double)bitmapSource.PixelHeight;
System.Windows.Media.Imaging.BitmapSource transformedBitmapSource =
new System.Windows.Media.Imaging.TransformedBitmap(bitmapSource, new System.Windows.Media.ScaleTransform(newWidthRatio, newHeightRatio));
int width = transformedBitmapSource.PixelWidth;
int height = transformedBitmapSource.PixelHeight;
int stride = width * ((transformedBitmapSource.Format.BitsPerPixel + 7) / 8);
textBox1.Text = "WidthRatio " + newWidthRatio + " HeigthRatio " + newHeightRatio + " Width " + width + " Height " + height;
byte[ bits = new byte[height * stride];
transformedBitmapSource.CopyPixels(bits, stride, 0);
unsafe
{
fixed (byte* pBits = bits)
{
IntPtr ptr = new IntPtr(pBits);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, stride, System.Drawing.Imaging.PixelFormat.Format32bppPArgb, ptr);
pictureBox1.Image = bitmap;
return bitmap;
}
}
}
}Wenn ich die Methode mit .dcr statt .cr2 Files aufrufe bekomme ich in dieser Zeile eine Fehlermeldung:
System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Media.Imaging.BitmapFrame.Create(
stm, System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.OnLoad);
NotSupportedException wurde nicht behandelt / Es wurde keine passende Imagingkomponente zum Abschließen dieses Vorgangs gefunden.
Soweit ich bisher gelesen habe geht es wohl nur so, dass ich mir das .dcr File in ein byte[ array schreibe, und aus diesem byte[ array dann wieder ein image erstelle.
gruß eli