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 8656929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:23:59+00:00 2026-06-12T15:23:59+00:00

i have a problem with cutting an image. What i want to do is,

  • 0

i have a problem with cutting an image.

What i want to do is, to cut an image in some slices, mostly quadratic.
The code isn’t yet refined for boundary values and shouldn’t cut the whole image in an approriate size, but thats currently not the problem.

My problem is, that the first image which has been cut is really a part of the original image, but the 2nd image (or all after it) are only black. i am just at a dead end and i don’t know what the problem is.

            var sourceImg = System.Drawing.Image.FromFile(args[numcount]);

                int cutsizeHeight = sourceImg.Height < cutsize ? sourceImg.Height : cutsize;
                int cutsizeWidht = sourceImg.Width < cutsize ? sourceImg.Width : cutsize;

                int cutPassesHeight = (int)(sourceImg.Height / cutsize) == 0 ? 1 : (int)(sourceImg.Height / cutsize);
                int cutPassesWidth = (int)(sourceImg.Width / cutsize) == 0 ? 1 : (int)(sourceImg.Width / cutsize);

                for (int i = 0; i < cutPassesHeight; i++)
                {
                    for (int j = 0; j < cutPassesWidth; j++)
                    {
                        var mem = new MemoryStream();
                        var sourcePositionX = i * cutsizeHeight;
                        var sourcePositionY = j * cutsizeWidht;
                        var cutRectangle = new System.Drawing.Rectangle(0, 0, cutsizeWidht, cutsizeHeight);

                        var newImage = new Bitmap(cutRectangle.Width, cutRectangle.Height);
                        Graphics g = Graphics.FromImage(newImage);
                        g.DrawImage(sourceImg, cutRectangle, sourcePositionX, sourcePositionY, cutsizeWidht, cutsizeHeight, GraphicsUnit.Pixel);
                        newImage.Save(mem, ImageFormat.Png);

                        var saveImage = System.Drawing.Image.FromStream(mem);
                        var fileName = System.IO.Path.GetFileName(args[numcount]);
                        var pureName = fileName.Split('.');
                        fileName = pureName[0] + i.ToString() + "_" + j.ToString() + ".png";
                        saveImage.Save(@"C:\usr\test\" + fileName);
                    }
                }

This is my code snippet.
Currently i am testing it with an imagesize 5906 * 1773. The slice dimensions per cutted image should be 2096 * 1773. The code above ignores therefore the rest of 1714 in the width (2096 * 2 = 4192, rest of 5906 – 4192 = 1714). But thats okay, though.

The problem is, that the second one won’t be the image, but it is black.

  • 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-12T15:24:00+00:00Added an answer on June 12, 2026 at 3:24 pm

    Okay, the solution is: Use the original code but this was wrong, so instead of using:

    var sourcePositionX = i * cutsizeHeight;
    var sourcePositionY = j * cutsizeWidht;
    

    it’s correct to use:

    var sourcePositionY = i * cutsizeHeight;
    var sourcePositionX = j * cutsizeWidht;
    

    X at the coordinate system stands for width, i just made a small X/Y mistake here. now it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After some Googling it appears this is a common problem but I have yet
I have problem with UIWebView delay when the load image from url. In my
I am attempting some pattern matching in Lua and have hit a small problem.
I have encountered some unforeseen consequences of porting to mono 2.8.1. Problem can be
I need to solve a problem by rotating an image, but I have this
We are working with some new Cutting Tools that can have it's hardware parameters
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with show or hide form in Window Form Application. I start

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.