Draw image every so pixels

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 1869 Views - Last Post: 11 October 2014 - 05:40 PM Rate Topic: -----

#1 dynamixcore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-October 14

Draw image every so pixels

Posted 10 October 2014 - 01:34 PM

Hello Community, (New Guy Here)

Sitting here for months struggling to figure out how to do this in vb.net and tried many times in vb6 with no luck. I have parts of this done but i am stuck on this drawing method i am trying to do.

So i am trying to either draw a picturebox based on resolution dynamically or images dynamically, For example:

Draw image every so pixels across the screen based on what the width resolution of the screen is OR draw image for every so pixels in a picturebox based on width of picturebox.

I figure i would need an array somehow but i am not sure how to draw or array in this way, Maybe not an array at all? I am just now playing around with vb.net and for years since a teen I've used vb6 (yes you have a noober on your hands.. sound the alarm).

Would anyone know how to go about this code to draw say every 50 pixels another image and only draw within the resolution width of the screen or picbox width? i have everything else but am lost on how to do this.

If it means anything what i am trying to do here is something ive been trying to accomplish for years.

Thanks in advance! You have my gratitude eternally you really have no idea!

Is This A Good Question/Topic? 0
  • +

Replies To: Draw image every so pixels

#2 ybadragon  Icon User is offline

  • Home Owner
  • member icon

Reputation: 571
  • View blog
  • Posts: 2,647
  • Joined: 11-May 12

Re: Draw image every so pixels

Posted 10 October 2014 - 01:40 PM

you will want to do some research Screen Bounds

Also you will want to look into Control.PointToScreen for looping through the pixels within a Controls location
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,769
  • Joined: 12-December 12

Re: Draw image every so pixels

Posted 10 October 2014 - 01:41 PM

Please use a meaningful title. I've changed it on this occasion.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13488
  • View blog
  • Posts: 53,864
  • Joined: 12-June 08

Re: Draw image every so pixels

Posted 10 October 2014 - 01:41 PM

Given an set width you can use a for loop to draw a box while the width of the box plus the current spot is no greater than "Screen.PrimaryScreen.Bounds.Width".

So a for loop, using the 'paint' event, and an if statement.

Remember the top left corner is 0,0.. and increasing the X makes you go right and increasing the y makes you go down.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,769
  • Joined: 12-December 12

Re: Draw image every so pixels

Posted 10 October 2014 - 01:44 PM

Quote

Draw image every so pixels across the screen based on what the width resolution of the screen is OR draw image for every so pixels in a picturebox based on width of picturebox.

A PictureBox can only hold a single image.

You can use a simple loop with a step of 50 (pixels).
Yes, you can use an array, or a List or other collection, to store the images. In which case, you could loop through this collection, offsetting the image by 50px each time.
Was This Post Helpful? 0
  • +
  • -

#6 dynamixcore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-October 14

Re: Draw image every so pixels

Posted 10 October 2014 - 01:51 PM

View Postandrewsw, on 10 October 2014 - 01:41 PM, said:

Please use a meaningful title. I've changed it on this occasion.

My Apologies, Next time i will do so.

Thanks for the change.

I hate to ask but would someone have a snippet to play around with? I will go ahead and research screen bounds.

Yes i understand coords just not sure how to apply them this way.

View Postandrewsw, on 10 October 2014 - 01:44 PM, said:

Quote

Draw image every so pixels across the screen based on what the width resolution of the screen is OR draw image for every so pixels in a picturebox based on width of picturebox.

A PictureBox can only hold a single image.

You can use a simple loop with a step of 50 (pixels).
Yes, you can use an array, or a List or other collection, to store the images. In which case, you could loop through this collection, offsetting the image by 50px each time.


Oh, I saw a snippet that showed how to add more than one on a picbox but i think i know what you mean.

View Postandrewsw, on 10 October 2014 - 01:44 PM, said:

Quote

Draw image every so pixels across the screen based on what the width resolution of the screen is OR draw image for every so pixels in a picturebox based on width of picturebox.

A PictureBox can only hold a single image.

You can use a simple loop with a step of 50 (pixels).
Yes, you can use an array, or a List or other collection, to store the images. In which case, you could loop through this collection, offsetting the image by 50px each time.


