Menu
News
All News
Dungeons & Dragons
Level Up: Advanced 5th Edition
Pathfinder
Starfinder
Warhammer
2d20 System
Year Zero Engine
Industry News
Reviews
Dragon Reflections
White Dwarf Reflections
Columns
Weekly Digests
Weekly News Digest
Freebies, Sales & Bundles
RPG Print News
RPG Crowdfunding News
Game Content
ENterplanetary DimENsions
Mythological Figures
Opinion
Worlds of Design
Peregrine's Nest
RPG Evolution
Other Columns
From the Freelancing Frontline
Monster ENcyclopedia
WotC/TSR Alumni Look Back
4 Hours w/RSD (Ryan Dancey)
The Road to 3E (Jonathan Tweet)
Greenwood's Realms (Ed Greenwood)
Drawmij's TSR (Jim Ward)
Community
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions, OSR, & D&D Variants
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Resources
Wiki
Pages
Latest activity
Media
New media
New comments
Search media
Downloads
Latest reviews
Search resources
EN Publishing
Store
EN5ider
Adventures in ZEITGEIST
Awfully Cheerful Engine
What's OLD is NEW
Judge Dredd & The Worlds Of 2000AD
War of the Burning Sky
Level Up: Advanced 5E
Events & Releases
Upcoming Events
Private Events
Featured Events
Socials!
EN Publishing
Twitter
BlueSky
Facebook
Instagram
EN World
BlueSky
YouTube
Facebook
Twitter
Twitch
Podcast
Features
Top 5 RPGs Compiled Charts 2004-Present
Adventure Game Industry Market Research Summary (RPGs) V1.0
Ryan Dancey: Acquiring TSR
Q&A With Gary Gygax
D&D Rules FAQs
TSR, WotC, & Paizo: A Comparative History
D&D Pronunciation Guide
Million Dollar TTRPG Kickstarters
Tabletop RPG Podcast Hall of Fame
Eric Noah's Unofficial D&D 3rd Edition News
D&D in the Mainstream
D&D & RPG History
About Morrus
Log in
Register
What's new
Search
Search
Search titles only
By:
Forums & Topics
Forum List
Latest Posts
Forum list
*Dungeons & Dragons
Level Up: Advanced 5th Edition
D&D Older Editions, OSR, & D&D Variants
*TTRPGs General
*Pathfinder & Starfinder
EN Publishing
*Geek Talk & Media
Search forums
Chat/Discord
Menu
Log in
Register
Install the app
Install
Upgrade your account to a Community Supporter account and remove most of the site ads.
Enchanted Trinkets Complete--a hardcover book containing over 500 magic items for your D&D games!
Community
General Tabletop Discussion
*Geek Talk & Media
Looking for a C/Java library that will read in Greyscale TIFFs and produce a matrix
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Fenlock" data-source="post: 1732092" data-attributes="member: 6305"><p>libtiff.org had som sample images, so here is some code that works <img src="https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f600.png" class="smilie smilie--emoji" loading="lazy" width="64" height="64" alt=":D" title="Big grin :D" data-smilie="8"data-shortname=":D" /> </p><p></p><p>[CODE]</p><p>import java.awt.Color;</p><p>import java.awt.Graphics2D;</p><p>import java.awt.GraphicsConfiguration;</p><p>import java.awt.GraphicsDevice;</p><p>import java.awt.GraphicsEnvironment;</p><p>import java.awt.Transparency;</p><p>import java.awt.image.BufferedImage;</p><p>import java.awt.image.RenderedImage;</p><p>import java.io.File;</p><p>import java.io.IOException;</p><p>import javax.imageio.ImageIO;</p><p>import javax.media.jai.*;</p><p></p><p>public class TiffReader {</p><p> private int _width, _height;</p><p> private int[] _buffer;</p><p> </p><p> private void loadBuffer(String sourcepath) {</p><p> RenderedImage ri = JAI.create("fileload", sourcepath);</p><p> java.awt.image.Raster raster = ri.getData();</p><p> </p><p> int miny = raster.getMinY();</p><p> int maxy = miny + raster.getHeight();</p><p> int minx = raster.getMinX();</p><p> int maxx = minx + raster.getWidth();</p><p> _width = maxx-minx;</p><p> _height = maxy - miny;</p><p> </p><p> int[] p = new int[1];</p><p> _buffer = new int[_width * _height];</p><p> </p><p> for (int x = minx; x < maxx; x++) {</p><p> for (int y = miny; y < maxy; y++) {</p><p> p = raster.getPixel(x, y, p);</p><p> int pos = (x - minx) * _height + y - miny;</p><p> _buffer[pos] = p[0];</p><p> }</p><p> } </p><p> }</p><p> </p><p> private RenderedImage createImage() {</p><p> GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();</p><p> GraphicsDevice gd = ge.getDefaultScreenDevice();</p><p> GraphicsConfiguration gc = gd.getDefaultConfiguration();</p><p> BufferedImage bi = gc.createCompatibleImage(_width, _height, Transparency.OPAQUE);</p><p> Graphics2D g2d = bi.createGraphics();</p><p> </p><p> Color[] colors = new Color[256];</p><p> for (int c=0; c<256; c++)</p><p> colors[c] = new Color(c, c, c);</p><p> </p><p> for (int x = 0; x < _width; x++)</p><p> for (int y = 0; y < _height; y++) {</p><p> g2d.setColor(colors[_buffer[x * _height + y]]);</p><p> g2d.drawLine(x,y, x,y);</p><p> }</p><p> g2d.dispose();</p><p> </p><p> return bi;</p><p> }</p><p> </p><p> private void saveImage(RenderedImage image, String destinationpath) {</p><p> try {</p><p> File f = new File(destinationpath);</p><p> ImageIO.write(image, "jpg", f);</p><p> } catch (IOException e) {</p><p> } </p><p> }</p><p> </p><p> public void Transform(String sourcepath, String destinationpath) {</p><p> loadBuffer(sourcepath);</p><p> saveImage(createImage(), destinationpath);</p><p> }</p><p> </p><p> public static void main(String[] args) {</p><p> TiffReader tr = new TiffReader();</p><p> </p><p> switch (args.length) {</p><p> case 0:</p><p> System.exit(-1);</p><p> break;</p><p> case 1:</p><p> tr.Transform(args[0], args[0]+".jpg");</p><p> break;</p><p> default:</p><p> tr.Transform(args[0], args[1]);</p><p> } </p><p> System.out.println("Done!");</p><p> }</p><p>}</p><p>[/CODE] </p><p></p><p>graphics have never been my strong side, so you could probably create the new image easier (using a colormap).</p><p></p><p>/f</p></blockquote><p></p>
[QUOTE="Fenlock, post: 1732092, member: 6305"] libtiff.org had som sample images, so here is some code that works :D [CODE] import java.awt.Color; import java.awt.Graphics2D; import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Transparency; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.media.jai.*; public class TiffReader { private int _width, _height; private int[] _buffer; private void loadBuffer(String sourcepath) { RenderedImage ri = JAI.create("fileload", sourcepath); java.awt.image.Raster raster = ri.getData(); int miny = raster.getMinY(); int maxy = miny + raster.getHeight(); int minx = raster.getMinX(); int maxx = minx + raster.getWidth(); _width = maxx-minx; _height = maxy - miny; int[] p = new int[1]; _buffer = new int[_width * _height]; for (int x = minx; x < maxx; x++) { for (int y = miny; y < maxy; y++) { p = raster.getPixel(x, y, p); int pos = (x - minx) * _height + y - miny; _buffer[pos] = p[0]; } } } private RenderedImage createImage() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); BufferedImage bi = gc.createCompatibleImage(_width, _height, Transparency.OPAQUE); Graphics2D g2d = bi.createGraphics(); Color[] colors = new Color[256]; for (int c=0; c<256; c++) colors[c] = new Color(c, c, c); for (int x = 0; x < _width; x++) for (int y = 0; y < _height; y++) { g2d.setColor(colors[_buffer[x * _height + y]]); g2d.drawLine(x,y, x,y); } g2d.dispose(); return bi; } private void saveImage(RenderedImage image, String destinationpath) { try { File f = new File(destinationpath); ImageIO.write(image, "jpg", f); } catch (IOException e) { } } public void Transform(String sourcepath, String destinationpath) { loadBuffer(sourcepath); saveImage(createImage(), destinationpath); } public static void main(String[] args) { TiffReader tr = new TiffReader(); switch (args.length) { case 0: System.exit(-1); break; case 1: tr.Transform(args[0], args[0]+".jpg"); break; default: tr.Transform(args[0], args[1]); } System.out.println("Done!"); } } [/CODE] graphics have never been my strong side, so you could probably create the new image easier (using a colormap). /f [/QUOTE]
Insert quotes…
Verification
Post reply
Community
General Tabletop Discussion
*Geek Talk & Media
Looking for a C/Java library that will read in Greyscale TIFFs and produce a matrix
Top