PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 18, 2022

[FIXED] how to insert part of image into picturebox?

 May 18, 2022     c#, image, location, partial, picturebox     No comments   

Issue

I'm not really sure if it is possible to insert a part of image into picturebox, but I would like to create an image 500*500 pixels in size and then use the parts of it as small connectable 50*50 pieces by setting the location of image inside the pictureboxes...

Is anything similar possible through use of graphics? I'm not very familiar with it... (I am talking about C# forms application...)


Solution

After some time of searching and few personal attempts I have found a solution, this isn't my own, but sadly I have forgot where did I took it from:

   private static Image cropImage(Image img, Rectangle cropArea)
   {
       Bitmap bmpImage = new Bitmap(img);
       Bitmap bmpCrop = bmpImage.Clone(cropArea,
       bmpImage.PixelFormat);
       return (Image)(bmpCrop);
   }

This will created cropped image, you can now use it in code. SAMPLE:

   Picturebox P = new Picturebox;
   P.BackgroundImage = cropImage(ImageThatWillBeCropped, new Rectangle(0,0,50,50));

If anyone finds this useful and needs explanation for rectangle, please, feel free to ask :)



Answered By - Antonio Teh Sumtin
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing