Getting Enemy Objects to Draw Images

Hello!
I am coding a simple game as a practice example. The premise is your player appears on the left of the screen, while enemies swarm from the right side. You can fire your gun which creates Bullet objects that kill the zombies.
My problem is coming from a little detail I want to implement. Basically I want my zombies to have a chance of mumbling, something along the lines of "brains" "mmm" and other Zombie text. I have these as gif images, and I want to display the image as long as the Zombie remains mumbling. This is done in my drawZombie(Graphics g) method.
I have implemented a method but it doesn't seem to work. I am running through an array of Zombies and checking if they are mumbling, if they are not I set them to mumble if the event occurs using a Random object. All of the zombies appear to have the event occur at the same time and as result they all speak at once, following the same intervals.
http://data.tumblr.com/XaNEMhnY045oyvsjV6Wq94hE_500.gif
Within Zombie Class:
     public void zombieChange()
          if(alive)
               //Mumbles:          
               if(isMumbling == false)
                    checkMumble();
               xPos = xPos - speed;
               frame++;
               if(frame >= walk.length)
                    frame = 0;
     public void checkMumble()
          text = (int)Math.random() * 4;
          if(text < 1)
               isMumbling = true;
               text = r.nextInt(3) + 1;
     public void drawZombie(Graphics g)
          if(alive)
               g.drawImage(walk[frame], xPos, yPos, parent);
               if(isMumbling && textDuration > 0)
                    if(text == 1)
                         g.drawImage(ugh, xPos+5, yPos-20, parent);
                    else if(text == 2)
                         g.drawImage(mmm, xPos+5, yPos-20, parent);
                    else
                         g.drawImage(brains, xPos+5, yPos-20, parent);
                    textDuration = textDuration - 1;                    
               else {isMumbling = false; textDuration = 50;}
          }Within Main Class:
               for(Zombie e : z)
                    if(e != null)
                         e.zombieChange();
                         //Check Player Death:
                         if(e.getXPos()-10 < playerOne.getXPos())
                              System.out.println("hit");
                              playerOne.setIsFiring(false);
                              playerOne.setIsStill(false);
                              playerOne.setIsMovingLeft(false);
                              playerOne.setIsMovingRight(false);
                              playerOne.setIsAlive(false);
               }Here is the source:
http://www.sendspace.com/file/093qz5
http://www.megaupload.com/?d=ZBJB9HH7
What is the problem? Any ideas? I am aware there are errors in my code, I am just fooling around with ideas for now. Thanks.

Look at the line:
          text = (int)Math.random() * 4;Math.random() returns a number >= 0.0 and < 1.0. This is cast to an int then multipled by 4. However, the cast will always truncate the value to zero, thus text will alway equal zero after this line. Why not just use text = r.nextInt(4) instead? You already have the Random and use it in the next couple lines.

