Autor Beitrag
ebber
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 239
Erhaltene Danke: 1

Win XP, Win 7
C# (VS 2010), Delphi (2007), Expression 4
BeitragVerfasst: So 11.11.12 20:03 
Hallo,

ich versuche ein Grid in ein PNG Bild zu speichern. Das funktioniert auch:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
        public static RenderTargetBitmap GetImage(Grid view)
        {
            Size size = new Size(view.ActualWidth, view.ActualHeight);
            RenderTargetBitmap result = new RenderTargetBitmap((int)size.Width, (int)size.Height, 9696, PixelFormats.Pbgra32);
            DrawingVisual drawingvisual = new DrawingVisual();

            using (DrawingContext context = drawingvisual.RenderOpen())
            {
                context.DrawRectangle(new VisualBrush(view), nullnew Rect(new Point(), size));
                context.Close();
            }

            result.Render(drawingvisual);
            return result;
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            RenderTargetBitmap red = GetImage(grf);

            Stream file = File.OpenWrite("C:\\losch\\eee.png");

            PngBitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(red));
            encoder.Save(file);

            file.Close();
        }


Das Problem ist nun, wenn Teile des Bildes transparent sind, dann wird das Bild wohl einfach hineingezoomt im Sinne von zoom to fill.
Ich habe das Problem mal angehängt, ein Grid mit einem einfachen Strich, einmal transparenter Hintergrund, einmal farbiger. Beide haben jedoch die gleiche Pixelanzahl.

Kann man das irgendwo abstellen? Ich bin mir leider völlig unschlüssig wo das herkommt.

MfG
Einloggen, um Attachments anzusehen!