Changing images with c#

Hi,
I am making a slotmachine. I have everything but only need an animation for changing the images. This is what i got(only the code for the animation). I can change 2 images but don't know how to do it with multiple images like 5.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace animatie
    public partial class Form1 : Form
        public Form1()
            InitializeComponent();
            Timer t = new Timer();
            t.Interval = 100;
            t.Tick += new EventHandler(t_Tick);
            t.Start();
        bool one;
        void t_Tick(object sender, EventArgs e)
            Image img;
            if (one) img = imageList1.Images[0];  
            else img = imageList1.Images[1];                      
            one = !one;
            pictureBox1.Image = img;

Since it seems like you have it working for 2 images then expanding it to any # of images is straightforward. It looks like you're trying to animate the spinning wheel on the slot machine so that is the basis I'm working against.  I'm also assuming
you want to stick with the image list but there are other approaches as well.
Firstly make sure your images are all in the image list. Next I would recommend that you move the timer start logic out of your constructor.  You don't want it running when the form is created because it hasn't even been displayed yet.  If you
want the spinning to start as soon as the form is displayed then override the OnLoad and start the timer at that point.  I would recommend that you move this functionality into a separate method because you'll probably want to be able to spin the wheels
by clicking a button as well. 
Since you're using an image list you'll need to keep track of the "current" image.  To do that a simple image index field should be fine.  Each time the timer fires you increment the index by 1.  If it gets to the end of the list
(>= count) then reset it to 0.  Then set the PictureBox image to the image at that index.  This gives you the wrapping logic you want.  It won't give you a smooth transition image though, each image will basically just pop up. 
If you want a smooth transition then you might need to look at using a single image with images on it and the timer is simply having the window viewport move "down" the image in a scrolling fashion.  When it gets to the bottom it loops back
around.  For that kind of implementation a PictureBox is probably not a good idea, you'll want to use a simple custom control that handles its own painting instead.
Since you'll need to do this 3 times (one for each window) you might consider moving the logic into a custom control that represents a single window, the timer logic, image selection and image list.  You can then use 3 instances on your form to emulate
the slot machine.  Note that you'll want to add some randomness to the spinning because if each window spins at the same speed you'll always get the same behavior.  Therefore you should probably have each window randomly decide how long and how fast
to spin to introduce randomness to the spinning.
Michael Taylor
http://blogs.msmvps.com/p3net