Similar Messages

  • Problems drawing images form another class

    Ok as the title says I'm having trouble drawing images from a different class. I have a class that represents a plane and it has a draw' method that draws its .gif image.
    public void draw (Graphics g)
    g.drawImage(planepic , xPos, yPos, null)
    then in my main class in the paint method i have
    plane.draw(g);
    I think my problem is the null for my image observer. I tried using null as my image observer and i got a error saying i can't make a static reference to a non static method.
    I've done some research because i never really understood static but i still don't quite get it.
    Also when I use this as my image observer i get a error in my plane object.
    I also just tried passing and making a object for my main class and i still got the static error.
    Any help is appreciated and thanks in advance

    Ok as the title says I'm having trouble drawing
    images from a different class. I have a class that
    represents a plane and it has a draw' method that
    draws its .gif image.
    public void draw (Graphics g)
    g.drawImage(planepic , xPos, yPos, null)
    in my main class in the paint method i have
    plane.draw(g);
    I think my problem is the null for my image observer.
    I tried using null as my image observer and i got a
    error saying i can't make a static reference to a non
    static method. Use a minimal implementation of the ImageObserver to be sure.
    public class Plane implements ImageObserver
    public boolean imageUpdate(
    Image img,int infoFlags,int x,int y,int width,int height)
       switch(infoFlags)
          case ALLBITS:
                    return false;
          case SOMEBITS:
                    return true;
          default:
                return true;
    I've done some research because i never really
    understood static but i still don't quite get it.
    Also when I use this as my image observer i get a
    error in my plane object.
    I also just tried passing and making a object for my
    main class and i still got the static error.
    Any help is appreciated and thanks in advanceWhen you call draw(g) from your other class you hand it a Graphics context that you instantiated somewhere else ie: in another class. Without a more complete example it is really impossible to determine your issue for sure,
    but if I was to guess I would say you need to make sure that the Graphics context handed to the draw(Graphics) method was instantiated from a Component that was already visible. ie: Do a f
    Frame.createImage() from your parent frame after iyou have already called setVisible(true); In other words I suspect you are making and Image from some other Component that is not yet visible. That however is a guess so if not the issue post the rest of the code or at least a minimal implementation that demonstrates this.
    About static:
    static means the class/variable is the same throughout ALL classes of that type and if changed in one instance it will change and thus be the same for all instances.
    You CAN call static by referencing the base class Object without having to instantiate.
    ie:given
    public class SomeClass
    static String name;
    static String getName
       if(name == null)
          name = "DefaultName";
       return name;
    }Thus you could call..
      String name = SomeClass.getName();As opposed to
    SomeClass myClass = new SomeClass();
          myClass.getName();This can get you in trouble if you try to make a method that is static
    that then tries to reference non static variables.
    ie:
    public class SomeClass
    int x;
    static String name;
    SomeClass()
       x=0;
    static String getName
       if(name == null)
          name = "DefaultName";
       x++;
       return name;
    }In this case SomeClass.getName(); will throw and exception because it is trying to access[b] x  from a static context .
    Hope that clears that up for you; if not post a more complete example.
    Good Luck!
    (T)

  • Get a graph to draw

    I am using the data visualization tools tag library and manually setting the data via the tabularData attribute.
    Here is the relevant portion of my JSF (jspx) page:
         <dvt:graph id="tgraph" imageFormat="PNG" stylePath="Comet"
              tabularData="#{identity.tabularData1}" imageWidth="200"
              threeDEffect="true" graphType="BAR_VERT_CLUST"
              contentDelivery="immediate" shortDesc="Chart"
              imageHeight="100">
         </dvt:graph>
    The tabularData1 field in the identity bean at this point contains just some hard coded values. e.g.:
         Calendar cal = Calendar.getInstance();
         long time = cal.getTimeInMillis();
         tabularData1.add(new Object[]{ new Date(time), "A", Double.valueOf(1D) });
         tabularData1.add(new Object[]{ new Date(time), "B", Double.valueOf(1D) });
         tabularData1.add(new Object[]{ new Date(time + 86400000L), "A", Double.valueOf(2D) });
         tabularData1.add(new Object[]{ new Date(time + 86400000L), "B", Double.valueOf(2D) });
         tabularData1.add(new Object[]{ new Date(time + 172800000L), "A", Double.valueOf(3D) });
         tabularData1.add(new Object[]{ new Date(time + 172800000L), "B", Double.valueOf(3D) });
    As far as I can tell from reading many other threads, I believe I've done all that part right. The problem is that it will not actually display the graph. No error messages are displayed or logged either.
    Is there another command that I need to run to actually get it to create the image?
    I've also tried this through binding and using the setTabularData method too, but to no avail.
    My Web application has the following libraries in it. Am I missing some?
         adflogginhandler.jar
         adfm.jar
         adfshare.jar
         adfsharebase.jar
         dvt-face.jar
         dvt-jclient.jar
         dvt-utils.jar
         jewt4.jar
    Thanks,
    David

    Thanks. I tried that it mine and I still can't get it to draw.
    Therefore I started a whole new project with only this in it. Here are my files. Is there something that I'm leaving out.
    Test.jspx:
    &lt;?xml version='1.0' encoding='utf-8'?&gt;
    &lt;jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
    xmlns:dvt="http://xmlns.oracle.com/dss/adf/faces"
    version="2.1"&gt;
    &lt;jsp:directive.page contentType="text/html;charset=utf-8"/&gt;
    &lt;f:view&gt;
    &lt;af:document title="Test Document" maximized="true"&gt;
    &lt;af:panelGroupLayout layout="vertical"&gt;
    &lt;af:messages/&gt;
    &lt;af:panelGroupLayout layout="horizontal" halign="center"&gt;
    &lt;dvt:graph id="tgraph" imageFormat="PNG" stylePath="Comet"
    tabularData="#{testBean.tabularData}" imageWidth="400"
    threeDEffect="true" graphType="BAR_VERT_CLUST"
    contentDelivery="immediate" shortDesc="Chart"
    imageHeight="400"&gt;
    &lt;/dvt:graph&gt;
    &lt;/af:panelGroupLayout&gt;
    &lt;/af:panelGroupLayout&gt;
    &lt;/af:document&gt;
    &lt;/f:view&gt;
    &lt;/jsp:root&gt;
    faces-config.xml:
    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
    &lt;faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee [http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd]"
    version="1.2"&gt;
    &lt;application&gt;
    &lt;default-render-kit-id&gt;oracle.adf.rich&lt;/default-render-kit-id&gt;
    &lt;/application&gt;
    &lt;managed-bean&gt;
    &lt;managed-bean-name&gt;testBean&lt;/managed-bean-name&gt;
    &lt;managed-bean-class&gt;test.TestBean&lt;/managed-bean-class&gt;
    &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt;
    &lt;/managed-bean&gt;
    &lt;/faces-config&gt;
    TestBean.java:
    package test;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.List;
    import com.att.utils.DateUtil;
    public class TestBean {
    private List&lt;Object[]&gt; tabularData = new ArrayList&lt;Object[|http://forums.oracle.com/forums/]&gt;();
    public TestBean() {
    Calendar cal = DateUtil.zeroCalendarFields(Calendar.getInstance(), DateUtil.ZERO_DAY);
    cal.add(Calendar.MONTH, -1);
    long time = cal.getTimeInMillis();
    tabularData.add(new Object[]{ new Date(time), "A", Double.valueOf(100) });
    tabularData.add(new Object[]{ new Date(time), "B", Double.valueOf(150) });
    tabularData.add(new Object[]{ new Date(time + 86400000L), "A", Double.valueOf(200) });
    tabularData.add(new Object[]{ new Date(time + 86400000L), "B", Double.valueOf(250) });
    tabularData.add(new Object[]{ new Date(time + 172800000L), "A", Double.valueOf(300) });
    tabularData.add(new Object[]{ new Date(time + 172800000L), "B", Double.valueOf(350) });
    public List&lt;Object[]&gt; getTabularData() { return tabularData; }
    * @param tabularData
    public void setTabularData(final List&lt;Object&gt; tabularData) {}
    WebTest.war: (files in WAR)
    WebTest.war/Test.jspx
    WebTest.war/WEB-INF/
    WebTest.war/WEB-INF/classes
    WebTest.war/WEB-INF/classes/test
    WebTest.war/WEB-INF/classes/test/TestBean.class
    WebTest.war/WEB-INF/faces-config.xml
    WebTest.war/WEB-INF/lib
    WebTest.war/WEB-INF/lib/adf-richclient-api-11.jar
    WebTest.war/WEB-INF/lib/adf-richclient-impl-11.jar
    WebTest.war/WEB-INF/lib/adflogginghandler.jar
    WebTest.war/WEB-INF/lib/adfm.jar
    WebTest.war/WEB-INF/lib/adfshare.jar
    WebTest.war/WEB-INF/lib/adfsharebase.jar
    WebTest.war/WEB-INF/lib/dvt-faces.jar
    WebTest.war/WEB-INF/lib/dvt-jclient.jar
    WebTest.war/WEB-INF/lib/dvt-utils.jar
    WebTest.war/WEB-INF/lib/jewt4.jar
    WebTest.war/WEB-INF/lib/share.jar
    WebTest.war/WEB-INF/lib/trinidad-api-1.2.9.jar
    WebTest.war/WEB-INF/lib/trinidad-impl-1.2.9.jar
    WebTest.war/WEB-INF/lib/xercesImpl-2.6.2.jar
    WebTest.war/WEB-INF/lib/xmlparserv2.jar
    WebTest.war/WEB-INF/web.xml
    I figure I'm missing something simple, but I just can't figure it out. I've also tried it in both FireFox and IE, but neither one display a graph. The only error I get is something about ActiveData, but I believe that isn't relative here.
    Thanks again,
    David

  • Color Matrix Alpha values and drawing images.

    Hi All,
    I am experimenting with using a color matrix to change images and have brightness, R, G, B changing but the alpha does not seem to do anything. I have a scrollbar for the alpha value in the matrix in the example. It seems it should change the image in some
    way but it does not.
    In this example I put 1 for red in the matrix thinking as I moved the scroll bar the alpha transparency would change the image in some way but it does not? It does not matter what colors or image I use nothing seems to happen with alpha? Is it
    only for drawing lines and such or does it do something to images? If so what?
    Imports System.Drawing.Imaging
    Public Class Form3
    Private rustybmp As New Bitmap("c:\bitmaps\rusty.jpg")
    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.DoubleBuffered = True
    VScrollBar1.Maximum = 100
    VScrollBar1.Minimum = 0
    VScrollBar1.Value = 50
    End Sub
    Private Sub Form3_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
    Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
    {New Single() {1, 0.0, 0.0, 0.0, 0.0}, _
    New Single() {0.0, 1, 0.0, 0.0, 0.0}, _
    New Single() {0.0, 0.0, 1, 0.0, 0.0}, _
    New Single() {0.0, 0.0, 0.0, 1.0, 0.0}, _
    New Single() {1, 0, 0, VScrollBar1.Value / 100, 1}})
    Dim image_attr As New ImageAttributes
    image_attr.SetColorMatrix(cm)
    e.Graphics.DrawImage(rustybmp, Me.ClientRectangle, 0, 0, rustybmp.Width, rustybmp.Height, GraphicsUnit.Pixel, image_attr)
    End Sub
    Private Sub VScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles VScrollBar1.Scroll
    Me.Refresh()
    End Sub
    End Class

    I didn't try this.
    How to: Use a Color Matrix to Set Alpha Values in Images
    La vida loca
    Oh, ok, in your link example the alpha is the 4 row 4 col.
    I was using the 5th row 4th col because I thought that was R, G, B A across the 5th row. Maybe that is for a solid brush or something.
    This works as I expected that way. Still looking....
    Dim cm As ColorMatrix = New ColorMatrix(New Single()() _
    {New Single() {1, 0.0, 0.0, 0.0, 0.0}, _
    New Single() {0.0, 1, 0.0, 0.0, 0.0}, _
    New Single() {0.0, 0.0, 1, 0.0, 0.0}, _
    New Single() {0.0, 0.0, 0.0, VScrollBar1.Value / 100, 0.0}, _
    New Single() {0, 0, 0, 0, 1}})
    Cool!
    Now if you could just get that working with HoloLens..... :)
    La vida loca

  • Dashcode: How do I get the name of an image in a website?

    I'm making a widget that gets the filename of an image on a website and it changes the value of some parts of the widget if the filename has a certain name. The only problem is that I don't know how to get the name of this image in the widget. Could somebody please help me?

    If I understand well, I think that the XMLHttpRequest object may help you. Please check the following link:
    http://developer.apple.com/internet/webcontent/xmlhttpreq.html
    Also, if you can program in Perl (or some other scripting language), you can use an external script to read the filename and send it to your Widget.
    Mihalis.

  • How to Get a Video Thumbnail preview image in sharepoint Asset Library

    namespace ConsoleApplication3
    class Program
    static void Main(string[] args)
    using (var site = new SPSite("http://contoso/sites/teams"))
    using (var web = site.OpenWeb())
    var list = web.Lists.TryGetList("Videos");
    var videoProperties = new Dictionary<string, object>();
    videoProperties["Keywords"] = "Intranet Video";
    //videoProperties["AlternateThumbnailUrl"] = "/_layouts/images/preview.jpg";
    UploadVideo(list, @"C:\Downloads\Video3.mp4", videoProperties);
    public static void UploadVideo(SPList list,string fileName,IDict ionary<string,object> properties)
    SPFile file;
    using (var fileStream = File.OpenRead(fileName))
    var urlOfFile = SPUrlUtility.CombineUrl(list.RootFolder.ServerRelativeUrl, Path.GetFileName(fileName));
    file = list.RootFolder.Files.Add(urlOfFile, fileStream, true);
    list.Update();
    //listid = list.ID.add();
    SPListItem listItem = list.GetItemById(file.ListItemAllFields.ID);
    //SPListItem listItem = list.GetItems("Video3");
    var videoContentType = list.ParentWeb.Site.RootWeb.AvailableContentTypes["Video"];
    // listItem["ContentTypeId"] = videoContentType.Id;
    foreach (var property in properties)
    listItem[property.Key] = property.Value;
    listItem.Update();
    in this code "SPListItem listItem = list.GetItemById(file.ListItemAllFields.ID); " im getting null reference exception.an i have tried with other line "var listItem = file.ListItemAllFields;" same error.any one help me to get solve this
    issue.And how to Get a uploaded video Thumnail image.

    Hi,
    I did a test with your code in my environment and it works fine.
    For a better troubleshooting, I suggest you debug your code step by step. You may need to check if file.ListItemAllFields.ID is valid.
    If you want to get video Thumnail image, there is a column named Preview Image URL, the internal name of the field is AlternateThumbnailUrl.
    You can get the field value using Sever Object Model like below.
    String url = item[“AlternateThumbnailUrl”].ToString();
    Here is a similar thread for your reference:
    http://social.technet.microsoft.com/Forums/en-US/251974d8-18ac-4ff9-88a2-633b5bd80fce/get-asset-library-column-value-preview-image-url-programmatically?forum=sharepointgeneralprevious
    More information about how to get list item using Server Object Model:
    http://msdn.microsoft.com/en-us/library/office/ms460897%28v=office.14%29.aspx
    Best regards,
    Zhengyu Guo
    Zhengyu Guo
    TechNet Community Support

  • Unable to install supporting objects(custom CSS/Images) through SQL

    4.2.1
    Hi there,
    we have a Apex app which uses custom CSS/images loaded into shared objects CSS and image folders respectively. I followed the steps
    http://nerd.net.au/29-apex-application-express/general-application/122-include-images-with-supporting-objects-on-apex-export-import
    Now, this works fine when we manually import the application through application builder, it "prompts" if we want to install supporting objects, when yes is selected, everything gets installed.
    MY problem is we have an automated patching process where the .sql application file gets installed but the supporting objects are not. So I tried bundling the supporting object as a separate .sql file but got an error
    Testing options PL/SQL procedure successfully completed. declare * ERROR at line 1: ORA-20001: Package variable g_security_group_id must be set. ORA-06512: at "APEX_040200.WWV_FLOW_IMAGE_API", line 11 ORA-06512: at "APEX_040200.WWV_FLOW_IMAGE_API", line 31 ORA-06512: at
    The supporting object is a button. Do I need to set the application id or security group id or something else?
    begin
    wwv_flow_api.g_varchar2_table := wwv_flow_api.empty_varchar2_table;
    wwv_flow_api.g_varchar2_table(1) := '89504E470D0A1A0A0000000D494844520000009600000051080600000030EC5FEE000000097048597300000B1300000B1301009A9C1800000A4D6943435050686F746F73686F70204943432070726F66696C65000078DA9D53775893F7163EDFF7650F56';
    wwv_flow_api.g_varchar2_table(2) := '42D8F0B1976C81002223AC08C81059A21092006184101240C585880A561415119C4855C482D50A489D88E2A028B867418A885A8B555C38EE1FDCA7B57D7AEFEDEDFBD7FBBCE79CE7FCCE79CF0F8011122691E6A26A003952853C3AD81F8F4F48C4C9BD80';
    wwv_flow_api.g_varchar2_table(3) := '021548E0042010E6CBC26705C50000F00379787E74B03FFC01AF6F00020070D52E2412C7E1FF83BA50265700209100E02212E70B01905200C82E54C81400C81800B053B3640A009400006C797C422200AA0D00ECF4493E0500D8A993DC1700D8A21CA908';
    wwv_flow_api.g_varchar2_table(4) := '008D0100992847240240BB00605581522C02C0C200A0AC40222E04C0AE018059B632470280BD0500768E58900F4060008099422CCC0020380200431E13CD03204C03A030D2BFE0A95F7085B8480100C0CB95CD974BD23314B895D01A77F2F0E0E221E2C2';
    wwv_flow_api.g_varchar2_table(5) := '6CB142611729106609E4229C979B231348E7034CCE0C00001AF9D1C1FE383F90E7E6E4E1E666E76CEFF4C5A2FE6BF06F223E21F1DFFEBC8C020400104ECFEFDA5FE5E5D60370C701B075BF6BA95B00DA560068DFF95D33DB09A05A0AD07AF98B7938FC40';
    wwv_flow_api.g_varchar2_table(6) := '1E9EA150C83C1D1C0A0B0BED2562A1BD30E38B3EFF33E16FE08B7EF6FC401EFEDB7AF000719A4099ADC0A383FD71616E76AE528EE7CB0442316EF7E723FEC7857FFD8E29D1E234B15C2C158AF15889B850224DC779B952914421C995E212E97F32F11F96';
    wwv_flow_api.g_varchar2_table(7) := 'FD0993770D00AC864FC04EB607B5CB6CC07EEE01028B0E58D27600407EF32D8C1A0B91001067343279F7000093BFF98F402B0100CD97A4E30000BCE8185CA894174CC608000044A0812AB041070CC114ACC00E9CC11DBCC01702610644400C24C03C1042';
    wwv_flow_api.g_varchar2_table(8) := '06E4801C0AA11896411954C03AD804B5B0031AA0119AE110B4C131380DE7E0125C81EB70170660189EC218BC86090441C8081361213A8811628ED822CE0817998E04226148349280A420E988145122C5C872A402A9426A915D4823F22D7214398D5C40FA';
    wwv_flow_api.g_varchar2_table(147) := 'A514B7B6B6EA5AADA60B8582EAECEC54511471BD5EE7BEBE3EBF4E108FCA58FE9601580A68199FDAF12F8D1DDB5E3386221ADD8E3AF3CEC772A73505D60820C32BF0238E6DAF5D508DBAFFF2CFACE20C3E9A03E2789F3430B68D6DAF641BF33D8D6D63C0';
    wwv_flow_api.g_varchar2_table(148) := '1ADBC68035B68D016B6C1BDBC68035B6BD46B6FF3B0074B1DD40306DC6CD0000000049454E44AE426082';
    end;
    declare
        l_name   varchar2(255);
    begin
        l_name := 'logo.png';
      wwv_flow_api.create_or_remove_file(
         p_name=> l_name,
         p_varchar2_table=> wwv_flow_api.g_varchar2_table,
         p_mimetype=> 'image/png',
         p_location=> 'WORKSPACE',
         p_nlang=> '0',
         p_mode=> 'CREATE_OR_REPLACE',
         p_type=> 'IMAGE');
    end;
    /

    Thanks Fac586! I did follow the process on those lines and was able to successfully get the images, application installed. The CSS which just had
    body {
         background-color:#000000;
    }Was also applied. However, it for some reason does not work. Looks like the CSS is not getting loaded. When I delete the CSS and upload it again through the shared components->CSS folder, it works fine. Not sure what the solution is!
    Oh and by the way, thanks a ton for helping everyone!
    Cheers,
    Ryan

  • How can get a Graphics to draw line on screen?

    How can get a Graphics to draw line on screen?
    Now, I can get a Graphics to draw line based on component. For example JPanel, but I want to get a Graphics to draw line on screen.

    By drawing on the screen, I assume you mean drawing outside the bounds of a top-level window like
    JFrame or JDialog. You can't do that. At least, without going native and even then that's a dodgey thing
    for any platform to let you do. One thing you can do is simulate it with a robot's screen capture:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class X {
        public static void main(String[] args) throws Exception {
            Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
            BufferedImage image = new Robot().createScreenCapture(bounds);
            Graphics2D g2 = image.createGraphics();
            g2.setStroke(new BasicStroke(20));
            g2.setPaint(Color.RED);
            g2.drawLine(0, 0, bounds.width, bounds.height);
            g2.drawLine(bounds.width, 0, 0, bounds.height);
            g2.dispose();
            JLabel label = new JLabel(new ImageIcon(image));
            label.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent evt) {
                    System.exit(0);
            JFrame f = new JFrame();
            f.setUndecorated(true);
            f.getContentPane().add(label);
            f.setBounds(bounds);
            f.setVisible(true);
    }

  • How can i get session object based on session id?

    I have tried searching in forum but i can't find any solution that i can get session object based on session id and i also would like to know how to check whether the session is still active? My company currently using weblogic 5.1. I really hope that some one or anyone can help. I am new in using Servlet. I hope that i can find some answer here. Thank you.

    I have a need to get a Session object from a session id, so I don't think that the above should be deprecated. Here is my use case:
    0. I am displaying files in a file list
    1. I am downloading files.
    2. I am downloading files through a Servlet
    3. I am displaying the files as images in an applet
    4. The applet is ImageJ, and it apparently uses a full URL to download the file.
    5. I use request.getRequestURL() in the applet .jsp to get the full URL (the hostname and port)
    6. My app server is OC4J and it's behind an apache server and is host aliased.
    7. Thus the hostname is different between my applet .jsp and the Servlet URLs
    8. Thus I have 2 different sessions
    9. Thus I need to pass the session id (or some other unique identifier).
    10. I could stored the unique identifier in the application object, but then I would need to clean it up
    11. I cannot pass the the full path to the image due to security problems (what if someone downloads my password file?)
    12. I would like this to work in a clustered environment
    13. I think that WebDAV would solve my problems, since I could pass a full URL of webDAV to ImageJ for download. However, I am unsure how the security of WebDAV would work with ImageJ/URLConnection. I will have to research this feature in ImageJ.

  • Does acrobat has any option to read pdf content objects(stamps, layers, images etc) without using pl

    Does acrobat has any option to read pdf content objects(stamps, layers, images etc) without using plug-in in c#.net ?
    My requirement is read a pdf file and extract all the page objects(stampls, layers and images) along with its coordinates. Is it possible to get without using plug-ins in c#.net ?
    Please hlep me.

    These are very different things.
    JavaScript has some access to layers (called OCG). Layers are just names and have no coordinates to retrieve.
    Stamps may be annotations; there is some minimal access to these too I think. It may be hard to identify what is, and is not, a stamp even with a plug-in.
    Images are part of the actual page contents, and are only accessible to plug-ins.

  • I'm trying to access Window Handle (HWND) in Labview. This is an argument of a DLL. Also I need to get a pointer of an image buffer.

    Call library function in Labview:
    =================================
    Hi all,
    I'm trying to access a DLL using Call library function in Labview.
    1) I have problems in obtaining the window handle (hDC) of an object in Labview.
    2) Also to get the pointer of an image buffer.
    thanks
    Code Warrior
    Take life as it comes! you may never know what's gonna happen Tommorrow

    Bob Y. wrote:
    I'm trying to do something similar right now and coming to the same problems. I am trying to get the image from a Nikon DXM1200 camera that is mounted on a microscope. It has its own commands and capture card and is not playing well with the imaq stuff. I am using their SDK in an effort to get the images into LabVIEW.
    As I said, I am having the same types of problems. I managed to wrap everying into a dll and into a .net assembley, but I have been unable to figure out a way to get it into LabVIEW. I can call either of these things from LabVIEW to make an image capture. But, I have been unable to transfer that image into LabVIEW. I also have been unable to get enough windowing information to get the information into LabVIEW.
    I am not sure what Code Warrior is doing, but here is why I have been tracking this thread with great interest.
    Thanks for the thread,
    Bob
    You might want to look at http://www.hytekautomation.com/products.html. They have a Nikon interface for LabVIEW and since you already have the SDK, the issue mentioned on their site won't be a problem for you. It is for sure much more cost effective to pay them some money for that interface than trying to develop an interface yourself. The issues are quite involved and even if you knew quite some stuff about LabVIEW memory management and its internal C programming interface (and you can get quite some information from looking at the NI-IMAQ VIs too, eventhough they are anything but a nice example for good programming style), it is a work counting into weeks to get it done right.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Blast from the past: How do I draw image maps in Dreamweaver CC 2014?

    Need to update some old stuff, and can´t find where to draw image-maps on images.

    First, you need to be in Design View to get the image map tools to appear.
    Once there, the image map icons should show when you select an image. If they don't, you may have your Properties panel collapsed. In the bottom right corner of the Properties panel, there's a tiny triangle, click that to expand the panel to include the image map tools.

  • Detecting an object in an image

    hi all
    i need to know how to detect a particular object like a ball or a rectangular block within an image
    i tried opencv but it failed to detect an object within an image the C code used in JNI is given below
    #include <stdio.h>
    #include <stdlib.h>
    #include <jni.h>
    #include "sift.h"
    #include "imgfeatures.h"
    #include "kdtree.h"
    #include "utils.h"
    #include "xform.h"
    #include <cv.h>
    #include <cxcore.h>
    #include <highgui.h>
    #include "helloworld_HelloWorld.h"
    #define KDTREE_BBF_MAX_NN_CHKS 200
    /* threshold on squared ratio of distances between NN and 2nd NN */
    #define NN_SQ_DIST_RATIO_THR 0.49
    /******************************** Globals ************************************/
    char img1_file[] = "..\\football.png";
    char img2_file[] = "..\\sift.png";
    JNIEXPORT jint JNICALL
    Java_helloworld_HelloWorld_printNat(JNIEnv *env, jobject obj)
    IplImage * img1, * img2, * stacked;
         struct feature* feat1, * feat2, * feat;
         struct feature** nbrs;
         struct kd_node* kd_root;
         CvPoint pt1, pt2;
         double d0, d1;
         int n1, n2, k, i, m = 0;
         img1 = cvLoadImage( img1_file, 1 );
         if( ! img1 )
              fatal_error( "unable to load image from %s", img1_file );
         img2 = cvLoadImage( img2_file, 1 );
         if( ! img2 )
              fatal_error( "unable to load image from %s", img2_file );
         stacked = stack_imgs( img1, img2 );
         fprintf( stderr, "Finding features in %s...\n", img1_file );
         n1 = sift_features( img1, &feat1 );
         fprintf( stderr, "Finding features in %s...\n", img2_file );
         n2 = sift_features( img2, &feat2 );
         kd_root = kdtree_build( feat2, n2 );
         for( i = 0; i < n1; i++ )
              feat = feat1 + i;
              k = kdtree_bbf_knn( kd_root, feat, 2, &nbrs, KDTREE_BBF_MAX_NN_CHKS );
              if( k == 2 )
                   d0 = descr_dist_sq( feat, nbrs[0] );
                   d1 = descr_dist_sq( feat, nbrs[1] );
                   if( d0 < d1 * NN_SQ_DIST_RATIO_THR )
                        pt1 = cvPoint( cvRound( feat->x ), cvRound( feat->y ) );
                        pt2 = cvPoint( cvRound( nbrs[0]->x ), cvRound( nbrs[0]->y ) );
                        pt2.y += img1->height;
                        cvLine( stacked, pt1, pt2, CV_RGB(255,0,255), 1, 8, 0 );
                        m++;
                        feat1.fwd_match = nbrs[0];
              free( nbrs );
         fprintf( stderr, "Found %d total matches\n", m );
         cvNamedWindow( "Matches", 1 );
         cvShowImage( "Matches", stacked );
         cvWaitKey( 0 );
    cvReleaseImage( &stacked );
         cvReleaseImage( &img1 );
         cvReleaseImage( &img2 );
         kdtree_release( kd_root );
         free( feat1 );
         free( feat2 );
         return m;
    i donot want help exactly with opencv but a java code to detect an object within an image will be helpful and
    help on any modification i can make on the above program will be also helpful
    thank u                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi friend!
    I have the following issue:
    I'm trying to build a C++ DLL that uses OpenCV.
    But when I try to compile, I have the following errors:
    [Link Error] undefined reference to 'cvQueryFrame'
    [Link Error] undefined reference to 'cvReleaseCapture'
    [Link Error] undefined reference to 'cvReleaseImage'
    I'm using Dev-C++, and I set all the libraries directories correctly. If I try to compile an .exe file that uses OpenCV, it compiles successfully.
    Please help me! I'm getting "crazy" with that...

  • Getting NSData object from NSImage.

    I want NSData object from NSImage object.
    I looked in documentation and i didn't found any method to get back the data from image object. is it possible to retrieve NSData from NSImage ?
    Thanks....
    Message was edited by: xmax

    Somewhat ..
    - (NSData *)TIFFRepresentation
    Eric

  • How to get max 5 color from image??

    I try to get max 5 color from image (ex. jpeg,gif) ,I use PixelGrabber
    it too slowly when i use large image,Please help me, to run more fast
    (other way PixelGrabber)
    best regard
    [email protected],[email protected]
    source below:
    public String generateColor(InputStream source,String filePath){
    BufferedImage image = null;
    String RGB = "";
    System.out.println("==generateColor==");
    try {
    image = ImageIO.read(source);
    catch (IOException ex1) {
    ex1.printStackTrace();
    //image.getGraphics().getColor().get
    // BufferedImage image2 = ImageIO.read(source);
    // image.getColorModel().getNumColorComponents()
    if(image.getColorModel() instanceof IndexColorModel) {
    IndexColorModel icm = (IndexColorModel)image.getColorModel();
    byte[][] data = new byte[3][icm.getMapSize()];
    int[] rgbB = new int[icm.getMapSize()];
    icm.getRGBs(rgbB);
    String dataHtm = "<HTML><table width=\"100\" border=\"0\"><tr>";
    for(int i = 0 ;i< rgbB.length;i++){
    int r = (rgbB[i] >> 16) & 0xff;
    int g = (rgbB[i] >> 8) & 0xff;
    int k = (rgbB) & 0xff;
    System.out.println("red:" + Integer.toHexString(r));
    System.out.println("green:" + Integer.toHexString(g));
    System.out.println("blue:" + Integer.toHexString(k));
    dataHtm = dataHtm + "<td width=\"10\" bgcolor=\"#" + Integer.toHexString(r)+Integer.toHexString(g)+Integer.toHexString(k);
    dataHtm = dataHtm + "\"> </td>";
    dataHtm = dataHtm + "</tr></table></HTML>";
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter("c:\\23289207.html"));
    out.write(dataHtm);
    out.close();
    catch (IOException e) {
    e.printStackTrace();
    int w = image.getWidth();
    int h = image.getHeight();
    int[] pixels = new int[w*h];
    int[] pixs = new int[w*h];
    System.out.println("image width:"+w+"image hight:"+h+"image w*h:"+(w*h));
    Image img = Toolkit.getDefaultToolkit().getImage(filePath);
    PixelGrabber pg = new PixelGrabber(img, 0,0, w, h, pixels, 0, w);
    try {
    pg.grabPixels();
    catch (Exception x) {
    x.printStackTrace();
    String picColor = "";
    Stack stackColor = new Stack();
    Hashtable hashColor = new Hashtable();
    for (int i = 0; i < w * h; i++) {
    int rgb = pixels[i];
    int a = (rgb >> 24) & 0xff;
    int r = (rgb >> 16) & 0xff;
    int g = (rgb >> 8) & 0xff;
    int k = (rgb) & 0xff;
    i = i+1000;
    //System.out.println("i:" + i);
    picColor = convertToSring(r)+convertToSring(g)+convertToSring(k);
    stackColor.add(picColor);
    //System.out.println("picColor:"+picColor);
    // System.out.println("\n\n a:" + a);
    // System.out.println("red:" + r);
    // System.out.println("green:" + g);
    // System.out.println("blue:" + k);
    }//end for
    getMaxColor(stackColor);
    System.out.println("==generateColor==end\n\n");
    return null;

    import java.awt.Color;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    public class HighFive
        private void examineColors(BufferedImage image)
            long start = System.currentTimeMillis();
            int w = image.getWidth(), h = image.getHeight();
            int[] rgbs = image.getRGB(0,0,w,h,null,0,w);
            findHighFive(rgbs);
            long end = System.currentTimeMillis();
            System.out.println("total time = " + (end - start)/1000.0 + " seconds");
        private void findHighFive(int[] colors)
            int[] uniqueColors = getUniqueColors(colors);
            int[] colorCounts  = getColorCounts(uniqueColors, colors);
            int[] highFive     = getHighFive(colorCounts);
            // for each value of highFive find index in colorCounts
            // and use this index to find color code in uniqueColors
            for(int j = 0; j < highFive.length; j++)
                int index = findIndexInArray(colorCounts, highFive[j]);
                Color color = new Color(uniqueColors[index]);
                String s = color.toString();
                s = s.substring(s.indexOf("["));
                System.out.println("color " + s + "  occurs " +
                                    highFive[j] + " times");
        private int[] getUniqueColors(int[] colors)
            // collect unique colors
            int[] uniqueColors = new int[colors.length];
            int count = 0;
            for(int j = 0; j < colors.length; j++)
                if(isUnique(uniqueColors, colors[j]))
                    uniqueColors[count++] = colors[j];
            // trim uniqueColors
            int[] temp = new int[count];
            System.arraycopy(uniqueColors, 0, temp, 0, count);
            uniqueColors = temp;
            return uniqueColors;
        private int[] getColorCounts(int[] uniqueColors, int[] colors)
            // count the occurance of each unique color in colors
            int[] colorCounts = new int[uniqueColors.length];
            for(int j = 0; j < colors.length; j++)
                int index = findIndexInArray(uniqueColors, colors[j]);
                colorCounts[index]++;
            return colorCounts;
        private int[] getHighFive(int[] colorCounts)
            // find five highest values in colorCounts
            int[] highFive = new int[5];
            int count = 0;
            for(int j = 0; j < highFive.length; j++)
                int max = Integer.MIN_VALUE;
                for(int k = 0; k < colorCounts.length; k++)
                    if(colorCounts[k] > max)
                        if(isUnique(highFive, colorCounts[k]))
                            max = colorCounts[k];
                            highFive[count] = colorCounts[k];
                count++;
            return highFive;
        private boolean isUnique(int[] n, int target)
            for(int j = 0; j < n.length; j++)
                if(n[j] == target)
                    return false;
            return true;
        private int findIndexInArray(int[] n, int target)
            for(int j = 0; j < n.length; j++)
                if(n[j] == target)
                    return j;
            return -1;
        public static void main(String[] args) throws IOException
            String path = "images/cougar.jpg";
            Object o = HighFive.class.getResource(path);
            BufferedImage image = ImageIO.read(((URL)o).openStream());
            new HighFive().examineColors(image);
    }

Maybe you are looking for

  • How to view my family share calendar in outlook for mac 2011 (ical)

    Hey All Problem: Want to view my family share calendar in outlook for mac 2011. Want to have them sync on the fly (push) Currently running 2 exchange mailboxes which have their own mailboxes and calendars which you can toggle between. For the PC this

  • Bridge and PSCS5 slow and unstable after update

    I allowed my system to install the updates for Bridge, ACR and PS CS5.  Since then everything is unstable. I open bridge and click an image.  I'm first told Bridge is not responding.  After a couple minutes it will respond and open ACR.  If I click "

  • PRS-T1 Crashing, Freezing and Touchscreen Issues

    I'm getting A LOT of crashes and freezes using the PRS-T1. Sometimes the onboard reader software wants to close, other times the touch screen will die and I then have to do a reset. Yes, I fully charged the device before using it. It's VERY annoying.

  • Is provider.xml mandatory?

    Hi there, I'm looking through some source code developed elsewhere and it doesn't seem to have a provider.xml file included with the source code. Unfortunately, I don't have access to the app. server to see where this code has been deployed. My quest

  • Exporting AVI to DV - wont work - why?

    Hi there, Im having problems exporting about 40mins of AVI footage to DV PAL format. Im doing it using Premiere Pro CS3 on a PC with more than sufficient spec. The error message i keep getting is as follows: "Error compiling video. Cannot create or o