Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2005

Tip: Looking for answers? Try searching our database.

loss of color in image transformation

Thread view: 
Ishmael Rufus - 09 Aug 2005 22:47 GMT
I seem to run into a dead end.

I have been able to perform an image transformation into a smaller
image, however I always seem to lose a color channel.

Can anyone help me?

Here is the code below which does the transformation:
//Load Image into a buffer
    bufimage = ImageIO.read(file);
//Caculate sizes
    int newWidth, newHeight, width,height;
    width = bufimage.getWidth();
    height = bufimage.getHeight();
    newWidth = (int)(width * newSize);
    newHeight = (int)(height * newSize);

    BufferedImage newbufimage = new BufferedImage(newWidth, newHeight,
BufferedImage.TYPE_INT_ARGB); //Loss of color
    BufferedImageOp op = null;
    op = new
AffineTransformOp(AffineTransform.getScaleInstance(newSize,newSize),null);
    op.filter(bufimage, newbufimage);

//Now write the image to file - 1. opening a new file
    String outfile = file.getPath().substring(0,
file.getPath().lastIndexOf('\\') +
1).concat(file.getName().substring(0,
file.getName().indexOf('.')).concat("NEW.jpg"));
    File newFile = new File(outfile);

//Write to file
    ImageIO.write(newbufimage, "jpg", newFile);
    System.out.println("Wrote " + outfile + " to file");
//Clean up
    bufimage.flush();
    bufimage = null;
Ross Marchant - 09 Aug 2005 23:21 GMT
> I seem to run into a dead end.
>
> I have been able to perform an image transformation into a smaller
> image, however I always seem to lose a color channel.

<snip>

> BufferedImage newbufimage = new BufferedImage(newWidth, newHeight,
> BufferedImage.TYPE_INT_ARGB); //Loss of color
> BufferedImageOp op = null;

Maybe you want TYPE_INT_RGB, because jpg's do not have an alpha channel.

Ross
Ishmael Rufus - 11 Aug 2005 04:07 GMT
When i try using TYPE_INT_RGB I get an ImageOpException thrown: Unable
to transform src image where i call the filter method of "op"

op.filter(bufimage, newbufimage)
Boudewijn Dijkstra - 12 Aug 2005 17:40 GMT
>I seem to run into a dead end.
>
[quoted text clipped - 15 lines]
> BufferedImage newbufimage = new BufferedImage(newWidth, newHeight,
> BufferedImage.TYPE_INT_ARGB); //Loss of color

Graphics2D g = (Graphics2D) newbufimage.createGraphics();
#if defined STATIC_CONTEXT
g.drawImage(bufimage, 0, 0, null);
#elif BOOLEAN_EXPRESSION(this instanceof java.awt.Component)
g.drawImage(bufimage, 0, 0, this);
#endif

/*
> BufferedImageOp op = null;
> op = new
> AffineTransformOp(AffineTransform.getScaleInstance(newSize,newSize),null);
> op.filter(bufimage, newbufimage);
*/

> //Now write the image to file - 1. opening a new file
> String outfile = file.getPath().substring(0,
[quoted text clipped - 9 lines]
> bufimage.flush();
> bufimage = null;


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.