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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:41:39+00:00 2026-05-19T12:41:39+00:00

I have an image, let’s says a .png, that is uploaded by the user.

  • 0

I have an image, let’s says a .png, that is uploaded by the user.
This image has a fixed size, let’s say 100×100.

I would like to create 4 sprites with this image.

One from (0,0) to (50,50)

Another from (50, 0) to (100, 50)

The third from (0, 50) to (50, 100)

The last from (50, 50) to (100, 100)

How can I do that with my prefered C# ?

Thanks in advance for any help

  • 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-05-19T12:41:40+00:00Added an answer on May 19, 2026 at 12:41 pm

    To create a texture from a PNG file, use the Texture2D.FromStream() method (MSDN).

    To draw the different sections of the texture, use the sourceRectangle parameter to an overload of SpriteBatch.Draw that accepts it (MSDN).

    Here’s some example code:

    // Presumably in Update or LoadContent:
    using(FileStream stream = File.OpenRead("uploaded.png"))
    {
        myTexture = Texture2D.FromStream(GraphicsDevice, stream);
    }
    
    // In Draw:
    spriteBatch.Begin();
    spriteBatch.Draw(myTexture, new Vector2(111), new Rectangle( 0,  0, 50, 50), Color.White);
    spriteBatch.Draw(myTexture, new Vector2(222), new Rectangle( 0, 50, 50, 50), Color.White);
    spriteBatch.Draw(myTexture, new Vector2(333), new Rectangle(50,  0, 50, 50), Color.White);
    spriteBatch.Draw(myTexture, new Vector2(444), new Rectangle(50, 50, 50, 50), Color.White);
    spriteBatch.End();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

let's say that i have an image It's size is height : 150px width
Let's say I have an image URL http://website.com/content/image.png I want to grab that image
OK, let's say I have this Image: ImageIcon imageBack = new ImageIcon(System.getenv(APPDATA) + \.my_game\bg.png);
Let's say I have an image of this size: Using CSS3 and whatnot, is
Let's say I have this image this : With a black scratch and I
let's say we have an image that contain square,circle and other few object at
I have a image used for a LinearLayout background Let's say image has 20x100
Let's say I have an image that does not reside in the normal location:
Let's say we have the image defined as below. <Grid.Resources> <Image x:Key="SomeKey" Source="PathToTheImage.png" />
Let's say I have an image represented by a CFMutableBitVector. That means that ever

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.