none
Keep Bitmap in control by wrapping it downwards like a array of tiles RRS feed

  • Question

  • does anybody know how to keep a bitmap in a control by wrapping the edges that are off the sides like what a flow panel does?

    for example if I have a 32x8 bitmap like so..

    and the control I draw it onto is 16x16, is i possible to have the bitmap wrap around like so?

    I have tried making a array of controls in a flow panel but it lags the application when doing anything because I have over 1000 of these things.

    I have also tried directly drawing a array of bitmaps onto the control but it still takes a while to startup the application and increasing the array to 65536 entries the application runs out of memory since each bitmap is stored with a palette.

    Thursday, June 20, 2019 7:46 PM

All replies

  • Hi,

    Do you mean you want to use GDI+ or something else to draw the graphic? What is the specific meaning of "32x8" and "16x16"?

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 21, 2019 9:56 AM
    Moderator
  • hello I was thinking about using the PaintEvent of my custom control.

    32x8 is for example is the unaltered 32x8 pixel image in the picturebox.

    16x16 would be the altered image if the picturebox's width would be 16.

    I am trying to make a tile editor in which each tile is 8x8.


    Saturday, June 22, 2019 3:49 AM
  • Hi Shadowblitz16,

    Do you mean to generate "tile" based on the number of rows and columns provided? If so, here is a simple demo you can refer to.

        void Draw()
        {
            Graphics graphics = this.CreateGraphics();
            graphics.Clear(this.BackColor);
            graphics.Dispose();
            Random random = new Random();
            int Xvalue = 0;
            for (int col = 0; col < Convert.ToInt32(textBox1.Text); col += 1)
            {
                int Yvalue = 0;
                for (int row = 0; row < Convert.ToInt32(textBox2.Text); row += 1)
                {
                    Graphics g = this.CreateGraphics();
                    Rectangle rect = new Rectangle(Xvalue, Yvalue, 8, 8);
                    SolidBrush b1 = new SolidBrush(Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)));
                    g.FillRectangle(b1, rect);
                    Yvalue += 8;
                }
                Xvalue += 8;
            }
        }
    
        private void btDraw_Click(object sender, EventArgs e)
        {
            Draw();
        }

    Result:

    Hope this can help you.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 25, 2019 5:58 AM
    Moderator
  • @Kyle Wang

    thankyou.

    yes but I need to have at least 256x256 tiles displayed at once and these tiles will not just be single colors but bitmaps

    Tuesday, July 16, 2019 12:48 AM