public static BufferedImage createRGBAImageFromRGBA(Raster rgbaRaster,ICC_Profile rgbaProfile){
  BufferedImage image;
  int w=rgbaRaster.getWidth();
  int h=rgbaRaster.getHeight();
  rgbaProfile=null;
{
    int[] rgb=new int[w * h];
    int[] R=rgbaRaster.getSamples(0,0,w,h,0,(int[])null);
    int[] G=rgbaRaster.getSamples(0,0,w,h,1,(int[])null);
    int[] B=rgbaRaster.getSamples(0,0,w,h,2,(int[])null);
    int[] A=rgbaRaster.getSamples(0,0,w,h,3,(int[])null);
    for (int i=0, imax=R.length; i < imax; i++) {
      rgb[i]=A[i] << 24 | R[i] << 16 | G[i] << 8 | B[i];
    }
    Raster rgbRaster=Raster.createPackedRaster(new DataBufferInt(rgb,rgb.length),w,h,w,new int[]{0xff0000,0xff00,0xff,0xff000000},null);
    ColorSpace cs=ColorSpace.getInstance(ColorSpace.CS_sRGB);
    ColorModel cm=new DirectColorModel(cs,32,0xff0000,0xff00,0xff,0x0ff000000,false,DataBuffer.TYPE_INT);
    image=new BufferedImage(cm,(WritableRaster)rgbRaster,true,null);
  }
  return image;
}

public static BufferedImage createRGBAImageFromRGBA ( Raster rgbaRaster , ICC_Profile rgbaProfile ) { BufferedImage image ; int w = rgbaRaster . getWidth ( ) ; int h = rgbaRaster . getHeight ( ) ; rgbaProfile = null ; { int [ ] rgb = new int [ w * h ] ; int [ ] R = rgbaRaster . getSamples ( 0 , 0 , w , h , 0 , ( int [ ] ) null ) ; int [ ] G = rgbaRaster . getSamples ( 0 , 0 , w , h , 1 , ( int [ ] ) null ) ; int [ ] B = rgbaRaster . getSamples ( 0 , 0 , w , h , 2 , ( int [ ] ) null ) ; int [ ] A = rgbaRaster . getSamples ( 0 , 0 , w , h , 3 , ( int [ ] ) null ) ; for ( int i = 0 , imax = R . length ; i < imax ; i ++ ) { rgb [ i ] = A [ i ] << 24 | R [ i ] << 16 | G [ i ] << 8 | B [ i ] ; } Raster rgbRaster = Raster . createPackedRaster ( new DataBufferInt ( rgb , rgb . length ) , w , h , w , new int [ ] { 0xff0000 , 0xff00 , 0xff , 0xff000000 } , null ) ; ColorSpace cs = ColorSpace . getInstance ( ColorSpace . CS_sRGB ) ; ColorModel cm = new DirectColorModel ( cs , 32 , 0xff0000 , 0xff00 , 0xff , 0x0ff000000 , false , DataBuffer . TYPE_INT ) ; image = new BufferedImage ( cm , ( WritableRaster ) rgbRaster , true , null ) ; } return image ; }
creates a buffered image from a raster in the rgba color space , converting the colors to rgb using the provided cmyk icc_profile . as seen from a comment made by ' phelps ' at http : / / bugs . sun . com / bugdatabase / view_bug . do ? bug_id = 4799903
