<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Brian,<div><br></div><div>BufferedImage is always 2D, so you cannot have a BufferedImage with dimensions (height, width, 3).</div><div><br></div><div>If you know that you have an ArrayImg and you know the pixel Type, you can get to the underlying primitive array, for example</div><div><div style="margin: 0px; font-size: 11px; font-family: Monaco;"><span style="color: rgb(147, 26, 104);">byte</span>[] array = ( <span style="color: #931a68">byte</span>[] ) ( ( ArrayDataAccess< ? > ) img.update( <span style="color: #931a68">null</span> ) ).getCurrentStorageArray()</div></div><div>if you know that img is a UnsignedByteType ArrayImg. Then you wrap that in a BufferedImage.</div><div><br></div><div>You can do the same thing the other way around: Get the primitive array from the BufferedImage and wrap it in an ArrayImg.</div><div><br></div><div>Essentially the code you found does that for you for the standard PixelTypes (UnsignedByteType, ARGBType, etc )...</div><div><br></div><div>best regards,</div><div>Tobias</div><div><br><div><div>On 20 Aug 2014, at 00:20, Brian Schlining <<a href="mailto:bschlining@gmail.com">bschlining@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-family: Helvetica, Arial; padding: 1em; margin: auto; background-color: rgb(254, 254, 254); font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; position: static; z-index: auto;"><div class="bloop_markdown"><p style="margin: 15px 0px;">Hi All,</p><p style="margin: 15px 0px;">I’m trying to use imglib2 for some image processing. One thing I need to do is transform Img (actually ArrayImg) objects to BufferedImages. I’d also like to be able to transform those BufferedImages back into ArrayImg objects. For the most part I’m currently working with just PNG and JPEG (i.e. ARGB).</p><p style="margin: 15px 0px;"><strong>I think I found a way to convert an Img to BufferedImage, but I’m not sure this is the recommended method. So if anyone has a better recommendation, please let me know!!</strong><span class="Apple-converted-space"> </span>Here’s the method I found:</p><pre style="margin: 15px 0px; font-family: Monaco; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px;"><code style="font-family: Monaco; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px;">// Scala code, sorry Java folks.
import net.imglib2.img.display.imagej.ImageJFunctions
val imagePlus = ImageJFunctions.wrap(img, "")
val bufferedImage = imagePlus.getBufferedImage
</code></pre><p style="margin: 15px 0px;"><strong>How do I convert the buffered image back to an Img object?</strong><span class="Apple-converted-space"> </span>I saw this code at<span class="Apple-converted-space"> </span><a href="https://github.com/imglib/imglib/blob/imglib2-2.0.0-beta-21/scripting/src/main/java/net/imglib2/script/bufferedimag/BufferedImageImg.java" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;">https://github.com/imglib/imglib/…/BufferedImageImg.java</a>, but the resulting ArrayImg has dimensions of (height, width, 1) instead of the expected dimensions of (heigh, width, 3), so it doesn’t appear to be doing the right thing.</p><p style="margin: 15px 0px;">Thanks!</p><p style="margin: 15px 0px;">Brian</p></div><div class="bloop_original_html"><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;"><br></div><br><div id="bloop_sign_1408485827834051072" class="bloop_sign"><div style="font-family: helvetica, arial; font-size: 13px;">-- <br>Brian Schlining<br></div></div></div><div class="bloop_markdown"><div style="margin: 15px 0px;"><br class="webkit-block-placeholder"></div></div>_______________________________________________<br>ImageJ-devel mailing list<br><a href="mailto:ImageJ-devel@imagej.net" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;">ImageJ-devel@imagej.net</a><br><a href="http://imagej.net/mailman/listinfo/imagej-devel" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;">http://imagej.net/mailman/listinfo/imagej-devel</a><br></div></blockquote></div><br></div></body></html>