Exactly what im trying to do..

Use an imagelist as the source which i know that part so looks like i have some research to do on how to do the loop offsetting by 50 or a value each time.

Thanks for the assistance and if anyone has any examples to learn from that might do this, Please let me know! :)
Was This Post Helpful? 0
  • +
  • -

#7 dynamixcore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-October 14

Re: Draw image every so pixels

Posted 10 October 2014 - 04:08 PM

i found a good example of what im trying to do only not Christmas lights.. just small icons / png.

any idea or a code example of how this can be accomplished? i already wrote the transparency part as well as the desktop placement but i cannot get it to create dynamic images that stay within the width of your screen resolution. Obviously if i did just a transparent form with manual placement it would have to be the same screen res in order not to be cut off or be too short.

its exactly like this (this isnt a vb.net project just a program from long ago called twinkle bulbs) further ideas besides the research already linked?

Example of icons dynamicaly placed with spacing
Was This Post Helpful? 0
  • +
  • -

#8 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1444
  • View blog
  • Posts: 3,679
  • Joined: 01-February 13

Re: Draw image every so pixels

Posted 10 October 2014 - 05:10 PM

Hi,
You can use a simple loop in the Form`s Paint event to loop from 0 to the screens width divided by the ImageLists image size width (50) and draw each image at (x * the ImageList`s image size width). This makes a transparent borderless form that is positioned at the top left of the screen and is the width of the screen by the height of the ImageList`s image height.

Public Class Form1
    Private ImgLst As New ImageList With {.ImageSize = New Size(50, 50)}

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.Manual
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.Bounds = New Rectangle(0, 0, Screen.PrimaryScreen.WorkingArea.Width, ImgLst.ImageSize.Height)
        Me.BackColor = Color.Lime
        Me.TransparencyKey = Color.Lime
        Me.TopMost = True

        'Load all the png images into the ImageList
        For Each fn As String In IO.Directory.GetFiles("C:\TestFolder\New Folder", "*.png")
            ImgLst.Images.Add(Image.FromFile(fn))
        Next
    End Sub

    Private Sub Form1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDoubleClick
        Me.Close()
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        For x As Integer = 0 To CInt(Me.ClientSize.Width / ImgLst.ImageSize.Width)
            If x < ImgLst.Images.Count And Not (x * ImgLst.ImageSize.Width) + ImgLst.ImageSize.Width > Me.ClientSize.Width Then
                e.Graphics.DrawImage(ImgLst.Images(x), (x * ImgLst.ImageSize.Width), 0, ImgLst.ImageSize.Width, ImgLst.ImageSize.Height)
            End If
        Next
    End Sub
End Class


This post has been edited by IronRazer: 10 October 2014 - 05:39 PM

Was This Post Helpful? 1
  • +
  • -

#9 dynamixcore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-October 14

Re: Draw image every so pixels

Posted 10 October 2014 - 05:50 PM

mod: quote removed

Yes in fact most of this i already have just was trying to get the images to be dynamic which this helps! PERFECT!

mod: double quote removed

Ive been just trying to build this for myself personally. I have been waiting a long time to learn and figure out how to do this and in a few hours Sir you have solved something i have been working on for almost a year!

This post has been edited by modi123_1: 10 October 2014 - 05:52 PM
Reason for edit:: please do not quote the post above you.. just use the 'reply' button.

Was This Post Helpful? 0
  • +
  • -

#10 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1444
  • View blog
  • Posts: 3,679
  • Joined: 01-February 13

Re: Draw image every so pixels

Posted 10 October 2014 - 06:20 PM

Glad it helped. I am sure if you do a bit of experimenting and read the msdn documents on the different classes and their methods, properties, and events that you don`t understand, you will start doing these things without thinking to hard about it. ;)
Was This Post Helpful? 0
  • +
  • -

#11 dynamixcore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-October 14

Re: Draw image every so pixels

Posted 11 October 2014 - 02:34 AM

I was going to take it a step further and have a button call the paint but i keep getting "invalid cast exception", doing trial and error on some sites and guessing as well and that error i get every time and i dont see alternatives on msdn unless im just blind and stupid..

Couldn't i make a statement/line that would allow me to call the form1_Paint when i want instead of load and tha.?

