Image border problem using JAI

I've written some very simple code to scale an image down to a small
thumbnail in JPG format but the quality is quite horrible. Is there a way of making it look nicer?
src = JAI.create("fileload","filepath")
ParameterBlock params = new ParameterBlock();
params.addSource(src);
params.add(xScale);//x scale factor
params.add(yScale);//y scale factor
params.add(0.0F);//x translate
params.add(0.0F);//y translate
params.add(Interpolation.getInstance(Interpolation.INTERP_NEAREST));
dest = JAI.create("scale", params,null);
I switched to InterpolationBicubic, instead of Interpolationnearest the quality was much better but the resulting image contained borders.
could some one tell me is there any other way to get better and nicer results.

Yes you can fix the border problem by setting a render hint to change the way the borders are handled. Something like the following will do the trick.
You can also use BORDER_WRAP instead of BORDER_COPY, both seem to have a similar result. Mind you I am still very dissapointed with the quality of the bicubic resampling in JAI, but at least this will fix the problem with the borders.
RenderingHints rh = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY));
dest = JAI.create("scale", params,rh);

Similar Messages

  • How to resize image in JSP using JAI ??!!

    Please help me how to resize an JPEG image from my JSP, could I use JAI lib ? how ?

    Hello,
    I had the same problem few months ago ( in that case i used Jimi instead of JAI).
    The answer to your question is: use the java class called "Image".
    Infact you can use JAI just for load or save to disk your image that you have to resize and then use the following code to resize the image :
    Image imgResized = img.getScaledInstance(100,1,Image.SCALE_AREA_AVERAGING);
    The object "img" is the image to resize and the object "imgResized" is the image resized with width equals to 100 and with a right height.
    I used Jimi just to save my image and i think that with JAI there is a method to do this.
    You can use JAI to load in memory your image too so you can avoid problem with MediaTraker class.
    I hope that this can help you.
    Cheers.
    Stefano

  • Image border problem

    Hoping someone can help with a pesky border problem. I'm
    working on a Mac and have no problem creating a thin, off-white
    border (2 pixels) around an image and everything seems fine. But
    after posting, the border acts like a rollover and changes colour
    as if it was a link, which it isn't, and I don't want it to change.
    Even worse, the border shows purple or blue on a PC.
    Thanks much.

    Sorry forgot the link:
    http://www.ampsoft.net/webdesign-l/WindowsMacFonts.html
    "Miguel" <[email protected]> escribió en el
    mensaje de noticias
    news:g7rlj6$qct$[email protected]..
    > Hi again.
    >
    > Only one advice. Don´t use fonts which can´t
    be seen for everybody but
    > those which have that particular font installed in their
    systems.
    >
    > In this link you can see the common fonts of windows and
    Mac.
    >
    > "Miguel" <[email protected]> escribió en el
    mensaje de noticias
    > news:g7rl6u$q4f$[email protected]..
    >> Hi.
    >> You could set a tag in your css.
    >>
    >> img {
    >> border: 2px solid #FFFFFF;
    >> }
    >>
    >> This will put a 2 pixels border with white color
    around all images.
    >> In the HOME page where the image have a grey border
    you can change the
    >> border color.
    >> Also, have do you notice that in your home page you
    have the color of
    >> your paragraph in black, like the background? this
    make impossible to
    >> read it.
    >>
    >>
    >> "markham5656" <[email protected]>
    escribió en el mensaje de
    >> noticias news:g7qg76$h5b$[email protected]..
    >>> Hoping someone can help with a pesky border
    problem. I'm working on a
    >>> Mac and
    >>> have no problem creating a thin, off-white
    border (2 pixels) around an
    >>> image
    >>> and everything seems fine. But after posting,
    the border acts like a
    >>> rollover
    >>> and changes colour as if it was a link, which it
    isn't, and I don't want
    >>> it to
    >>> change. Even worse, the border shows purple or
    blue on a PC.
    >>> Thanks much.
    >>>
    >>
    >

  • Having a image alignment problem using clearbox

    Hi,
    I'm having an image alignment problem. I cannot figure it out. I'm using the clearbox - lightbox dreamweaver widget. Using Dreamweaver CS6.
    Actual page located here. Any help would be appreciated.
    http://dirtysouthink.com/gallery/dustin2.html

    This has very little to do with Dreamweaver. DW is merely a tool to assist you in building a web site. It is purely a matter of styling (CSS).
    When I look at the structure, I see
    BODY-CONTENT (width: 490px)
         GALLERY (width: 452px)
              CONTAINER (width: 500px)
                   ITEM (width: 150px)
    From this I can deduce that:
    GALLERY will fit inside BODY-CONTENT
    CONTAINER will NOT fit inside GALLERY or BODY-CONTENT
    ITEM will fit three times into CONTAINER
    To start with, I would reduce the size of the CONTAINER so that it fits inside of its parent. Then I would adjust the width of the ITEM so that only two of them fit inside of the CONTAINER.

  • Linked Image Border Problems

    This just started happening, and I can't figure out how or
    how to fix it. When I open up a blank HTML page, insert an image,
    then add a link to the image, DW automatically inserts a solid
    border around the image. The border property is blank, where it
    used to default to 0. I can manually change the border to 0 and it
    gets rid of the border...but this is a pain to do for every single
    linked image! Does anyone know what the problem is or how to fix
    it? It used to automatically default to 0. I am using the latest DW
    included with CS3.

    > When I open up a blank HTML page, insert an image, then
    add a link to the
    > image, DW
    > automatically inserts a solid border around the image.
    This is actually default browser behaviour which DW is
    emulating with the
    code it's been given.
    >The border property is
    > blank, where it used to default to 0. I can manually
    change the border to
    > 0 and
    > it gets rid of the border...but this is a pain to do for
    every single
    > linked
    > image!
    Pre-CS3, DW automatically inserted the border="0" attribute
    into the <img>
    tag on every single linked image.
    From CS3 onwards, Adobe is dropping HTML formatting
    attributes and
    encouraging everyone to use CSS.
    >Does anyone know what the problem is or how to fix it? It
    used to
    > automatically default to 0. I am using the latest DW
    included with CS3.
    The CSS fix is much easier than the previous default to
    border="0"
    behaviour.
    Just add "a img ( border: none; }" (without the quotes) to
    your external
    linked stylesheet.
    Regards
    John Waller

  • Problem Printing Images Using JAI

    I'm using JAI in an application that prints images. My program works fine on my development machine (Windows XP), but when I put it on my Windows Server 2008 r2-64 bit, it crashes for certain images (these are large images of land plats) that go to a particular printer (OCE PlotWave 300) It prints my smaller images that are printing on a variety of printers just fine (images of Mortgages etc..) and it prints everything just fine on my development machine. What could possibly be causing this?
    Edited by: LongStranjeTrip on Feb 2, 2011 4:34 PM
    Edited by: LongStranjeTrip on Feb 4, 2011 8:11 AM

    I'm using JAI in an application that prints images. My program works fine on my development machine (Windows XP), but when I put it on my Windows Server 2008 r2-64 bit, it crashes for certain images (these are large images of land plats) that go to a particular printer (OCE PlotWave 300) It prints my smaller images that are printing on a variety of printers just fine (images of Mortgages etc..) and it prints everything just fine on my development machine. What could possibly be causing this?
    Edited by: LongStranjeTrip on Feb 2, 2011 4:34 PM
    Edited by: LongStranjeTrip on Feb 4, 2011 8:11 AM

  • Problem while loading a JApplet ( which uses JAI ) on Netscape across ssl

    Hi Folks...
    I m having some problem in applet.. can any1 of u guys help me???? My problem is as follows..
    I m having 2 JApplets (Swing applet) one of the applet is using JAI (Java Advance Imaging APIs). I m trying 2 load both the applets in IE as well as in Netscape across SSL (ie thru https protocol) .Both the applet can be loaded on IE across SSL. but when i m trying to load the applet on Netscape, one of the applet which is using JAI is not getting loaded across SSL. The other applet which is not using JAI is running fine across SSL on Netscape also.
    I m getting some exception.. Is this exception comming bcoz JAI is not compatible with Netscape r bcoz of somethinf else??? If it is bcoz of the fact that Netscape does'nt have any support for JAI across SSL. then watz the possible solution 4 that. How can i overcome by this problem. Its very urgent.. i need to do it any how... Plz plz help me out if u guys have any idea abt this.. any help is most welcome..
    My ids r
    [email protected]
    [email protected]
    tks...
    Jameel

    Exactly what exception are you getting? That will really help in determining the problem. Also, do you have the same problems when going over a regular connection (i.e. not over SSL)?
    Kate

  • Problem using images in a button skin

    So, I have a weird problem. I need to be able to see a button in design mode. My button is a custom component (a ButtonBase) with a skin. So, I left is a tiny bit of the default skin so that you can see what it looked like in design mode. Now, the paths to the images that will be used for the various states of the button are binded to strings passed from another subcomponent. There was no other way to get what we needed done, so it stays messy. Anyway, I don't get things to display correctly. Here's the code, and after an image for what I'm getting:
    [CODE]
    <s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
                             xmlns:mx="library://ns.adobe.com/flex/mx"
                             minWidth="21" minHeight="21" alpha.disabled="0.5"
                             preinitialize="initImageVars()" creationComplete="init()">
        <!-- host component -->
        <fx:Metadata>
            <![CDATA[
            [HostComponent("customComponents.ToggleButtonCustom")]
            ]]>
        </fx:Metadata>
        <!-- states -->
        <s:states>
            <s:State name="up" />
            <s:State name="down" />
            <s:State name="selected" />
            <s:State name="disabled" />
            <s:State name="over" />
        </s:states>
        <fx:Script>
            <![CDATA[        
                import mx.controls.Alert;
                /* First thing's first: we need to initialize our global and accessable components. */
                [Bindable]
                public var upButtonPath:String = "";
                [Bindable]
                public var downButtonPath:String = "";
                [Bindable]
                public var activeButtonPath:String = "";
                [Bindable]
                public var disabledButtonPath:String = "";
                [Bindable]
                protected var label:String = "";
                private function initImageVars():void
                    upButtonPath = "assets/" + this.hostComponent.upButtonPath;
                    downButtonPath = "assets/" + this.hostComponent.downButtonPath;
                    activeButtonPath = "assets/" + this.hostComponent.activeButtonPath;
                    disabledButtonPath = "assets/" + this.hostComponent.disabledButtonPath;
                private function init():void
                    /* Give values to public variables */
                    //upButtonPath = "Up.png";
                    //downButtonPath = "Down.png";
                    //activeButtonPath = "Active.png";
                    label = this.hostComponent.label;
                /* Define the skin elements that should not be colorized. For button, the graphics are colorized but the label is not. */
                static private const exclusions:Array = ["labelDisplay"];
                override public function get colorizeExclusions():Array {return exclusions;}
                override protected function initializationComplete():void
                    useChromeColor = true;
                    super.initializationComplete();
                private var cornerRadius:Number = 2;
            ]]>       
        </fx:Script>
        <!-- layer 1: fill -->
        <s:Rect id="fill" left="1" right="1" top="1" bottom="1" radiusX="2">
            <s:fill>
                <s:LinearGradient rotation="90">
                    <s:GradientEntry color="0xFFFFFF"
                                                     color.down="0xAAAAAA"
                                                     color.selected="0xBBBDBD"
                                                     alpha="0.85" />
                    <s:GradientEntry color="0xD8D8D8"
                                                     color.down="0x929496"
                                                     color.selected="0x9FA0A1"
                                                     alpha="0.85" />
                </s:LinearGradient>
            </s:fill>
        </s:Rect>
        <mx:ViewStack id="buttonImage" x="0" y="0"
                                    selectedIndex="0" selectedIndex.down="1" selectedIndex.selected="2"    selectedIndex.disabled="3">
            <s:NavigatorContent id="upState">
                <mx:Image source="{upButtonPath}" width="500" height="500" />
            </s:NavigatorContent>
            <s:NavigatorContent id="downState">
                <mx:Image source="{downButtonPath}" />
            </s:NavigatorContent>
            <s:NavigatorContent id="activeSate">
                <mx:Image source="{activeButtonPath}" />
            </s:NavigatorContent>
            <s:NavigatorContent id="disabledState">
                <mx:Image source="{disabledButtonPath}" />
            </s:NavigatorContent>
        </mx:ViewStack>
        <s:Label id="labelDisplay" text="{label}"
                         textAlign="center"
                         verticalAlign="middle"
                         maxDisplayedLines="3"
                         horizontalCenter="0" verticalCenter="1"
                         left="10" right="10" top="2" bottom="2">
        </s:Label>
    </s:SparkSkin>
    [/CODE]
    That gives me this image:
    And if I use the following code to resize it, I get this:
    [CODE]
    /* From the component, called from init(), which is called on creationComplete */
    private function resizeEverything():void
      var dummyImage:Image = new Image();
      var pathToDummy:String = "assets" + upButtonPath;
      dummyImage.source = pathToDummy;
      thisBtn.height = dummyImage.height;
      thisBtn.width = dummyImage.width;
      dummyImage = null;
    [/CODE]
    If you have any idea what to do with this, let me know. I set the buttons to the exact height and width of the images I'm using when I first call them. I don't know how else to manage this. I want the faded white to be an exact mirror of the image, so that designers (not me) can move them around on design mode. Thank you!

    Figured it out. The images I was given had large amounts of padding, and when I tried to auto-resize the buttons, Flash could never grab the image and therefore couldn't size off it, so the size of the component was forced to 0,0. It's all good now.

  • Until recently I was able to send images in the body of my Yahoo emails. Now, I am getting the message "This message has been truncated", and the email does not go through. I do not have this problem using IE. Could you please help? Thank you.

    Until recently I was able to send images in the body of my Yahoo emails. Now, I am getting the message "This message has been truncated", and the email does not go through. I do not have this problem using IE. Could you please help? Thank you.

    Try this -> http://support.apple.com/kb/TA38632?viewlocale=en_US

  • Downgrading Image Resolution Using JAI

    I am interested in downgrading the resolution of TIFF images that I am inserting into a PDF to reduce the document's file size. The TIFF images are either CCITT G4 bitonal or JPEG RGB. What would be the best approach to doing this using JAI?
    I appreciate any suggestions.
    Youssef Eldakar
    Bibliotheca Alexandrina

    Youssef
    The following code will load a TIFF image (or JPEG or some other formats that I can't remember) into a PlanarImage object and then rescale it according to the scale factors and then save as a TIFF.
    For example if you wanted to change a 320 x 240 image to a 160 x 120 use xScaleFactor and yScaleFactor of 0.5.
      public static PlanarImage rescale(String inputFilename, String outputFilename, float xScaleFactor, float yScaleFactor)
            // load the image from the file
            PlanarImage image = JAI.create("fileload", inputFilename);
            ParameterBlock rescaleParameters = new ParameterBlock();
            rescaleParameters.addSource(image);
            rescaleParameters.add(xScaleFactor);
            rescaleParameters.add(yScaleFactor);
            // saving as TIFF is a little more complicated than loading
            try
                FileOutputStream out = new FileOutputStream(outputFilename);
                TIFFEncodeParam parameters = new TIFFEncodeParam();
                ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF", out, parameters);
                try
                    encoder.encode(image);
                    out.close();
                catch (IOException e)
                    System.out.println("Failed to encode the image");
            catch (java.io.FileNotFoundException ioEx)
                System.out.println("Could not write to file " + filename);

  • Problem using the IMAQ Extract function.Not getting two different image out

    Hi, I am trying to use the multiple IMAQ extract functions to get certain parts of the webcam image and then using the color extract function to get the average RGB values. The problem is that both the IMAQ extract functions give the same image on its output port. The block diagram snippet and VI are attached below. Also, please let me know if there is a better way of doing this. I need to expand this later to extract rgb values of about 40-50 different parts of the image instead of just two shown below.
    Solved!
    Go to Solution.
    Attachments:
    Extract RGB Data.vi ‏104 KB

    You did not create another image that you should wire to the input "Image Dst" of "IMAQ Extract".  That's why you always operate on the original image (which you should not do if you intend to operate on several regions of the image).
    Solution: 
    (1) Create a new image and wire this to "Image Dst".
    (2) Apply the histogram operation sequentially (e.g. in a loop).
    That way you will notice, that Image Dst contains actually(!) the region you have specified.  (Put a probe on the image wire that goes from the Extract VI to the Histogram VI).

  • Flex 4.5 problem using image in Mobile Application (Android)

    I have a problem using flex and mobile application...
    I have an image with path = "/mnt/sdcard/images/20120202172020990.jpg"
    Simply using
         <s:Image id="image" source="/mnt/sdcard/images/20120202172020990.jpg" />
    Get me an empty image on device, still using it on computer (desktop build / debug) it works fine...
    I have enabled every kind of permission in the app.xml
    Why I got this error?

    I actually solved the problem using:
    image.source = File.desktopDirectory.resolvePath(file_name).url;
    using instead this one it will work only under windows...
    image.source = File.desktopDirectory.resolvePath(file_name).nativePath;
    I don't know if it's a bug or whatelse, but I think that the source property of Image passing a filename that start with / (/ is root for unix based OS, android, linux, ios, etc), will take is as a relative path instead of complete path...

  • My iphone has a problem, it simply does not work, the screen is all black with a few colorful scribbles and images blend, I used it only took 6 days and returned to service when operated only 7 more days and it happened again the same thing, what do I do?

    My iphone has a problem, it simply does not work, the screen is all black with a few colorful scribbles and images blend, I used it only took 6 days and returned to service when operated only 7 more days and it happened again the same thing, what do I do?

    Reset the PRAM
    Reinstall the operating system from the dvd (you will not loose your data)

  • Showing various images on browser using JSP and Servlet

    Hello Guys!
    I am starting to develop in Java and already I am facing a big problem.
    If somebody will have some tip or suggestion, will be very well comings!
    The application must present in browser images originnally of format TIF. As it is not a native format of the I.E. , I converted the image for JPG (without saving it on disk) and send it to the browser a encoded image (encode) using JAI library in one servlet had access by a JSP. Then, the structure of my application is thus:
    1) an archive JSP draws the initial screen in browser and presents one input text.
    2) later that the user places the parameter, I make an access to the database and read a quantity of images to be presented.
    3) From there in the proper JSP, I use de tag img src to send image to the browser in agreement archive the amount of images.
    It follows the code of the JSP:
    <% 
                    int intI=0;
                    int intCont=0;
                    if(blnImagem == true){
                        out.println("<br>");
                        out.println("<table border=0 STYLE=border-collapse:collapse>");
                        out.println("<tr>");
                        for(intI=0;intI < Processo.intQtdImagens;intI++){
                           Imagem.strImgTif = Imagem.IndicarImagem(Processo.strNmPath,Processo.strSubPath,Processo.intNuImagem,intI);                                                                    
                           out.println("<th>");
                           out.println("<table border=1 STYLE=border-collapse:collapse rules='cols'>");
                           out.println("<tr>");
                           out.println("<th>");
                           %>
                             <img src="ShowImg" WIDTH=100>
                           <%
                           out.println("</th>");
                           out.println("</tr>");
                           out.println("</table>");
    %>and code on the ShowImg servlet:
            response.setContentType("image/jpeg");       
            ServletOutputStream sos = response.getOutputStream();
            RenderedOp src = JAI.create("fileload", Imagem.strImgTif);           
            ImageEncoder encoder = ImageCodec.createImageEncoder("JPEG",sos,null);       
            encoder.encode(src); 
            sos.close();The problem is if I have 10 images to present, it WILL BE it is executed 10 times and it passes 10 names of different archives, but in the page only the last image is presented 10 times. It is as if it processed the TAG to the end of everything in way that the value of the static variable Imagem.strImgTif was chore only with the last value and the same loaded image 10 times. How I make to solve this? Somebody has some idea?
    THANK YOU !
    Emidio

    If I understand correctly what your problem is:
    Do this in the jsp:
    out.println("<img src=\"ShowImg?image=" + intI + "\" WIDTH=100>");
    In the image servlet, get the "image" parameter and parse it as an int. Move the Imagem.IndicarImagem() call to the image servlet.

  • Help!!! Image print problem

    hi,
    I want to print an image using JAI(Java Advance Imaging). I have something which scales the image
    first and then prints it out. It prints the image, but the resolution of the Image is horrible.
    The image comes out so blury it hard to see. Can anybody help me with this problem.
    Any help is always appreciated.
    Here is the Code.
    import java.util.*;
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import java.awt.print.*;
    import javax.media.jai.*;
    import com.sun.media.jai.codec.*;
    import java.awt.image.renderable.ParameterBlock;
    import javax.swing.RepaintManager;
    * <p>Title: </p>
    * <p>Description: </p>
    * <p>Copyright: Copyright (c) 2002</p>
    * <p>Company: </p>
    * @author unascribed
    * @version 1.0
    public class JAIImagePrint implements Printable {
    protected RenderedImage renderedImage;
    protected int imageWidth, imageHeight;
    protected Point printLoc = new Point(0,0);
    public void setPrintLocation(Point d) {
    printLoc = d;
    public Point getPrintLocation() {
    return printLoc;
    public void loadAndPrint(String filename){
    RenderedOp renderedOp = JAI.create("fileload", filename);
    renderedImage = renderedOp.createInstance();
    print();
    protected void print() {
    PrinterJob pj = PrinterJob.getPrinterJob().getPrinterJob();
    pj.setPrintable(this);
    pj.printDialog();
    try{
    pj.print();
    }catch(Exception e){System.out.println(e);}
    public int print(Graphics g, PageFormat f, int pageIndex){
    if(pageIndex >= 1) return Printable.NO_SUCH_PAGE;
    Graphics2D g2d = (Graphics2D) g;
    g2d.translate(f.getImageableX(), f.getImageableY());
    if(renderedImage != null){
    double scale = Math.min(f.getImageableWidth()/ renderedImage.getWidth(), f.getImageableHeight()/renderedImage.getHeight());
    Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_BICUBIC);
    ParameterBlock params = new ParameterBlock();
    params.addSource(renderedImage);
    params.add(new Float(scale));
    params.add(new Float(scale));
    params.add(0.0F);
    params.add(0.0F);
    params.add(interp);
    PlanarImage image = JAI.create("scale",params);
    printImage(g2d, image);
    return Printable.PAGE_EXISTS;
    } else return Printable.NO_SUCH_PAGE;
    public void printImage(Graphics2D g2d, RenderedImage image){
    if((image == null)|| (g2d == null)) return;
    int x = printLoc.x;
    int y = printLoc.y;
    AffineTransform at = new AffineTransform();
    at.translate(x,y);
    g2d.drawRenderedImage(image,at);

    I have run into the same problem. From what I have seen the Image object is only capable of handling a pixel based picture. A pixel based picture only has a resolution of 72 dots per inch, where as most printers have a much higher resolution.
    I haven't found a way around it yet. But I am looking at some alternative methods.

Maybe you are looking for

  • Dump : COMPUTE_INT_PLUS_OVERFLOW

    Hi experts, I am getting a dump COMPUTE_INT_PLUS_OVERFLOW in a report. its at the line: z1 = z1 + z1. Dump says: "Using + or 'ADD' to add the values 2060095488 and 2060095488 resulted in a value greater than 2147483647 or samller than -2147483648. Th

  • Java multi-thread Applet and Multi-processor

    Hello, I have a JAVA applet which work fine on a mono-processeur machine and not fine at all on multi-processors. It use multi thread (for reading on socket) and some times, request are lost. Is that a matter of programming or a JVM bug ? This happen

  • Trial Version PSE12 download

    I am currently trying to download the trial version of PSE12 on my MacBook Pro.  The download blue bar indicated that the files downloaded and immediately went into "extracting files" activity.   This was 7 hours ago.  It is still processing.  I also

  • Replacing MI424WR Rev F Router

    I got Asus RT-AC68U high speed router. Have it hooked to my MI424WR Rev F router as an WL Access Point. MI424WR was having issues connecting to my WiiU. The Asus has no issues. I want to make the Asus the main router (much faster). I know CAT5 to ONT

  • Nokia N8 won't playback music

    hi i have had my nokia a little over a week and have been happy with it so far though i am having trouble playing music.  i have loaded lots of music on and it wouldn't playback at all.  i removed them all and tried again.  they play now but just ver