Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8481237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:30:43+00:00 2026-06-10T19:30:43+00:00

I am new learner to WPF. here I got a question. I have a

  • 0

I am new learner to WPF. here I got a question.
I have a image, width:360, height:360. Here I want to crop this image like below:

( 0,0 ) to (120,120) save to the first ImageSource object,

(120,0 ) to (240,120) save to the second ImageSource object,

(240,0 ) to (360,120) save to the third ImageSource object;,

……

pls see more details in below picture:
enter image description here

My code sample below:

    private void CutImage(string img)
    {
        int iLeft = 0;
        int iTop = 0;
        int count = 0;

        Image thisImg = new Image();
        BitmapImage src = new BitmapImage();
        src.BeginInit();
        src.UriSource = new Uri(img, UriKind.Relative);
        src.CacheOption = BitmapCacheOption.OnLoad;
        src.EndInit();
        thisImg.Source = src;

        for (int i = 0; i < 3; i++)
        {
            iTop = i * 120;
            for (int j = 0; j < 3; j++)
            {
                iLeft = j * 120;

                Canvas canvas = new Canvas();

                Rectangle destRect = new Rectangle();
                destRect.SetValue(Canvas.LeftProperty, (double)0);
                destRect.SetValue(Canvas.TopProperty,(double)0);
                destRect.Width = destRect.Height = 120;

                Rect srcRect = new Rect();
                srcRect.X = iLeft;
                srcRect.Y = iTop;
                srcRect.Width = srcRect.Height = 120;


                thisImg.Clip = new RectangleGeometry(srcRect);

                thisImg.Clip.SetValue(Canvas.TopProperty, (double)iTop);
                thisImg.Clip.SetValue(Canvas.LeftProperty, (double)iLeft);
                thisImg.Clip.SetValue(Canvas.WidthProperty, (double)120);
                thisImg.Clip.SetValue(Canvas.HeightProperty,(double)120);

                objImg[count++] = (ImageSource)thisImg.GetValue(Image.SourceProperty);
            }
        }
      }

but it doesn’t work as I expected, seems that all the ImageSource objects store the same image, not the corping part. Any one can help me ? thx.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:30:45+00:00Added an answer on June 10, 2026 at 7:30 pm

    Use CroppedBitmap to do this:

    private void CutImage(string img)
    {
        int count = 0;
    
        BitmapImage src = new BitmapImage();
        src.BeginInit();
        src.UriSource = new Uri(img, UriKind.Relative);
        src.CacheOption = BitmapCacheOption.OnLoad;
        src.EndInit();
    
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                objImg[count++] = new CroppedBitmap(src, new Int32Rect(j * 120, i * 120, 120, 120));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to PHP and MySQL, have heard amazing things about this website from Leo
I am a new visual basic learner and I already have some difficulties in
Hello stackoverflow pals.I am a new rails learner. My question is: I am listing
I am a very new zend framework and phpunit test learner. I have a
I am new to WPF and Prism, but I already learned that you have
apologies, really new C# learner. my application will have these windows: a main display
I know this could be a subjective question, but I want to know your
As some of you have discovered, a new feature (?) appeared WPF 4, where
I am a new learner to C++. I have a text file, its contents
I am a new java learner. Recently I was reading Generic programming and got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.