قص وتغيير حجم EPS

حل واجهة برمجة تطبيقات C++ الأصلي لإدارة حجم صور EPS.

 

أصبح تحويل صورة EPS الخاصة بك أسهل من أي وقت مضى! باستخدام Aspose.Page لـ C++، يمكنك قص ملفات EPS أو تغيير حجمها لتلائم مواصفاتك الدقيقة في بضعة أسطر من التعليمات البرمجية. هل تريد تكبيرها؟ لا مشكلة. هل تحتاجها أصغر؟ لقد قمنا بتغطيتك. تتيح لك واجهة برمجة التطبيقات الخاصة بنا لـ C++ قياس صورتك بدقة، مما يضمن ملاءمتها لرؤيتك بشكل مثالي. ولكن لماذا قد ترغب في قص أو تغيير حجم صورة EPS؟

  • إذا كنت تقوم بتصميم تخطيط لمستند مطبوع أو رقمي، فقد تحتاج إلى تغيير حجم صورة EPS لتلائم أبعاداً محددة.
  • من خلال تقليل حجم الصورة، يمكنك تصغير حجم الملف، مما يسهل مشاركته أو تحميله أو طباعته. يتم أيضاً تحميل ملفات الصور الأصغر حجماً بشكل أسرع على مواقع الويب وفي المستندات الرقمية، مما يعزز تجربة المستخدم.
  • يمكن أن يساعد القص في التخلص من الأجزاء المشتتة للانتباه أو غير ذات الصلة بالصورة، مع تركيز الانتباه على العناصر الرئيسية، ويمكنه أيضاً تغيير نسبة العرض إلى الارتفاع في الصورة لتناسب احتياجات التصميم الخاصة بك بشكل أفضل. لذلك يمكن للقص الدقيق تحسين التكوين العام والجاذبية المرئية للصورة.
  • يمكن أن يساعد كل من القص وتغيير الحجم في تحسين الصورة لاستخدام الويب، مما يضمن تحميلها بسرعة وظهورها بشكل جيد على أحجام الشاشات المختلفة.

يوفر لك Aspose.Page وظائف لإدارة حدود ملفات EPS بسهولة. باستخدام واجهة برمجة التطبيقات هذه، يمكنك قياس أو قص الصور باستخدام C#. لمعرفة المزيد حول كيفية التعامل مع ملفات EPS ، اتبع الوثائق. لمشاهدة الإصدار المباشر من الوظيفة، جرب التطبيقات عبر الأنظمة الأساسية EPS Crop و EPS Resize .

لاستخدام الوظيفة، تحتاج أولاً إلى الحصول على الحل:

  • افتح مدير حزم NuGet، وابحث عن Aspose.Page وقم بتثبيته. يمكنك أيضاً استخدام الأمر التالي من وحدة تحكم مدير الحزم.

Package Manager Console Command

    PM> Install-Package Aspose.Page

خطوات تغيير حجم صورة EPS.

يوضح المثال أدناه عملية تغيير حجم .eps بالوحدات المختارة - النقاط. الترتيب هو:

  1. قم بتهيئة كائن PsDocument باستخدام تدفق إدخال يحتوي على ملف EPS.
  2. قم بتعريف الحجم الحالي للصورة باستخدام الطريقة الثابتة ExtractEpsSize() .
  3. قم بإنشاء تدفق إخراج لملف EPS الناتج.
  4. قم بتغيير حجم كائن PsDocument بحجم جديد بالنقاط باستخدام الطريقة الثابتة ResizeEps() .
  5. احفظ ملف EPS الذي تم تغيير حجمه.
