Update Image.java
parent
eb61ff715f
commit
c3ae97b99d
|
@ -50,38 +50,6 @@ public class Image
|
|||
this.comp = comp;
|
||||
}
|
||||
|
||||
public Image(String imagePath)
|
||||
{
|
||||
ByteBuffer img;
|
||||
ByteBuffer imageBuffer;
|
||||
try
|
||||
{
|
||||
imageBuffer = IOUtil.ioResourceToByteBuffer(imagePath, 8 * 1024);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try (MemoryStack stack = stackPush())
|
||||
{
|
||||
IntBuffer w = stack.mallocInt(1);
|
||||
IntBuffer h = stack.mallocInt(1);
|
||||
IntBuffer comp = stack.mallocInt(1);
|
||||
// Use info to read image metadata without decoding the entire image.
|
||||
// We don't need this for this demo, just testing the API.
|
||||
if (!stbi_info_from_memory(imageBuffer, w, h, comp))
|
||||
{ throw new RuntimeException("Failed to read image information: " + stbi_failure_reason()); }
|
||||
// Decode the image
|
||||
img = stbi_load_from_memory(imageBuffer, w, h, comp, 0);
|
||||
if (img == null)
|
||||
{ throw new RuntimeException("Failed to load image: " + stbi_failure_reason()); }
|
||||
this.image = img;
|
||||
this.width = w.get(0);
|
||||
this.height = h.get(0);
|
||||
this.comp = comp;
|
||||
}
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{ return height; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue