Hi there,
I am creating a customisable user interface that uses images as buttons etc. However when I just use the DrawImage function without including the image size it draws it at double the size, I thought I should draw it at its default size?
I then tried including the image size using the myImage.Width and Height, but still gets drawn double the size! I then looked at the values that were getting returned for the Width and height and it is returning the wrong size!
Does anyone know why the image might be returning double the actual size? (just so you know the actual image H&W is 52x52, but its getting drawn at 104x104)
Here is my code
Code Snippet
public
Form1()
{
InitializeComponent();
butMusic = new Button(@"C:\Documents and Settings\Chris\My Documents\Visual Studio 2008\Projects\PFPC\PFPC\PFPC\interface\Music_Button.jpg", "Music", 100, 100); // 100 values are location
}
class
Button
{
private float x, y; // Image location
private Image image; // Image
private String text; // Image text
public Button(string imagePath, string imageText, float x, float y)
{
this.image = Image.FromFile(imagePath);
this.x = x;
this.y = y;
this.text = imageText;
}
public void Draw(Graphics dc)
{
float imageCentre; // Get image centre - relative to position on screen
sFormat.Alignment = StringAlignment.Center; // Centre it when drawn where i place it
dc.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
//image centre
imageCentre = x + (image.Width / 2);
dc.DrawImage(image, x, y);//, image.Width, image.Height);
dc.DrawString(this.text, textFont, textBrush, imageCentre, y + image.Height + 2, sFormat);
}
}
Many thanks