Path: csiph.com!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Fred Greer Newsgroups: comp.lang.java.programmer Subject: Re: ImageIO/BufferedImage behaving inconsistently from one day to the next. Date: Thu, 21 Jun 2012 04:58:46 +0000 (UTC) Organization: A noiseless patient Spider Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 21 Jun 2012 04:58:46 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="8/8JQq6c1kRmpw0DMqPx+Q"; logging-data="2996"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tX6LGd2GqlQFfzfdh9EXuzAma6eyGzq4=" X-Mailer: MicroPlanet-Gravity/3.0.4 Cancel-Lock: sha1:fbaF9TEFBm9cJB2Px+rBUyPBN18= Xref: csiph.com comp.lang.java.programmer:15483 On Wed, 20 Jun 2012 21:23:35 -0700, Knute Johnson wrote: > On 6/20/2012 5:23 PM, Fred Greer wrote: >> On Wed, 20 Jun 2012 08:39:37 -0700, Knute Johnson wrote: >> >>> On 6/19/2012 7:31 PM, Fred Greer wrote: >>>> I have code that used to work perfectly, which processes images in >>>> certain ways, and today it suddenly was not working. I hadn't changed >>>> the code at all. I tracked the problem down to spurious >>>> IllegalArgumentExceptions being thrown by this code: >>>> >>>> public class ImageUtils { >>>> >>>> private static float[] BLUR = {0.1111111, 0.1111111, 0.1111111, >>>> 0.1111111, 0.1111111, 0.1111111, >>>> 0.1111111, 0.1111111, 0.1111111} >>>> ... >>>> public static BufferedImage blur (BufferedImage img) { >>>> Kernel k = new Kernel(3, 3, BLUR); >>>> ConvolveOp co = new ConvolveOp(k, ConvolveOp.EDGE_NO_OP, >>>> null); BufferedImage dest = new >>>> BufferedImage(img.getWidth(), >>>> img.getHeight(),img.getType()); >>> >>> Please try just putting BufferedImage.TYPE_INT_ARGB here instead of >>> getting the type from the other image and tell us what happens. >> >> Are 32-bit PNGs loaded via ImageIO.read guaranteed to be ARGB, or at >> least compatible with ARGB destination images for the purposes of >> ConvolveOp and friends? > > I am certainly no expert but I would think that a PNG file would create > an ARGB image without any problems and I was curious what would happen. > > The other option is to not even create a new image and just convert the > one you have by putting null destination field. I thought that didn't work, at least for some transformations? At the same time, I prefer to minimize mutation and prefer creating new objects. There's much less scope for concurrency problems and some other sorts of bugs that way, particularly when a single object is used in various places and none of them expect it to change because of one of the other places.