How to Zoom the Image in JAI

Hi,
I need to zoom the image during the each button click.I have done 1 program ,but i coulnt able to change the parameter block's value each time.Take this program and just change the pic's path and run
it ll show the pic,smaller than its actual size,because i changed the parameter block's value.this cahnge i want to do for each button click,please try to solve my problem,
the code is
import javax.swing.JFrame;
import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.image.RenderedImage;
import java.awt.image.BufferedImage;
import java.awt.BasicStroke;
import java.awt.Color;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import javax.swing.JPanel;
import java.awt.image.renderable.ParameterBlock;
import java.io.IOException;
import javax.media.jai.Interpolation;
import javax.media.jai.JAI;
import javax.media.jai.*;
import java.awt.geom.*;
import java.awt.geom.AffineTransform;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.media.jai.RenderedOp;
import com.sun.media.jai.codec.FileSeekableStream;
import javax.media.jai.widget.ScrollingImagePanel;
* This program decodes an image file of any JAI supported
* formats, such as GIF, JPEG, TIFF, BMP, PNM, PNG, into a
* RenderedImage, scales the image by 2X with bilinear
* interpolation, and then displays the result of the scale
* operation.
public class JAISampleProgram extends DisplayJAI implements MouseListener
JPanel jp=null;
ParameterBlock params=null;
Interpolation interp=null;
RenderedImage image1;
RenderedImage image2;
RenderedImage rop;
ScrollingImagePanel panel=null;
JFrame jf=null;
BufferedImage buff;
Graphics2D graph;
int width;
int height;
JAISampleProgram()
JButton zoomin= new JButton(ico1);
JButton zoomout = new JButton(ico2);
jp = new JPanel();
FileSeekableStream stream = null;
try
stream = new FileSeekableStream("D:/muthu/My Pictures/anniyan1.jpg");
catch (IOException e)
e.printStackTrace();
System.exit(0);
/* Create an operator to decode the image file. */
image1 = JAI.create("stream", stream,null);
* Create a standard bilinear interpolation object to be
* used with the "scale" operator.
interp = Interpolation.getInstance(
Interpolation.INTERP_BICUBIC_2);
* Stores the required input source and parameters in a
* ParameterBlock to be sent to the operation registry,
* and eventually to the "scale" operator.
params = new ParameterBlock();
params.addSource(image1);
params.add(0.1f); // x scale factor
params.add(0.1f); // y scale factor
params.add(0.0F); // x translate
params.add(0.0F); // y translate
params.add(interp); // interpolation method
/* Create an operator to scale image1. */
image2 = JAI.create("scale", params,null);
/* Get the width and height of image2. */
width = image1.getWidth();
height = image1.getHeight();
/* Attach image2 to a scrolling panel to be displayed. */
panel= new ScrollingImagePanel(image2, width, height);
panel.setSize(400,300);
setPreferredSize(new Dimension(image1.getWidth(),image1.getHeight()));
buff = new BufferedImage(image1.getWidth(),image1.getHeight(), BufferedImage.TYPE_INT_RGB);
width=image1.getWidth();
height=image1.getHeight();
graph = buff.createGraphics();
graph.setStroke(new BasicStroke(2.0f));
panel.addMouseListener(this);
jp.add(zoomin);
jp.add(zoomout);
jf = new JFrame("sample");
jf.setContentPane(panel);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
repaint();
public void mouseClicked(MouseEvent e)
ParameterBlock pb = new ParameterBlock();
interp = Interpolation.getInstance(Interpolation.INTERP_BICUBIC_2);
pb = new ParameterBlock();
pb.addSource(image2);
pb.add(0.5f); // x scale factor
pb.add(0.5f); // y scale factor
pb.add(0.0F); // x translate
pb.add(0.0F); // y translate
pb.add(interp); // interpolation method
rop = JAI.create("scale", params,null);
panel= new ScrollingImagePanel(rop, width, height);
panel.setSize(400,300);
setPreferredSize(new Dimension(image1.getWidth(),image1.getHeight()));
buff = new BufferedImage(image1.getWidth(),image1.getHeight(), BufferedImage.TYPE_INT_RGB);
width=image1.getWidth();
height=image1.getHeight();
graph = buff.createGraphics();
graph.setStroke(new BasicStroke(2.0f));
repaint();
public void mouseEntered(MouseEvent e)
public void mouseExited(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public synchronized void paintComponent(Graphics g)
panel.paintComponents(g);
Graphics2D g2d = (Graphics2D)g;
g = jp.getGraphics();
g2d.setColor(Color.BLUE);
g2d.drawLine(50,50,100,100);
graph.setColor(Color.yellow);
g.drawLine(60,60,120,120);
g2d.drawRenderedImage(rop,AffineTransform.getTranslateInstance(100.00,100.00));
/* params = params.set(0.1f,0);
params = params.set(0.1f,1); */
public static void main(String[] args)
/* Validate input.
* Create an input stream from the specified file name
* to be used with the file decoding operator.
JAISampleProgram jai = new JAISampleProgram();
/* Create a frame to contain the panel. */
jai.jf.pack();
Toolkit theKit=Toolkit.getDefaultToolkit();
Dimension dim=theKit.getScreenSize();
int scrWidth=dim.width;
int scrHeight=dim.height;
jai.jf.setSize(scrWidth,scrHeight);
jai.jf.show();
}

