A problem with graphics

This is a discussion on A problem with graphics within the C# Programming forums, part of the General Programming Boards category; Hi all I have been playing around with some basic graphic elements to get in touch with OOP and C#. ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    85

    A problem with graphics

    Hi all

    I have been playing around with some basic graphic elements to get in touch with OOP and C#. i have managed to put the following piece of code together but am experiencing an unusual issue with it.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace Graphictest1
    {
        public partial class Form1 : Form
        {
            public int xpos = 10;
            public int ypos = 10;
            
            Bitmap myBitmap = new Bitmap(@"c:\green_ball.bmp");     //64 x 64 pixel images
            Bitmap myBitmap1 = new Bitmap(@"c:\wall1.bmp");               
            Bitmap myBitmap2 = new Bitmap(@"c:\brown_ball.bmp");
    
            public Graphics g;
            private Bitmap myscreen; 
    
            public Form1()
            {
                InitializeComponent();
    
                this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
                this.SetStyle(ControlStyles.UserPaint, true);
                this.SetStyle(ControlStyles.DoubleBuffer, true);
                this.UpdateStyles();
                
                myscreen = draw();
                this.Invalidate();
            }
    
            public Bitmap draw()
            {
                Bitmap back = new Bitmap(this.Width, this.Height);
                Graphics p  = Graphics.FromImage(back);
    
                int x;
                int y;
                int tile = 1;
    
               myBitmap.MakeTransparent(Color.White);
                myBitmap1.MakeTransparent(Color.White);
                myBitmap2.MakeTransparent(Color.White);  
    
              for (y = 0; y <= 640; y = y + 64)
                {
                    for (x = 0; x <= 768; x = x + 64)
                    {
                        if (tile == 1)
                        {
                            p.DrawImage(myBitmap1, x, y);
                            tile = 0;
                        }
                        else
                        {
                            p.DrawImage(myBitmap2, x, y);
                            tile = 1;
                        }
                    }
                }
    
                p.DrawImage(myBitmap, xpos, ypos);
    
                return (back) ;
            }
    
            private void Form1_KeyDown(object sender, KeyEventArgs e)
            {
                string key = e.KeyData.ToString();
    
                if (key == "Right")
                {
                    xpos = xpos +4;
                }
                else if (key == "Left")
                {
                    xpos = xpos -4;
                }
                else if (key == "Up")
                {
                    ypos = ypos -4;
                }
                else if (key == "Down")
                    ypos = ypos +4;
    
    
                myscreen = draw();
               this.Invalidate();  
      
            }
    
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
               // its overridden
            }
    
            protected override void OnPaint(PaintEventArgs e)
            {
               e.Graphics.DrawImage(this.myscreen, 0, 0); 
                //base.OnPaint(e);
            }
        }
    }
    Nothing spectacular in there as you can see (well to someone who is used to it anyway - which im not).

    My problem is this, in the draw routine, the three lines which turn on transparency (highlighted) seem to affect the actual size of the graphics the system draws.

    Is it supposed to affect the size ?

    when i comment them out, i get graphics about 1/4 of the dimension i get when uncommented. Can anyone shed any light on this ?

    it does not affect the actual execution of the code in anyother way i can see.

    thanks in advance.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    85
    Just as a note to this as it got no replys - i believe the issue was something to do with different DPI resolution settings on the images but am still not 100&#37;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginning Game Programming Type Books
    By bumfluff in forum Game Programming
    Replies: 36
    Last Post: 09-13-2006, 05:15 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  3. Graphics Programming :: Approach and Books
    By kuphryn in forum Windows Programming
    Replies: 4
    Last Post: 05-11-2004, 09:33 PM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 06:18 AM
  5. Graphics Problem
    By drdroid in forum C++ Programming
    Replies: 5
    Last Post: 02-27-2002, 02:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21