Useing "MemoryImageSource" to create an image

Hi !!
I have written a programm to display an image in a frame useing a MemoryImageSource objest.
Here is the code:
int width=10;
int height=10;
java.awt.image.MemoryImageSource mis = new java.awt.image.MemoryImageSource(width,height,newImage,0,width);
Image testImage =createImage(mis);
ImageIcon newIcon = new ImageIcon(testImage);
lblChangedImage.setSize(width,height);
lblChangedImage.setIcon(newIcon);
--------------------------------The array values of the "newImage" array are as follows -----------------------
position value
0 75
1 82
2 93
3 105
4 119
5 132
6 144
7 152
8 151
9 150
10 148
11 142
12 141
13 145
14 147
15 143
16 139
17 139
18 140
19 142
20 145
21 148
22 152
23 154
24 154
25 155
26 158
27 159
28 160
29 159
30 157
31 156
32 157
33 157
34 156
35 156
36 157
37 160
38 162
39 163
40 160
41 166
42 171
43 172
44 168
45 166
46 167
47 169
48 166
49 167
50 165
51 158
52 153
53 151
54 149
55 146
56 134
57 120
58 104
59 98
60 99
61 102
62 99
63 94
64 88
65 101
66 99
67 91
68 99
69 104
70 97
71 93
72 98
73 95
74 98
75 104
76 106
77 103
78 100
79 101
80 99
81 95
82 94
83 98
84 106
85 108
86 103
87 96
88 95
89 96
90 98
91 99
92 99
93 97
94 96
95 95
96 102
97 103
98 104
99 109
I hope some one will help me to solve this problem.
Thank you in advance.
Muditha

Try this, it create a very, very small icon:
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
public class Muditah1
     public static void main(String[] argv)
          //int white= (0xff<<24) | (255<<16) | (255<<8) | 255;
          int black= (0xff<<24);
          int yellow= (0xff<<24) | (255<<16) | (255<<8);
          int[] pixels= {
               yellow, black,  black,  black,  yellow,
               black,  yellow, black,  yellow, black,
               black,  black,  yellow, black,  black, 
               black,  yellow, black,  yellow, black,
               yellow, black,  black,  black,  yellow
          Image image= Toolkit.getDefaultToolkit().createImage(
               new MemoryImageSource(5, 5, pixels, 0, 5));
          JFrame frame= new JFrame();
          frame.getContentPane().add(new JLabel(new ImageIcon(image)));
          frame.pack();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
}