Similar Messages

  • How to change Images with ImageIcon

    Hello everyone, this is my first post on the forums.
    I am struggling at the moment to find a way to change images in my program. I am making a card game and when the user clicks a button it will replace the card he has with another card. I thought the following code would work but apparently it doesnt:
    String cardPathA = "image1.gif";
    ImageIcon imageCardA = new ImageIcon(cardPathA);   //cardPathA for example is image1.gif
    //during the program the user changes cards so it should now show image2.gif
    cardPathA = "image2.gif";
    imageCardA.setImage(cardPathA);The error occurs when compiling and it reads: "+setImage(java.awt.Image) in javax.swing.ImageIcon cannot be applied to (java.langlString)+".
    I have searched all over the internet and I haven't found anything. I would appreciate some help. Thanks :)

    im not really sure i made a quick example to show how I would change the imageIcon in a button, just change the paths for cardPathA and cardPathB for your pictures to get it working.
    The only other thing i can think of is maybe to call repaint() for the components you are trying to change the image?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class ImageChange extends JFrame implements ActionListener{
             final private String cardPathA;
            final private String cardPathB;
         private ImageIcon myImageIcon;
            private JButton changeCard;
            private int counter;
            private JPanel panel;
            private JButton imageButton;
         public ImageChange(){       
                changeCard = new JButton("Change Button");
                counter = 0;
                cardPathA = "1.gif";
                cardPathB = "2.gif";
                myImageIcon = new ImageIcon(cardPathA);
                imageButton = new JButton(myImageIcon);
            public void makeGui(){
                changeCard.addActionListener(this);
                panel = new JPanel(new BorderLayout());
                panel.add(changeCard,BorderLayout.NORTH);
                panel.add(imageButton,BorderLayout.CENTER);
                this.add(panel);
                this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
                this.pack();
                this.setVisible(true);
         public void actionPerformed (ActionEvent menuChoice){
                counter++;
                if(counter%2 ==0){             
                    myImageIcon = new ImageIcon(cardPathA);
                    imageButton.setIcon(myImageIcon);
                }else{
                    myImageIcon = new ImageIcon(cardPathB);
                    imageButton.setIcon(myImageIcon);
            public static void main(String[] args){
                ImageChange test = new ImageChange();
                test.makeGui();
    }Calypso

  • Change image with radio group

    I hope this is a simple one for someone out there.
    I need to swap images with a radio group.
    I'll post the code here so you have what I have for now.
    Obviously I haven't gotten anything working.
    Image names to be:
    Case_green.png
    Case_blue.png
    Case_blacklight.png
    Case_red.png
    <!--START RADIO BUTTONS-->
    <!--START RADIO BUTTON SCRIPT-->
    <script type="text/javascript">
    </script>
    <!--END RADIO BUTTON SCRIPT-->
    <form name="Colors" method="post" action="">
    <table width="358" align="left">
    <tr>
    <td width="70"><label>
    <input name="ColorRadios" type="radio" id="ColorRadios_0"
    value="radio_green" checked>
    Green</label></td>
    <td width="57"><label>
    <input name="ColorRadios" type="radio" id="ColorRadios_1"
    value="radio_blue">
    Blue</label></td>
    <td width="105"><label>
    <input type="radio" name="ColorRadios"
    value="radio_blacklight" id="ColorRadios_2">
    Black Light</label></td>
    <td width="54"><label>
    <input type="radio" name="ColorRadios" value="radio_red"
    id="ColorRadios_3">
    Red</label></td>
    </tr>
    </table>
    </form>
    <p align="left">
    <!--END RADIO BUTTONS-->

    Mick,
    Thanks
    William - sorry about the missing quote.
    Paul Davis
    http://www.kaosweaver.com/
    Visit us for dozens of useful Dreamweaver Extensions.
    http://www.communitymx.com/
    Partner at Community MX - Extend your knowledge
    Mick White wrote:
    > Paul Davis wrote:
    >> this would be something like:
    >> <input name="ColorRadios" type="radio"
    id="ColorRadios_1"
    >> value="radio_blue"
    >>
    onclick="document.getElementById('swapimageid').src='Case_blue.jpg'>
    >
    > onclick=
    > "document.getElementById('swapimageid').src=
    > 'Case_'+this.value.split('_')[1]+'.jpg'"
    >
    > Mick
    > Note: You forgot closing quotes.
    >>
    >> The image that is getting swapped will need a unique
    ID, but that
    >> should do it.
    >>
    >>
    >> Paul Davis
    >>
    http://www.kaosweaver.com/
    >> Visit us for dozens of useful Dreamweaver
    Extensions.
    >>
    >>
    http://www.communitymx.com/
    >> Partner at Community MX - Extend your knowledge
    >>
    >> William Rickert wrote:
    >>> I hope this is a simple one for someone out
    there.
    >>>
    >>> I need to swap images with a radio group.
    >>>
    >>> I'll post the code here so you have what I have
    for now. Obviously I
    >>> haven't gotten anything working.
    >>>
    >>> Image names to be:
    >>> Case_green.png
    >>> Case_blue.png
    >>> Case_blacklight.png
    >>> Case_red.png
    >>>
    >>>
    >>> <!--START RADIO BUTTONS-->
    >>> <!--START RADIO BUTTON SCRIPT-->
    >>> <script type="text/javascript">
    >>>
    >>>
    >>> </script>
    >>> <!--END RADIO BUTTON SCRIPT-->
    >>>
    >>> <form name="Colors" method="post"
    action="">
    >>> <table width="358" align="left">
    >>> <tr>
    >>> <td width="70"><label>
    >>> <input name="ColorRadios" type="radio"
    id="ColorRadios_0"
    >>> value="radio_green" checked>
    >>> Green</label></td>
    >>> <td width="57"><label>
    >>> <input name="ColorRadios" type="radio"
    id="ColorRadios_1"
    >>> value="radio_blue">
    >>> Blue</label></td>
    >>> <td width="105"><label>
    >>> <input type="radio" name="ColorRadios"
    >>> value="radio_blacklight" id="ColorRadios_2">
    >>> Black Light</label></td>
    >>> <td width="54"><label>
    >>> <input type="radio" name="ColorRadios"
    value="radio_red"
    >>> id="ColorRadios_3">
    >>> Red</label></td>
    >>> </tr>
    >>> </table>
    >>> </form>
    >>> <p align="left">
    >>> <!--END RADIO BUTTONS-->
    >>>

  • Change Images with Web Dynpro Theme Editor

    Hi, I am using the Web Dypnro Theme Editor for the Portal but I can not find where to change the branding image, the masthead image, the banner or things like that. Is there any way to change this things with the theme editor? Thanks
    Regards.

    Hi Pablo,
    These documents might help u out:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3ea0d790-0201-0010-80b8-b680496a3838
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/d2b1d790-0201-0010-25b7-d1fb059a8ad9
    Regards,
    Pooja.

  • Change Image with Link Hover

    Does any one know how to do this? I found basic code but I am
    not sure how or what needs to be changed.
    <html>
    <head>
    <script language="JavaScript" type="text/JavaScript">
    function showT(q){
    document.getElementById('ima').setAttribute('src','0'+q+'.jpg')
    <title>Confused</title>
    </head>
    <body>
    <table width="500" border="0">
    <tr>
    <td width="20%"><a href="#"
    onmouseover="showT(0)">pic 1<br>
    <br>
    </a><a href="#" onmouseover="showT(1)">pic
    2<br>
    <br>
    </a><a href="#" onmouseover="showT(2)">pic
    3</a></td>
    <td><img id="ima" src="00.jpg" width="100"
    height="100"></td>
    </tr>
    </table>
    <body>
    I found this on
    http://jdstiles.com/java/hoverchangeimage.html
    I have seen it work and I want to make it work for a client I
    am doing a web site for.
    </html>

    You are trying to do a simple image swap? Just use DW's
    SwapImage behavior
    instead of this third-party stuff.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "BWSC" <[email protected]> wrote in message
    news:fvu41d$7be$[email protected]..
    > Does any one know how to do this? I found basic code but
    I am not sure how
    > or
    > what needs to be changed.
    > <html>
    > <head>
    > <script language="JavaScript"
    type="text/JavaScript">
    > function showT(q){
    >
    document.getElementById('ima').setAttribute('src','0'+q+'.jpg')
    > }
    > <title>Confused</title>
    > </head>
    >
    > <body>
    > <table width="500" border="0">
    > <tr>
    > <td width="20%"><a href="#"
    onmouseover="showT(0)">pic 1<br>
    > <br>
    > </a><a href="#" onmouseover="showT(1)">pic
    2<br>
    > <br>
    > </a><a href="#" onmouseover="showT(2)">pic
    3</a></td>
    > <td><img id="ima" src="00.jpg" width="100"
    height="100"></td>
    > </tr>
    > </table>
    > <body>
    >
    > I found this on
    http://jdstiles.com/java/hoverchangeimage.html
    >
    > I have seen it work and I want to make it work for a
    client I am doing a
    > web
    > site for.
    > </html>
    >

  • Displaying dynamically changing image: a problem with JLabel.

    Hello! I use NetBeans 5.5 and I develop my GUI with Matisse. I'm rather a beginner in developing GUIs with this editor...
    I'd like to display a dynamically changing image. The idea is: GUI shows the image, that is modified as some computations run in a different thread. App will be run on a single machine.
    I'm trying to display the image as a label's icon. The problem is that my app's frame can be resized - and when it is, the label also resizes. When the label is resized, the image should also be resized - the image should always be of the same size as the label. The problem? I noticed, that it works only when I make my app's bigger. When I try to lower its dimensions, the label's dimensions remain the same. Why the label don't make its size smaller?
    My code works as follows: when app's main frame is resize, the panel (the one, that the label is placed in) is also resized. And, since the label is in the panel, it (should) also be resized. So I wrote all the resize-events handlers (therefore I know that the resize event is sent when my app's frame is resized, and when the panel is resized - but the label is resized only when it grows bigger). In this methods I modify the image displayed in the label (I resize the image).
    Or, perhaps, there is some other way to show a (dynamically changing) image with Swing... I chose JLabel, because I didn't want to write my own JComponent. JLabel can display image and that is all I need. The problem is: when the label grows bigger, I create a new, bigger image (icon). Why my label don't get smaller (the resize event isn't even sent)?

    There is no component that dynamically resizes an image. You need to create your own. Something like this:
    JComponent component = new JComponent()
         protected void paintComponent(Graphics g)
              //  Scale image to size of component
              g.drawImage(yourImage, 0, 0, getWidth(), getHeight(), null);
    };

  • I had this video file and I was trying to flip it to a format that would work with iMovie.  It used to have the Quicktime image with it.  So, I assume it was a QT file.  But, somehow I've changed the file from a video to a folder.

    I had a video file and I was trying to flip it to a format that would work with iMovie.  It used to have the Quicktime image with it.  So, I assume it was a QT file.  But, somehow I've changed the file from a video to a folder.  I've tried to undo the action.  No luck.  I wasn't running my Time Machine.  So, I can't go back.  Help.  It's the only copy of this video.

    I've tried to undo the action.
    How?
    Please detail ALL you have done so far in the way of troubleshooting?   Need this info to avoid the been there done that scenarios.
    it's the only copy of this video.
    Where did you get the video from?
    From the pic I noticed that the folder is 841.9mb.  What's inside?  Or what happens when you click on it?

  • I've been editing images with ease for a long time but now the changes are not being saved.

    I've been editing images with ease for a long time but now the changes are not being saved.
    Also, it is not liking me adding a large ammount of images in one go?

    Remember: we cannot see your machine. There are 9 different versions of iPhoto and they run on 8 different versions of the Operating System. The tricks and tips for dealing with issues vary depending on the version of iPhoto and the version of the OS.  So to get help you need to give as much information as you can. Basic things like :
    - What version of iPhoto.
    - What version of the Operating System.
    - Details. As full a description of the problem as you can. For instance: 'iPhoto won't export' is best explained by describing how you are trying to export, and so on.
    - History: Is this going on long? Has anything been installed or deleted?
    - Are there error messages?
    - What steps have you tried already to solve the issue.
    - Anything unusual about your set up? Or how you use iPhoto?
    Anything else you can think of that might help someone understand the problem you have.

  • Image with transparent background changes surrounding fill color when PMS...

    Hello.
    I have a .PSD image I'm using in InDesign CS3. It's a greyscale image with a transparent background. When I bring it into InDesign and set the background color of the image box to a Pantone and then print it, the PMS color within the area of the .PSD image size changes color compared to the rest of the page. But, when the same document is printed, but with "All Spot to Process" via the Ink Manager, the page prints fine. I get the same results on a number of different Canon and Xerox proofing printers. I have uploaded a PDF to my web server showing an example of the results I'm getting the PDF can be found here:
    http://theboyk.net/temp/PMSvsCMYK.pdf
    The first page is the document printed normally. You can see the color change in the green (Pantone Green). The second page is the same document printed with "All Spot to Process" via Ink Manager.
    Does anyone know why this happens when I leave it as printing a spot color?
    Any advice would be appreciated!
    Thanks,
    Kristin.

    I totally forgot to put that in my post.  Yes, I am putting logos with transparent backgrounds in front of colored rectangles.  That's how I noticed that this one logo is showing up with a white background.  The weird thing is that the other two logos are fine.  I did find a different version of this logo and this one works fine.  The one that works fine is a JPG and the one that shows up with a white background is a JPG.

  • Smart Collection for images with changed metadata not written to disk?

    The thumbnails in the grid view have a little icon in the upper right corner when the metadata for the file has been changed but not written to the XMP (or whatever) files.
    Is it possible to create a LR2 Smart Collection, or maybe a filter, that will find all such images?

    Dave, good to know that Ctrl-S on everything will write it all out.
    John, I *hate* being blind about what is going on. So I can Ctrl-S on everything and get it all written out. But I can't tell how many images I have changed, or perhaps also sort them by type so I can see what kinds of files will have to be rewritten. I can't even tell if I've remembered to do a Ctrl-S and whether there are images with data only in the catalog and not in the XMP etc. files.
    I'm one of those who are more comfortable if everything that can be recorded in XMP is recorded there. But I don't want to leave auto-write to XMP on while re-organizing everything.

  • Why all processed image with JAI will change into images with 96DPI?

    i think this is the disadvantage of JAI.I have an image with 300*300DPI.
    but when i read the image ,and saved it,it become an image with 96DPI.I truely need 300DPI.Does anyone can solve this problem.Thanks.

    I've just done a few more tests. Using the image I have described (a portrait with a Layer Mask, and in the Mask I have painted in black to remove certain parts), if I add a new layer and move it to the bottom the image doesn't change. When I fill the new layer with white, the image 'fattens'. Then when I SELECT ALL on the new layer, and Edit > Clear, the image slims down again.
    I can't get a grip on that. When I create a new layer, what is on the new layer? Why, when I fill that new layer with white, does the image 'fatten.'
    It seems to me I shouldn't have to create a new base layer and fill it with white to ensure that PS properly displays an image.
    If anyone wants to see the effect, I have uploaded the image (Tiff, 1.9 MB ) to:
    http://www.mediafire.com/?1jt3vmg5dxn

  • Capture image with webcam: how to change image orientation

    Hi all,
    I have taken the code shown in thread http://forum.java.sun.com/thread.jspa?threadID=570463&tstart=0, and it works ok (many thanks for it).
    However, all webcam resolutions are in "landscape" mode (e.g. 320 x 240), but I would like to capture a "portrait" image (e.g. in 240 x 320).
    Do you know any easy way to do it (but not physically tilting the camera, so that the video in the screen is shown in its correct orientation)?
    Best regards.

    Hi Owen,
    in my current application I don't need right now to use any large image, so that I have decided to implement a "simple" solution as the first one that you appointed: to use a transparent rectangle above the image, and then crop the saved image withing the limits of this rectangle.
    In order to do it, I have modified your code so that the panel (visualContainer) where to show the image is using an OverlayLayout format:
    <address>visualContainer = new JPanel();</address>
    <address>OverlayLayout overlay = new OverlayLayout(visualContainer);</address>
    <address>visualContainer.setLayout(overlay);</address>
    I have added one class to create the transparent rectangle, using a code like this:
    class TopPanel extends JPanel
    Point loc;
    int width, height;
    public TopPanel()
    setOpaque(false);
    width = 50;
    height = 50;
    protected void paintComponent(Graphics g)
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    if(loc == null)
    init();
    g2.setPaint(Color.blue);
    g2.drawRect(loc.x, loc.y, width, height);
    private void init()
    int w = getWidth();
    int h = getHeight();
    loc = new Point();
    loc.x = (w - width)/2;
    loc.y = (h - height)/2;
    In order to show the rectangle, what I have done is to add a TopPanel() to visualContainer just before adding the Player visualComponent.
    However, by doint in this way, the rectangle is not shown, but only the webcam image. I don't know if I'm doing something wrong, so any help on this issue is welcome.
    Best regards,
    izk

  • Changing an image with an alpha to a layer

    OK this is going to be tricky to explain. I have an image...it's a house I rendered in Cinema 4D. It has an alpha channel which of course is the outline of the house. I'd like to edit the house...for example, make the roof wider. Of course I can do this, but I can't have it edit the alpha, too. Is there any way to do this? I know you can create layers and delete the edges of an object and do it that way...but my image is flat with an alpha channel. Is there a way to convert my house to a layer and have the black erased?
    Ultimately, I'd like to take my image and then add a layer and copy the house to a layer, and not have the black background come with it. I would assume there's a way to convert an image with an alpha channel to a new layer, but I'm not sure how

    Another way...(Assuming I read what you want correctly. lol.)
    On the layers panel drag the little lock, side of the layer to the trash can, this will convert the background layer to a normal layer.
    In the menu goto select>Load selection - For the channel select your alpha channel. (This uses your alpha channel for a selection)
    Make sure your layer is still selection if you have more than one layer
    Select the third from the left icon at bottom of layer panel (looks like a square with a circle in the middle) This will create a mask using the selection.
    Now what was white in the alpha chanel is visible and what was black is now transparent.
    Now your image has a mask and since there is a link between the two you can scale the image and the mask at the same time.

  • How do I change stills with each menu item selected?

    Hi all.
    I am trying to create a menu (with 10 items) which contains one single dropzone box, which will contain a still that changes with each menu item selected (instead of 10 different stills next to each item).
    I have absolutely no idea how to achieve this! Do I create a different menu for each item? Is there a way to have a slideshow within the menu that changes with each item selected?
    Please help!
    Many thanks
    James

    THe way to do what you want to do is layered menus which have some limits
    http://dvdstepbystep.com/layersover.php
    What you would do is change the item that appears in the same section - in other words there would be ten layers with a diffrerent picture in the same exact spot, the rectangle buttons sections do not need to be over the picture section
    http://dvdstepbystep.com/Layers_Example.dmg is a project that does changing images.

  • I am considering upgrading to lightroom 5. But first can I talk to someone to fix a major issue. My catalogue has disappeared and a new one without my chosen images has taken its place.I need to retrieve my original duplicate/ changed images?

    Hi there,
    I am considering up grading to lightroom 5. But first I need to be sure I can retrieve my original library, which has been replaced by images from iphoto I hadn't slected. I currently use a lightroom 3 and have spent countless hours as a professional photographer improving my original photographs. Can I speak to someone regarding this matter?
    I would really appreciate your help in resolving this matter asap.
    Kind reagards
    Pablo

    Morning Geoff,
    Hope you slept well. I have been busy looking into many of the things you
    have told me.
    Where should I start so much info.
    There are 7 Ircat folders. Some empty some contain approx 7000 images. Some
    of the images /altered on lightroom are here few maybe 50. Although they
    are missing or offline and now in the CR2 format ( photoshop elements),
    which is very strange. I think this an issue as to why it may have all
    gone, changed? In another Ircat folder many images are in the condition I
    left them although not all of them, the latest 2013 are missing. Also in
    another extension Ircat folder many of the images are there I imagine the
    same 7000 but cant be seen?
    On my hard drive there is a folder I cannot open, it reads in progress and
    says no App to open document, search App store for Application. Perhaps
    this is the key, I also have little storage space on my hard drive.
    Many images under 2012 on hard drive have the tiff image, with altered
    version created on lightroom some now show as CR2 version to view the photo
    photoshop elements opens up automatically, which I never use. I do feel
    this is a major reason/ issue?
    Also under certain folders with dates my images appear pixelated or blurry.
    Under another heading the jpg version is great approx 73 some are missing
    the latest and most important, unfortunately I want in Tiff.
    Under another folder on hard drive I have many of the images I am chasing
    approx 60 but the size is a concern 2-2.5mb, should be around 40mb?
    In another folder all are in CR2 photoshop elements.
    Time Machine, which I'm sure was inactive tells me it could not back up
    disk?
    Under thumbnails it looked promising all in DNG many missing and in CR2
    format.
    I thought I would let you know in case I haven't already that the memory on
    the imac is very low, hence why I began trashing/ deleting images yesterday
    thet are saved on my hard drive this is when all this mess occured.
    Are there short cuts I can use to remove images that are duplicates without
    lightroom becoming tempermental?
    Were too next? I am hoping the originals can be found and installed in
    their original form.
    I really appreciate all of your help and time, please help me
    Cheers mate
    Pablo
    On Mon, Dec 29, 2014 at 8:06 PM, Pablo Hughes <[email protected]>

Maybe you are looking for