This post has been edited by andrewsw: 11 October 2014 - 03:14 AM
Reason for edit:: Removed previous quote, just press REPLY

Was This Post Helpful? 0
  • +
  • -

#12 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1444
  • View blog
  • Posts: 3,679
  • Joined: 01-February 13

Re: Draw image every so pixels

Posted 11 October 2014 - 04:32 AM

Hi,
I am not sure exactly how your application is suppose to look and act. Perhaps if you explain in detail how your form is suppose to look and act when the user first opens it and then explain what you want it to do when the user clicks the button it will help us suggest a solution to this.

I have to leave now and i wont be around most of the day so, if you don`t get an answer by the time i get home i will try to help. :)
Was This Post Helpful? 0
  • +
  • -

#13 dynamixcore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-October 14

Re: Draw image every so pixels

Posted 11 October 2014 - 10:11 AM

What im trying to make is a small application that puts "Christmas light bulb images" across the top of the desktop. Its more of a personal mission since i was a teen and i know its kind of weird but ive wanted to make something like this forever that works at all resolutions (looping / draw with paint as you have there does that)


Ive handled the transparency but what i need to do is either have a timer or control be able to call form_paint with specific static images (make a flashing effect) or be able to change the index maybe for a chase effect. basically switching from one png icon to another just like the image i showed you from another application is what i am trying to do.

I was able to change static here to change the draw a fixed image in imglst:

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        For x As Integer = 0 To CInt(Me.ClientSize.Width / ImgLst.ImageSize.Width)
            If x < ImgLst.Images.Count And Not (x * ImgLst.ImageSize.Width) + ImgLst.ImageSize.Width > Me.ClientSize.Width Then
                e.Graphics.DrawImage(ImgLst.Images(x), (x * ImgLst.ImageSize.Width), 0, ImgLst.ImageSize.Width, ImgLst.ImageSize.Height)
            End If
        Next
    End Sub


and change to this:
| this was changes from x to a number 1 choosing an image loaded in imglst|
e.Graphics.DrawImage(ImgLst.Images(1), (x * ImgLst.ImageSize.Width), 0, ImgLst.ImageSize.Width, ImgLst.ImageSize.Height)


The one thing i cant even imagine is how to change specific images based on count or index, Example "every other image use another image instead creating a chase effect." or use a timer to call form_paint correctly with each having a different variable.

For the flash effect i know i can create a timer then call it with a string variable but i tried to call the paint on 2 x timers or even buttons and i get thrown " Invalid cast exception".

The changing image every other image / index items i have no clue how to even begin writing that one.

Including images that shows my objective on this app.

Posted Image
Lights off

Posted Image
Lights on

Posted Image
Chase pattern part one

Posted Image
Chase pattern part two

Believe me any help is super appreciated and i most certainly dont mind donating for the help and not chump change, thats how bad i want to make this work. ( i hope this doesn't violate forums rules to donate to someone for help on a non-commercial project)
Was This Post Helpful? 0
  • +
  • -

#14 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2330
  • View blog
  • Posts: 9,381
  • Joined: 03-December 12

Re: Draw image every so pixels

Posted 11 October 2014 - 10:40 AM

I can see this being done a couple different ways. You could swap the images, easy, you could actually paint the graphic, slightly more work.


The code you are working with ( posted in [code] tags) will help us debug what you do have.

Load the images into an array and loop through the images sleeping between intervals.
Was This Post Helpful? 0
  • +
  • -

#15 dynamixcore  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 10-October 14

Re: Draw image every so pixels

Posted 11 October 2014 - 10:48 AM

View Postastonecipher, on 11 October 2014 - 10:40 AM, said:

I can see this being done a couple different ways. You could swap the images, easy, you could actually paint the graphic, slightly more work.


The code you are working with ( posted in [code] tags) will help us debug what you do have.

Load the images into an array and loop through the images sleeping between intervals.


Thats the issue, Im not that familiar with vb.net enough to perform that. Would there be a resource or example for this on the net that you know of?

Lol.. i have like 5 books on learning vb.net ive been running through because i am done working with vb6 after a good decade. VB6 is just flat out useless for me now.

I hate being this bad of a noob-tard.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2