Similar Messages

  • Question about Using BufferedImage to create jpeg image

    I was puzzled by a problem about using of class BufferedImage. I want to dynamicly create a jpeg image with bufferedimage, the step is as follows:
    1.create a new bufferedImage object:
    BufferedImage image = new BufferedImage((int)imageWidth, (int)imageHeight, BufferedImage.TYPE_BYTE_BINARY);
    2.get the Graphics object from image:
         Graphics graphics = image.getGraphics();
    3.then draw string and any other graphics with graphics
    4.create jpeg image:
         try {
         FileOutputStream fos = new FileOutputStream("c://test.jpg");
         BufferedOutputStream bos = new BufferedOutputStream(fos);
         JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
         encoder.encode(image);
         bos.close();
         } catch(Exception e) {
         System.out.println(e);
    The problem is that :
    if the graphic width and height is large enough(in my computer, the largest number is 4000*4000,of course it can be 6000*2000, but the total number is limited.), step 1 will be error: OutofMemory!
    I'm worrying about it all day and night.Even though I try all my best,I still can't find what's wrong with it.
    Can you help me--the helpless one?

    Right. 4000x4000x3bytes ("true" color) is 64 mbytes. Your jpeg file might be smaller of course, but it's still going to be a behomoth. The best thing to try is increasing your java runtime size... I've never had to do this, but you can probably find it on this site somewhere

  • What "Partitions" type should I use when I create an image in Disk Utility?

    I have a Sony HDR-SR1 camcorder and have been creating images in Disk Utility to dump copies of my camcorders hard drive to. That way I can mount the disk image and import into iMovie just as if the camera was plugged in. These are the options I've been using:
    Volume Size: varies
    Volume Format: Mac OS Extended (Journaled)
    Encryption: none
    Partitions: Single partition - Apple Partition Map (the default I believe)
    Image Format: read/write disk image
    The option I'm not sure of and can't find much information on is Partitions. Up until now all the ones I've created use what I listed above. What is the difference between all the options (hard disk, cd/dvd, no partition, single partition - *multiple options*) and what should I be using to ensure long term compatibility with these disk images. Thanks.

    You don't need the journaling feature. Everything else appears proper. As for the various formats, check DU's help files.

  • Can i 'open using photoshop' without creating another image in LR

    I'm working with RAW files imported into LR 3.2
    I swear that in an earlier version of LR - when I did 'open with photoshop' a corresponding Tiff file was not created in LR unless the image was saved in Photoshop.
    I'm sure it used to work along these lines...
    Open with PS, start to edit in photoshop - then decide not to continue - exit photoshop without saving. Tiff not created in LR.
    Open with PS, start to edit in photoshop - Ctrl+S in Potoshop (or save on exit, etc). Tiff was created in LR.
    anyway- that's the methodology I want.... can I have it?
    [I know that I can 'export' as a Tiff, but thats not the option I want. I only want files opened with PS, from LR, to save in LR if saved in PS]
    SS

    I never use bridge..but,
    If i browse to a folder with a raw file (I use DNG) and right click, open with CS5 - adobe CR6.3 and CS5 fire up.
    In LR i import from camera, as DNG files.
    If I use the edit with CS5 command, PSCS5 fires up but the image never shows in CS5, a corresponding Tiff is not created in LR. [This is an unresolved issue from some time ago, I've deleted preferences files etc..but cannot get transfer from LR to CS5 using 'edit with CS5']
    To overcome this i have CS5 set up as second external editor - having pointed it to where CS5 is installed]
    So. I have the DNG files in LR3.3.
    Right Click - Edit in photoshope.exe (manually pointed as discussed above)
    Dialog box 'what to edit' opens - choice of open a copy with LR adjustements is the only choice. Can selecte file size etc.
    irrespective of whether 'stack with original' is selected - a Tiff file is genrated in LR, and CS5 fires up with the Tiff file open.
    Saving in CS5 results in the file in LR being updated to match.
    As earlier - I only want a Tiff created in LR, if I decide to save the Tiff from CS5.
    thanks for help so far.

  • Using AS to Create Dynamic Images

    Hi all... hoping someone here can help me out.
    I'm working on
    this site for a
    client, and they're going to have a lot of inventory for me to
    add to it.
    If you enter the site and then click on "Sofas" on the left
    menu you'll see the layout I'm doing.
    I've uploaded a file of just the "sofas" section for
    you to download
    here.
    What I'm wondering is if there's an easy way to make just one
    movie clip called "thumbnail" and one called "big". Then, depending
    on the section the person goes to they would create all the movie
    clips and let the Loader component know what image to load in based
    on the section.
    Then I could just upload the jpgs to the server and not have
    to make 300+ movieclips for every one of them.
    Hope this makes sense.
    Oh yeah... you'll notice I'm using Blogger to get the content
    onto each sofa... but that may not matter one way or another.
    Hopefully not. If there's a better way to populate the text let me
    know.
    Thanks!

    Hi all... hoping someone here can help me out.
    I'm working on
    this site for a
    client, and they're going to have a lot of inventory for me to
    add to it.
    If you enter the site and then click on "Sofas" on the left
    menu you'll see the layout I'm doing.
    I've uploaded a file of just the "sofas" section for
    you to download
    here.
    What I'm wondering is if there's an easy way to make just one
    movie clip called "thumbnail" and one called "big". Then, depending
    on the section the person goes to they would create all the movie
    clips and let the Loader component know what image to load in based
    on the section.
    Then I could just upload the jpgs to the server and not have
    to make 300+ movieclips for every one of them.
    Hope this makes sense.
    Oh yeah... you'll notice I'm using Blogger to get the content
    onto each sofa... but that may not matter one way or another.
    Hopefully not. If there's a better way to populate the text let me
    know.
    Thanks!

  • Can i use iphoto to create transparent images?

    I would like to know if there is any way to edit my images on iPhoto to have a transparent background. I need to upload photos to a website, but I do not want there to be a white "shadow" around my images. I know you can do it with Photoshop, but can you do it easily with iPhoto?

    No. But the Instant Alpha feature in Preview or Pages will do this for you. Image editors like Acorn have this as well. Remember to save the files as png or other, as jpeg doesn't support transparency.
    Regards
    TD

  • How to create an image viewer

    i need to know how to create an image viewer would appreciate
    help thanks

    you can use loadMovie() to load a jpg image into flash (and
    if you're using flash 8 you can load other image formats into
    flash) and use it to create an image viewer.

  • How Do You Use XML To Create Image Upload On A WebSite?

    Hello,
    Could some one please help me understand how to create web image gallery and web video gallery using XML? I have found few xml codes that could be used to do this but I am not so sure how to use them. I want my clients to be able upload images and videos with linking thumbnails to Image and or Videos. Do you think the codes I included in this question will help me achive this goal? And do I need to put all in one and in the same directory so it will work? Please help with your idea and tell me how you would use these codes and how you may step-by-step implement the idea your self to your own web site.
    I have also included the instruction I found on the web with the codes.
    Starting with You Tube, API on their video gallery, here are the codes I found,
    Assume you are to use the YouTube, XML code; What will you change here so it will work on your own www.domain.com?
    <% Dim xml, xhr, ns, YouTubeID, TrimmedID, GetJpeg, GetJpeg2, GetJpeg3, thumbnailUrl, xmlList, nodeList, TrimmedThumbnailUrl Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
    xml.async = False
    xml.setProperty "ServerHTTPRequest", True
    xml.Load("http://gdata.youtube.com/feeds/api/users/Shuggy23/favorites?orderby=updated") If xml.parseError.errorCode <> 0 Then
        Response.Write xml.parseError.reason End If Set xmlList = xml.getElementsByTagName("entry") Set nodeList = xml.SelectNodes("//media:thumbnail") For Each xmlItem In xmlList
        YouTubeID = xmlItem.getElementsByTagName("id")(0).Text
        TrimmedID = Replace(YouTubeID, "http://gdata.youtube.com/feeds/api/videos/", "")
        For Each xmlItem2 In nodeList
            thumbnailUrl = xmlItem2.getAttribute("url")
            Response.Write thumbnailUrl & "<br />"
        Next     Next    
    %>
    For the image gallery, the following are the codes I found with your experience do I need to use the entire codes or just some of them that I should use?
    CODE #01Converting Database queries to XML
    Using XML as data sources presumes the existence of XML. Often, it is easier to have the server create the XML from a database on the fly. Below are some scripts for common server models that do such a thing.
    These are starting points. They will need to be customized for your particular scenario.
    All these scripts will export the data from a database table with this structure:
    ID: integer, primary key, autoincrement
    AlbumName: text(255)
    ImagePath: text(255)
    ImageDescription: text(2000)
    UploadDate: datetime
    The output of the manual scripts will look like:
    <?xml version="1.0" encoding="utf-8" ?>
      <images>
         <image>
              <ID>1</ID>
              <album><![CDATA[ Family ]]></album>
              <path><![CDATA[ /family/us.jpg ]]></path>
              <description><![CDATA[ here goes the description ]]></description>
              <date><![CDATA[ 2006-11-20 10:20:00 ]]></date>
         </image>
         <image>
              <ID>2</ID>
              <album><![CDATA[ Work ]]></album>
              <path><![CDATA[ /work/coleagues.jpg ]]></path>
              <description><![CDATA[ here goes the description ]]></description>
              <date><![CDATA[ 2006-11-21 12:34:00 ]]></date>
         </image>
      </images>
    These are all wrapped in CDATA because it is will work with all data types. They can be removed if you know you don't want them.
    Note: If using the column auto-generating versions, ensure that all the column types are text. Some databases have data type options like 'binary', that can't be converted to text. This will cause the script to fail.
    CODE #02ASP Manual: This version loops over a query. Edit the Query and XML node names to match your needs.
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
    <%
    Dim MM_conn_STRING
    MM_conn_STRING = "dsn=image_gallery;uid=xxxx;pwd=xxxx"
    %>
    <%
    Dim rsImages
    Dim rsImages_cmd
    Dim rsImages_numRows
    ' Query the database and get all the records from the Images table
    Set rsImages_cmd = Server.CreateObject ("ADODB.Command")
    rsImages_cmd.ActiveConnection = MM_conn_STRING
    rsImages_cmd.CommandText = "SELECT ID, AlbumName, ImagePath, ImageDescription, UploadDate FROM images"
    rsImages_cmd.Prepared = true
    Set rsImages = rsImages_cmd.Execute
    ' Send the headers
    Response.ContentType = "text/xml"
    Response.AddHeader "Pragma", "public"
    Response.AddHeader "Cache-control", "private"
    Response.AddHeader "Expires", "-1"
    %><?xml version="1.0" encoding="utf-8"?>
    <images>
      <% While (NOT rsImages.EOF) %>
         <image>
              <ID><%=(rsImages.Fields.Item("ID").Value)%></ID>
              <album><![CDATA[<%=(rsImages.Fields.Item("AlbumName").Value)%>]]></album>
              <path><![CDATA[<%=(rsImages.Fields.Item("ImagePath").Value)%>]]></path>
              <description><![CDATA[<%=(rsImages.Fields.Item("ImageDescription").Value)%>]]></description>
              <date><![CDATA[<%=(rsImages.Fields.Item("UploadDate").Value)%>]]></date>
         </image>
        <%
           rsImages.MoveNext()
         Wend
    %>
    </images>
    <%
    rsImages.Close()
    Set rsImages = Nothing
    %>
    CODE #03
    Automatic: This version evaluates the query and automatically builds the nodes from the column names.
    <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
    <%
    Dim MM_conn_STRING
    MM_conn_STRING = "dsn=image_gallery;uid=xxxx;pwd=xxxx"
    %>
    <%
    Dim rsAll
    Dim rsAll_cmd
    Dim rsAll_numRows
    ' Query the database and get all the records from the Images table
    Set rsAll_cmd = Server.CreateObject ("ADODB.Command")
    rsAll_cmd.ActiveConnection = MM_conn_STRING
    rsAll_cmd.CommandText = "SELECT * FROM Images"
    rsAll_cmd.Prepared = true
    Set rsAll = rsAll_cmd.Execute
    ' Send the headers
    Response.ContentType = "text/xml"
    Response.AddHeader "Pragma", "public"
    Response.AddHeader "Cache-control", "private"
    Response.AddHeader "Expires", "-1"
    %><?xml version="1.0" encoding="utf-8"?>
    <root>
      <% While (NOT rsAll.EOF) %>
         <row>
             <%
                 For each field in rsAll.Fields
                 column = field.name
             %>
              <<%=column%>><![CDATA[<%=(rsAll.Fields.Item(column).Value)%>]]></<%=column%>>
              <%
                 Next
              %>
         </row>
        <%
           rsAll.MoveNext()
         Wend
    %>
    </root>
    <%
    rsAll.Close()
    Set rsAll = Nothing
    %>

    OK, I understand - thanks for that.
    I thought the whole process was supposed to be a bit more seemless? Having to upload/download documents and manually keep them in sync will leave a lot of room for errors.
    It's kinda painful the way iOS doesn't have folders. It makes things incompatible with the Mac and means you can't group files from multiple apps into a single project - who organises their digital life by the apps they use?
    I think I'll recommend they use their iPad only.
    Thanks for that.
    Cheers
    Ben

  • Problem in creating 1 image using differnt images

    Dear Fellows I want to create an image by using different images in byte array format. Images may be transparent or normal images. I want final result in byte array. I am using the following technique which is working fine but the problem with this technique is that it takes too much time to create an image. This is because I am using MediaTraker. If I delete the code of MediaTracker then program have undeterministic behavior i.e, sometimes it create the final image properly and sometimes nothing is displayed in final image.
    I need some help from you. If anyone of you know the technique to draw image using different images without using mediaTracker kindly let me know.
    Early replies will be appreciated
    // here is the sample code which i m using for creating image
    byte[] backgroundImage= // read 800 X 600 image from disk and convert it in to byte array
    byte[] image1 = // read 200 X 200 image from disk and convert it in to byte array
    byte[] transparentImage // read 300 X 300 transparent image from disk and convert it in to byte array
    Image img=null;
    Frame frame =new Frame();
    frame.addNotify();
    //creating BufferedImage object to store Final image
    BufferedImage requiredImage= new BufferedImage(800,600,BufferedImage.SCALE_SMOOTH);
    //get Graphics of BufferedImage created above
    Graphics2D g=(Graphics2D) requiredImage.getGraphics();
    ///// begin draw back ground image
    img=Toolkit.getDefaultToolkit().createImage(backgroundImage);
    try
    MediaTracker mt = new MediaTracker(frame);
    mt.addImage(img, 0); // adds image with ID 0
    mt.waitForID(0);
    }catch(Exception myex)
    myex.printStackTrace();
    //draw background starting from x=0, y=0 with 800 X 600 dimentions
    g.drawImage(img,0,0,800,600,null);
    ////////// end draw background image
    ////////// begin draw image1
    img=Toolkit.getDefaultToolkit().createImage(image1);
    try
    MediaTracker mt = new MediaTracker(frame);
    mt.addImage(img, 0); // adds image with ID 0
    mt.waitForID(0);
    }catch(Exception myex)
    myex.printStackTrace();
    //draw image1 starting from x=10, y=10 with 200 X 200 dimentions
    g.drawImage(img,10,10,200,200,null);
    //////////// end draw image1
    //////begin transparentImage
    img=Toolkit.getDefaultToolkit().createImage(backData);
    try
    MediaTracker mt = new MediaTracker(frame);
    mt.addImage(img, 0); // adds image with ID 0
    mt.waitForID(0);
    }catch(Exception myex)
    myex.printStackTrace();
    //draw transparentImage starting from x=400, y=0 with 300 X 300 dimentions
    g.drawImage(img,400,0,300,300,null);
    ///end draw transparent image
    byte []finalResult = //convert requiredImage into byte array;
    you can mail me the solution on my email address [email protected]
    thanks with best regards
    and waiting for someone to reply
    kamran zameer

    is there anyone on this forum to help me??????
    regards,
    kamran zameer

  • Create an image of my current PC laptop and them use as Bootcamp image...

    I currently have a Dell laptop that I've had for almost two years, running Win XP. I've installed tons of software over that time. I would love to be able to create an "image" of this laptop, and then use it as a Bootcamp partition. I can imagine that this is very difficult, due to the different hardware, if nothing else, if it's possible at all.
    Is this possible? If so, how?

    And not transferable unless you used retail copy.
    http://www.apple.com/support/bootcamp

  • Error when creating an image (dmg) using hdiutil

    Hi everybody,
    I´m using a script which creates an image (dmg) from a selected folder.
    This works without errors.
    But I also want to create images from CDs and DVDs using this script. Doing so I always get the error "Only one image can be created at a time"
    I thought that a previous imaging process was not finished yet and I rebooted the Mac. But I still get this error. Any idea?
    Here is the script:
    set Ordner to choose folder
    tell application "Finder"
    set diskNames to name of Ordner
    set myNewPath to POSIX path of (path to desktop folder) as string
    set theListe to every process
    end tell
    set myNewPath to myNewPath & diskNames & ".dmg"
    set Quellordner to POSIX path of Ordner as string
    set Skript to "hdiutil create -srcfolder " & Quellordner & " " & myNewPath
    do shell script Skript
    iMac Core Duo/1,5 GB; MacBook Pro Core2Duo 2GB   Mac OS X (10.4.4)  

    I believe this has something to do with terminal and have spaces in folder names / disk names. As it sees the space and thinks it is another command and in this case i believe it thinks you are trying to do two or more disk images at once. Therefore it is important to deal with spaces. Thankfully you should be ablr to get around this by using the quoted form command which i have implemented below.
    I repeated your error using a folder called "Cd for Cherie". Folders without gaps such as "pH" worked fine.
    I havent tested this with any disk but i believe if you alter it to this hopefully it will work
    Also the name of the folder wasnt working for me so i altered to to work for me, i am using 10.4.8 so if it doesnt work for you then change it back.
    --Start Code
    tell application "Finder"
    set infor to info for Ordner
    set diskNames to name of infor
    -- display dialog diskNames as string
    --set diskNames to name of Ordner
    set myNewPath to POSIX path of (path to desktop folder) as string
    -- set theListe to every process
    end tell
    set myNewPath to quoted form of (myNewPath & diskNames & ".dmg")
    set Quellordner to quoted form of POSIX path of Ordner as string
    set Skript to "hdiutil create -srcfolder " & Quellordner & " " & myNewPath
    do shell script Skript
    --end code

  • How the **** do i get back my library i was just using.No didn't save image or restore been using it for months the same way no tells me to choose or create a library and my previous versions don't recover

    How the **** do i get back my library i was just using.No didn't save image or restore been using it for months the same way no tells me to choose or create a library and my previous versions don't recover.Please help I just deleted all doubles did allmy artwork Etc..

    Do you have a back up?
    If not you're into using file recovery software like  File Salvage - you can download a free trial and it will scan the disk for you and tell you with might be recoverable. Actual recovery will require that you purchase the app. There may be many files with the same or similar names. Always recover the largest file size.
    There are other such apps. Search on Macupdate or the App Store

  • I need to create a image using some numeric values and i want to display values in image,

    I need to create a image using some numeric values and i want to display values in image, Numeric values be enterd by text file, excel file or user input by dialog box,
    this is the sample if image.
    http://s17.postimg.org/5xvtzbztn/5_01_03_I.png
    128 x 16 Pixels , Back ground Black, Numbers in Red, Should be same as above picture.
    Because i have hundreds of images to create like this.
    If any one can make a script for this it is very good.
    Sorry about my English.
    Thank you.

    Have you checked out data driven graphics?
    https://helpx.adobe.com/photoshop/using/creating-data-driven-graphics.html

  • Is there a way to create an image using UPC lines?

    Is there anyway to create an image by using UPC lines? Maybe a plugin........?

    Good day!
    What do you mean by
    create an image by using UPC lines
    Could you post (a link to) an example?
    Regards,
    Pfaffenbichler

  • Best computer to use to create an image

    We use netboot as a diagnostic tool. Traditionally when a new model computer comes out, it wont netboot, so I would recreate the image using the computer. This has worked fine until the intels which dont seem as backwards compatible as the PPCs were. Currently the netboot image we use was made off an imac ( I use system image utility to make the image) and it works fine to boot everything but the 1.83GHz Core2Duo Macbooks. They freeze after a couple of minutes. MacPros with 2 video cards also fail to netboot.
    So my question is- what is the best computer to use to create an image that is compatible with all prior computers?

    You need separate images for intel and PPC Macs.

Maybe you are looking for

  • What's the difference between OEM and standart licensing of VMware vSphere for users?

    Good day, Could you please explain me, What's the difference between OEM and standart licensing of VMware vSphere for users?

  • SQL Developer 1.5.1 on XP: Abruptly aborts when laptop lid is closed

    I have SQLD 1.5.1 (latest version available for download, build 5440) on Windows XP (on a Lenovo laptop T60). When I am headed to say a meeting for example, and close the lid of the laptop so it goes to sleep/hibernate and then come back and open the

  • I plugged my iPhone in to my computer and nothing is showing up. What do I do?

    I just got the iPhone and followed the instructions to plug it into my computer. When I plugged it in, all that appeared were the options that normally come up when I'm downloading my photos to the computer. Nothing about the iPhone or installation c

  • RAS SDK Scalability

    We are planning to develop a reporting application which will create entire report using RAS SDK and display them in DHTML using Viewer SDK. In our application we donu2019t have any physical RPT file stored on Server because application users will de

  • Flash Builder Beta 2 won't install

    Hey, the installer is saying that "the version of this file is not compatible with the version of windows you're running".   I'm running windows vista 64 bit, but have installed plenty of 32 bit apps just fine.  I was able to install beta 1 just fine