hi,

I was wondering if someone give you an image e.g. http://www.google.co.uk/images/nav_logo29.png.. how do you get one image and include it in your page without using photoshop etc.

Say we have a pack of playing cards and all the cards are in one image how do you select one card from the whole thing and give it a name etc..

say we have 2,3,4,5,6 of spades in one image ....

hope i make sense

Thanks

Try with this:

public System.Drawing.Image LoadImagePiece(string imagePath, Rectangle desiredPortion)
{
   using (Image img = Image.FromFile(path))
   {
       Bitmap result = new Bitmap(desiredPortion.Width, desiredPortion.Height, PixelFormat.Format24bppRgb);
       using (Graphics g = Graphics.FromImage((Image)result))
       {
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            g.DrawImage(img, 0, 0, desiredPortion, GraphicsUnit.Pixel);
       }
       return result;
   }
}

Hi,

Can you explain please how you get those images using your method. I did some reseach and the term i m looking for is Image map in asp.net and html ...

Upper code is based on that graphics is drawn on bitmap and that is returned as image(result).

Example (Open new project and try following code to understand):

private void Form1_Load(object sender, EventArgs e)
        {
            // new Point(x, y) - coordinates of upper left point of the piece
            // new Size(x2, y2) - coordinate of bootom right point of the piece
            pictureBox1.Image = LoadImagePiece(@"imagePath", new Rectangle(new Point(0,0),new Size(100,100)));
        }

        public System.Drawing.Image LoadImagePiece(string imagePath, Rectangle desiredPortion)
        {
            using (Image img = Image.FromFile(imagePath))
            {
                Bitmap result = new Bitmap(desiredPortion.Width, desiredPortion.Height, PixelFormat.Format24bppRgb);
                using (Graphics g = Graphics.FromImage((Image)result))
                {
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.DrawImage(img, 0, 0, desiredPortion, GraphicsUnit.Pixel);
                }
                return result;
            }
        }

If you don't understand, tell me to send you a project.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.