scale your Graphics2D object
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Graphics2D.html#scale(double,%20double)
Also check the documentation of
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JComponent.html#paint(java.awt.Graphics)
and see if your code would be better in paint(java.awt.Graphics) instead of paintComponent(Graphics g)

Similar Messages

  • How to Zoom an Image whereever the mouse moves?

    Hi,
    I have to zoom the image where ever the mouse cursor moves.
    If i am moving the mouse at the position (x,y) then that part of the image has to be zoomed.
    So that the pixels are clearly visible to user.
    Can any one suggest me what i have to do exactly.
    Thanks & Regards

    As always with such questions: have a look at the tutorial
    http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
    -Puce

  • Can any one tell me how to stream the images in flash.

    Hello Friends,
    i have created a dynamic page flip book with xml, i want to
    zoom the images in swf loaded, with streaming, so that user can
    preview the image while a good quality image is loading. I wanna
    know that how to load a part of large image or swf.
    Image effect like :-
    http://www.zoomify.com/
    Can any one tell me how to stream the images in flash.

    On Thu, 17 Apr 2008 05:53:27 +0000 (UTC), "FlashDavil"
    <[email protected]> wrote:
    >I wanna know that how to load a
    >part of large image or swf.
    You show a preview and use loadMovie() to load a big file.
    You can
    create a preloader (progress bar) showing how much part is
    loaded,
    while user sees the small image. When you achieve 100% tou
    show that
    big image. What's more?
    > Can any one tell me how to stream the images in flash.
    What are you talking about is not a "streaming", but
    "progressive
    download". Images "streaming" is impossible.

  • How to insert the image or logo into the table as a field in webdynpro abap

    Hi Friends,
    Please tell me how to insert the image or logo into the table as a field in webdynpro abap.........

    Hi Alagappan ,
          In your view layout you take table UI element and then you bind it with some context nodes.
    The attributes of your nodes comes as a field.
    Now in these fields you can set various properties and image is one of them.
    Go to ->
    1. View Layout -> Right Click on ROOTUIELEMENTCONTAINER -> INSERT ELEMENT -> TABLE
    2. Right click on table -> Create Binding.
       Here you have to bind it with the appropriate context node.
    You will get two properties here
    a- Standard Cell Editor :- ( make it image )
    b- Standard properties :- ( If required set image properties ).
    3. If you want put image from out side then import it as a mime object and set the source of your table field ( used as a image )
    also have a look :-
    [Image Properties|http://help.sap.com/saphelp_nw04/helpdata/en/f3/1a61a9dc7f2e4199458e964e76b4ba/content.htm]
    Hope this will solve your problem.
    Reply if any case of any issue.
    Thanks & Regards,
    Monishankar C

  • I am trying to find out how to copy the image on my existing hard drive to my new hard drive before I install it so it will be like I didn't do anything.

    I am trying to find out how to copy the image on my existing hard drive to my new hard drive before I install it so it will be like I didn't do anything. Thanks for the info. on changing it.

    Format is found in the Erase Tab:
    The Disk Image is found on the Restore Tab:

  • How to change the images dynamically in a table.

    Hai,
                     How to change the images dynamically in a table based on the condition in webdynpro abap.
    Edited by: Ravi.Seela on Oct 13, 2011 2:17 PM

    This has been much discussed earlier. Do search posts.
    For your scenario i would do the following.
    inside your node which is binded to the table, i create a new node image with cardinality 1 ..1 and a attribute called path of type string.
    create a  supply function for the node image .
    Supply method now has a Element (Parent element ) and node.
    Based on your record in element, set the right image source to path attribute and bind the node.
    This will make sure that the framework calls the image supply function for every row in a table.

  • How to get the image stored in archieve link as an attachment in work item.

    Hi All,
    through transaction OAWD we are storing scanned images.
    Once this transaction is executed a workitem appears in the inbox of the initiator with the scanned invoice as attachment.
    When the user executes the work item FV60 screen is displayed where the user enters the data based on the scanned invoice attachment.
    After the user Parks the document the custom workflow triggers and a workitem appears in the inbox of an approver.
    Our requirement is that the scanned image should also appear as the attachment.
    Can you please suggest how to get the image stored in archieve link as an attachment in work item.
    Regards
    Shraddha

    Hi Martin,
    with every parked document a scanned image is linked.
    I need to create a link under objects and attachments in the work item, such that when the user clicks that link the image is displayed.
    At present the following functionality is available.
    The BO used is FIPP
    Objects and attachments:
    parkeddocument:AK0108500001252008.(via FIPP binding with WIOBJECT_ID)
    On clicking the link below objects and attachments: the parked document AK0108500001252008 opens in display mode.
    Now we want to have 2 links:
    parkeddocument:AK0108500001252008.
    image.
    When we click on the link image then the scanned invoice linked to the document should get opened.
    I am able to get the image id of the the image through  SAP_WAPI_GET__OBJECTS,
    export parameter leading_object provides the detail.
    But I am not able to figure out how to use it in my workflow to display it as an attachment.
    Hope this will give a better understanding of my question.
    can you please suggest as to how I should proceed with it.

  • How to store the images in Oracle?

    Hi,
    I am a new developer, trying to find out how to store the images in Oracle. Is there anyway that I can store the images in Oracle and insert them into my html file?
    Thanks!
    Sarah

    There is a simple image example available from OTN.
    From the OTN main page, go to Products --> interMedia --> Sample Code. The name of the example is "Load rich media content with a browser."
    This example loads and retrieves an image from an Oracle8i database through a web page using the Oracle interMedia Web Agent.
    Hope this helps.
    null

  • How to place the images in Indesign xml file by Javascript?

    How to place the images in Indesign xml file by Javascript?
    We got the Indesign xml file, how to give the image placement link by Indesign javascript? Please help me its urgent.

    Hi,
    You can pass the image url as a href attribute=> file:///Users/me/Documents/my_pic.jpg directly within your xml. It just needs that you pass a local, static and valid url.
    If you want to add image later once the xml is flowed and so target specific nodes and inject images, it's a bit more complex. If the node is not part of the layout, you may try to reach the XMLElement objet and such an attribute, then layout the element.
    var x = some XMLElement
    x.xmlAttributes.add("href","file:///Users/m/Documents/my_pic.jpg" );
    If already placed, then you have to get the associated pageItem, then place your file into it.
    pagItm.place ( File ( "/Users/m/Documents/my_pic.jpg" ) );
    Hope that helps,
    Loic
    http://www.loicaigon.com

  • How to embed the Images in the java sourse

    How to embed the Images in the java sourse
    The size of the file will be too large while I put the binary code of the image into the java sourse!
    thanks

    You could encrypt them with a private key and then
    decrypt them with a public key.
    Almost had it... public key encryption works the other
    way around... otherwise what's the point of
    encrypting... if the decryption key is public?Spinoza's right. Public key encryption works both ways, but it would be useless in this case to encrypt with the private key. The problem is, how do you package your private key with the application in a way that doesn't allow the user to get it? Encrypt it? :-) I agree that there's no point to this exercize. If users want to screw up the application by editing its image files, let 'em.

  • How to store the images in tables

    how to store the images in tables .what is the use of "clob ,blob"

    Using with the CLOB or BLOB, you can store the images in the table.
    Srini C

  • How to upload the image and diplay the image in the browser using jsp

    How to upload the image and diplay the image in the browser using jsp
    thanks
    shan

    i'll suggest looking for sample code or tutorial with a relevant query in google, which as far more time than us to answer this type of reccurent question

  • How to save the image in the form?

    As thread, how to save the image into a file from the pdf form - image box?
    I have Adobe Acrobat 9 Pro extended.

    Hi Sandy,
    Sorry for Delay.Could you please provide script code for the Button and in which event we want to add the code
    I want to Save the lot of images in the PDF. For that I kept Image field in the form.Here I am able to upload the images but those are not saved.
    If possible please share the details document.
    Please help me.
    Thanks,
    Ravi.

  • How to display the image which in KM folder using url iview

    Hi Friends
    How to display the image, which is under KM folder structur using the url iview.
    i trying using url iview url as  \document\testfolder\abc.jpg as url for the iview.
    but its now working .. so please help me how to slove this problem
    If is not the correct way then please suggest me best way to achive this.
    Thanks
    Mukesh

    Hi Mukesh,
    I think this may work,
    1, Create a HTML Layout.
        You can put your image wherever  u want with HTML Codes.
        Check this, [Article|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3915a890-0201-0010-4981-ad7b18146f81] & [Help|http://help.sap.com/saphelp_nw04/helpdata/en/cc/00c93e9b2c3d67e10000000a114084/frameset.htm]
        With this, u can use the standard KM commands also.
    2, U need to use KM Navigation iView for this rather than KM Doc iView.
    3, In the Nav iView, u can use &rndLayoutSet=nameOfUrHTMLLayout to force the view with this new layout.
    Regards
    BP

  • How to receive the images / binary data t ype

    How to receive the images / binary data type in webdynpro....
    i have a website that let's the user send email, the email attachment and message are stored in both in images data type....
    q1) can i stored the message into binary data type...but the message is very long.....
    q2) if i have a textbox ...i surely will need to display the message  in string ,right ?
    [......... msg here ........]
    what is the codes to receive the images / binary data type in webdynpro....

    As in your previous post if you are storing them as BLOB object.. am sure you are able to get a byte stream or byte array(bytes[]) out of it.
    There should be some way to identify if its a image or a message BLOB. If its a image , convert into bytes and use 
       WDWebResource.getWebResource(bytes,resource type).getAbsoluteURL()
    to obtain the url.. assign this image UI element..
    In case its the message , use bytes.toString to get the message ..
    Regards
    Bharathwaj

Maybe you are looking for