تغيير حجم EPS
    // The path to the documents directory.
    System::String dataDir = RunExamples::GetDataDir_WorkingWithEPS();
    
    //Create an input stream for EPS file
    {
        System::SharedPtr<System::IO::Stream> inputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
        // Clearing resources under 'using' statement
        System::Details::DisposeGuard<1> __dispose_guard_1({ inputEpsStream});
        // ------------------------------------------
        
        try
        {
            //Initialize PsDocument object with input stream
            System::SharedPtr<PsDocument> doc = System::MakeObject<PsDocument>(inputEpsStream);
            
            //Get size of EPS image
            System::Drawing::Size oldSize = doc->ExtractEpsSize();
            
            //Create an output stream for resized EPS
            {
                System::SharedPtr<System::IO::Stream> outputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output/" + u"output_resize_points.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
                // Clearing resources under 'using' statement
                System::Details::DisposeGuard<1> __dispose_guard_0({ outputEpsStream});
                // ------------------------------------------
                
                try
                {
                    //Increase EPS size in 2 times and save to the output stream
                    doc->ResizeEps(outputEpsStream, System::Drawing::SizeF(static_cast<float>(oldSize.get_Width() * 2), static_cast<float>(oldSize.get_Height() * 2)), Aspose::Page::Units::Points);
                }
                catch(...)
                {
                    __dispose_guard_0.SetCurrentException(std::current_exception());
                }
            }
        }
        catch(...)
        {
            __dispose_guard_1.SetCurrentException(std::current_exception());
        }
    }

يوضح المثال أدناه عملية القص بدلاً من تغيير حجم .eps بالوحدات المختارة - النقاط. الترتيب هو:

  1. قم بتهيئة كائن PsDocument باستخدام تدفق إدخال يحتوي على ملف EPS.
  2. قم بتعريف المربع المحيط الحالي للصورة باستخدام الطريقة الثابتة ExtractEpsBoundingBox() .
  3. قم بإنشاء تدفق إخراج لملف EPS الناتج.
  4. قم بقص كائن PsDocument بمربع محيط جديد باستخدام الطريقة الثابتة CropEps() .
  5. احفظ ملف EPS المقصوص.
قص EPS
    // The path to the documents directory.
    System::String dataDir = RunExamples::GetDataDir_WorkingWithEPS();
    
    //Create an input stream for EPS file
    {
        System::SharedPtr<System::IO::Stream> inputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"input.eps", System::IO::FileMode::Open, System::IO::FileAccess::Read);
        // Clearing resources under 'using' statement
        System::Details::DisposeGuard<1> __dispose_guard_1({ inputEpsStream});
        // ------------------------------------------
        
        try
        {
            //Initialize PsDocument object with input stream
            System::SharedPtr<PsDocument> doc = System::MakeObject<PsDocument>(inputEpsStream);
            
            //Get initial bounding box of EPS image
            System::ArrayPtr<int32_t> initialBoundingBox = doc->ExtractEpsBoundingBox();
            
            //Create an output stream for resized EPS
            {
                System::SharedPtr<System::IO::Stream> outputEpsStream = System::MakeObject<System::IO::FileStream>(dataDir + u"output/" + u"output_crop.eps", System::IO::FileMode::Create, System::IO::FileAccess::Write);
                // Clearing resources under 'using' statement
                System::Details::DisposeGuard<1> __dispose_guard_0({ outputEpsStream});
                // ------------------------------------------
                
                try
                {
                    //Create new bounding box
                    //Bounding box is represented by 4 numbers: x0, y0, x, y, where x0 - left margin, y0 - top margin, x - (x0 + width), y - (y0 + height)
                    System::ArrayPtr<float> newBoundingBox = System::MakeArray<float>({260, 300, 480, 432});
                    
                    //Crop EPS image and save to the output stream                    
                    //Croping of image is changing of its bounding box so that new values of bounding box will be within initial bounding box, that is
                    //initialBoundingBox[0] <= newBoundingBox[0] <= initialBoundingBox[2]
                    //initialBoundingBox[1] <= newBoundingBox[1] <= initialBoundingBox[3]
                    //initialBoundingBox[0] <= newBoundingBox[2] <= initialBoundingBox[2]
                    //initialBoundingBox[1] <= newBoundingBox[3] <= initialBoundingBox[3]
                    doc->CropEps(outputEpsStream, newBoundingBox);
                }
                catch(...)
                {
                    __dispose_guard_0.SetCurrentException(std::current_exception());
                }
            }
        }
        catch(...)
        {
            __dispose_guard_1.SetCurrentException(std::current_exception());
        }
    }

EPS ما هو EPS تنسيق الملف

تنسيق EPS (Encapsulated PostScript) هو ملف PostScript يُستخدم لتغليف رسومات صفحة واحدة. يُعد مثالياً للرسومات المتجهة والرسومات النقطية المدمجة. بمجرد استيراد ملف EPS إلى مستند، يصبح غير قابل للتحرير، لذا يُستحسن تحويله إلى تنسيق يمكن التعديل عليه مثل SVG أو PDF قبل الاستخدام.