Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Foto in der Größe anpassen und in das Clipboard kopieren

27.10.2019 (👁159)


Im folgenden C# Code wird ein Foto geladen, in der Größe angepasst und anschließend in den Zwischenspeicher kopiert.

Hintergrund: in dem Code soll in Word ein Foto per Word-Addin geladen werden. Vor dem Einfügen in das Word-Dokument wird das Foto per C# zur Laufzeit in der Größe angepasst und dann zur Weiterverarbeitung in den Word-Clipboard gespeichert.

       public static void load_Photo_compressed_to_Clipboard(string input_Image_Path, int setLength)

        {

            //---------------< Image_resize() >---------------

            Bitmap source_Bitmap = new Bitmap(input_Image_Path);

            double dblWidth_origial = source_Bitmap.Width;

            double dblHeigth_origial = source_Bitmap.Height;

            //< check orientation >

            bool IsOrientation_Horizontal = (dblWidth_origial > dblHeigth_origial) ? true : false;

            //</ check orientation >

            int new_Height = 0;

            int new_Width = 0;

            double zoom_factor = 1;

            if (IsOrientation_Horizontal == true)

            {

                new_Width = setLength;

                zoom_factor = new_Width / dblWidth_origial;

                new_Height = (int)(dblHeigth_origial * zoom_factor);

            }

            else

            {

                new_Height = setLength;

                zoom_factor = new_Height / dblHeigth_origial;

                new_Width = (int)(dblWidth_origial * zoom_factor);

            }

            Image outImage = new Bitmap(source_Bitmap, new_Width, new_Height);

            var t = new Thread((ThreadStart)(() =>

            {

                Clipboard.SetImage(outImage);

            }));

            t.SetApartmentState(ApartmentState.STA);

            t.Start();

            t.Join();

            //---------------</ Image_resize() >---------------

        }

C# Code