9 Replies - 1682 Views - Last Post: 31 July 2012 - 01:13 PM Rate Topic: -----

#1 Tailean  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 21-March 12

Using Images as layers... or perhaps Transparity

Posted 30 July 2012 - 03:38 PM

Okay, so I have decided to make a simple card maker. The program will 'ideally' allow its user to load a picture from their c drive and it will allow them to change different images while the loaded picture stays the same.

The Problem: I decided to use picture boxes but the problem is picture-boxes are square and in some cases I am using hexagons. So perhaps its transparency I am having the trouble with bu cause my images were made in MS paint.

If anyone has been down this road and can help me with either a new direction to approach this or any easy solutions...feel free. Thanks again for reading.

Is This A Good Question/Topic? 0
  • +

Replies To: Using Images as layers... or perhaps Transparity

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1900
  • View blog
  • Posts: 5,697
  • Joined: 05-May 12

Re: Using Images as layers... or perhaps Transparity

Posted 30 July 2012 - 06:33 PM

To paint into irregular shapes, you can use the overloads on Graphics.SetClip() that take GraphicsPaths or Regions. Here's the documentation for the flavor that takes a path: http://msdn.microsof...ibrary/0z994t06

Now your question from the other thread about the "opaque form" is starting to make a little bit of sense. You had the right paradigm of have containers that can hold things, lets you move them around, a paints when you tell them to. Unfortunately, the choice of using the Form control and other WinForm controls is probably not the best choice to implement the paradigm. You will probably be better off implementing something to hold a list of images to be rendered and calling Graphics.DrawImage().

If you really need some transparency effects, there are overloads of Graphics.DrawImage() that take an ImageAttributes parameter. In the ImageAttributes class, you can set color keys for transparency effects.
Was This Post Helpful? 0
  • +
  • -

#3 Tailean  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 21-March 12

Re: Using Images as layers... or perhaps Transparity

Posted 30 July 2012 - 07:50 PM

ok to use this:

private void SetClipPath(PaintEventArgs e)
{

    // Create graphics path.
    GraphicsPath clipPath = new GraphicsPath();
    clipPath.AddEllipse(0, 0, 200, 100);

    // Set clipping region to path.
    e.Graphics.SetClip(clipPath);

    // Fill rectangle to demonstrate clipping region.
    e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
}


I would need to create a class with a GraphicsPath Method? What type of information would I need to provide in that Method to get my desired effect?
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1900
  • View blog
  • Posts: 5,697
  • Joined: 05-May 12

Re: Using Images as layers... or perhaps Transparity

Posted 30 July 2012 - 08:38 PM

GraphicPath there is a class that is already implemented by the framework. To do your hexagon, you'd probably have to call AddPolygon() and pass in the points of your hexagon.
Was This Post Helpful? 0
  • +
  • -

#5 Tailean  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 21-March 12

Re: Using Images as layers... or perhaps Transparity

Posted 30 July 2012 - 08:50 PM

hmm.... perhaps I don't have a using statement I need. I keep getting this:

Error	1	The type or namespace name 'GraphicsPath' could not be found (are you missing a using directive or an assembly reference?)	C:\Users\Tailean\Documents\Visual Studio 2010\Projects\MyCCG\MyCCG\Form1.cs	26	13	MyCCG



I have: using System.Drawing;

This post has been edited by Tailean: 30 July 2012 - 08:52 PM

Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1900
  • View blog
  • Posts: 5,697
  • Joined: 05-May 12

Re: Using Images as layers... or perhaps Transparity

Posted 30 July 2012 - 09:02 PM

Good instincts there. You should follow them more often.

To help you follow your instincts, it often pays to look at the documentation. In this case, you're having a problem with GraphicPath. Looking in MSDN, we get to the class documentation page: http://msdn.microsof...2d.graphicspath

If you look near the top it says:

Quote

Namespace: System.Drawing.Drawing2D
Assembly: System.Drawing (in System.Drawing.dll)

Was This Post Helpful? 0
  • +
  • -

#7 Tailean  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 21-March 12

Re: Using Images as layers... or perhaps Transparity

Posted 31 July 2012 - 01:16 AM

In these 2 lines:

private void SetClipPath(PaintEventArgs e)
        {
            clipPath.AddEllipse(0, 0, 200, 100);

            e.Graphics.FillRectangle(new SolidBrush(Color.Black), 0, 0, 500, 300);
        }


Could you tell me what the numbers stand for? (0, 0, 200, 100) 0, 0, 500, 300. I know that's probably a very basic question..I am just unsure..i never worked with this before.
Was This Post Helpful? 0
  • +
  • -

#8 MrShoes  Icon User is offline

  • D.I.C Regular

Reputation: 186
  • View blog
  • Posts: 303
  • Joined: 13-June 12

Re: Using Images as layers... or perhaps Transparity

Posted 31 July 2012 - 04:48 AM

I believe IntelliSense will confirm, but it should be the 4 parameters to define a rectangle: x,y,width,height (where x + y denote the upper-left corner of the rectangle).

EDIT: Just checked the documentation and was correct. You can also pass in an existing Rectangle or RectangleF object.

GraphicsPath.AddEllipse() on MSDN

This post has been edited by MrShoes: 31 July 2012 - 05:03 AM

Was This Post Helpful? 0
  • +
  • -

#9 Curtis Rutland  Icon User is online

  • (╯°□°)╯︵ (~ .o.)~
  • member icon


Reputation: 3793
  • View blog
  • Posts: 6,390
  • Joined: 08-June 10

Re: Using Images as layers... or perhaps Transparity

Posted 31 July 2012 - 12:42 PM

Please learn to search the MSDN before you ask these questions. Each of these has been answered by referencing the documentation, as shown by the posters. I'm not trying to be harsh, since I know you're fairly new to this, but the documentation is your best friend. Learn to love it. Learn to use it, and you won't be at the mercy of some forum people's free time.
Was This Post Helpful? 1
  • +
  • -

#10 Tailean  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 56
  • Joined: 21-March 12

Re: Using Images as layers... or perhaps Transparity

Posted 31 July 2012 - 01:13 PM

I hear you, and I did look it up..however...I didn't understand still that's why I asked the question.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1