Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11855 Posts in 1569 Topics- by 3054 Members - Latest Member: Ljustin770

11. February 2012, 12:52:40 PM
Xith3D CommunityGeneral CategorySupport (Moderator: Marvin Fröhlich)Loading Texture in database
Pages: [1]
Print
Author Topic: Loading Texture in database  (Read 262 times)
elijah
Enjoying the stay
*
Offline Offline

Posts: 72


View Profile
« on: 26. February 2010, 12:15:00 AM »

I have image file that are stored in the database. I need to retrieve the image from the database and load it as Texture2D. I tried the following code and it does not work.
Code:
// Get the image from the database as in ObjectInputStream
public static ObjectInputStream getXithImageIcon(ResultSet rs, String ColumnName) throws SQLException, IOException, ClassNotFoundException {
ObjectInputStream ois = null;
Blob blob;

blob = rs.getBlob(ColumnName);

if (blob != null) {
System.out.println( "blob Size = " + blob.length() );

ois = new ObjectInputStream(blob.getBinaryStream());
blob.free();

}

// return loader.data[0];
return ois;
}

Code:
// normalImage , hoveredImage , pressImage  are the ObjectInputStream being loaded from the database.
try {
TextureLoader loader = TextureLoader.getInstance();
if (normalImage != null) {
NORMAL_IMAGE = loader.loadTexture(normalImage, FlipMode.NOT_FLIPPED, TextureFormat.RGBA, MipmapMode.BASE_LEVEL, true);
normalImage.close();

}

if (hoveredImage != null) {
HOVERED_IMAGE = loader.loadTexture(hoveredImage, FlipMode.NOT_FLIPPED, TextureFormat.RGBA, MipmapMode.BASE_LEVEL, true);
hoveredImage.close();
}

if (pressImage != null) {
PRESS_IMAGE = loader.loadTexture(pressImage, FlipMode.NOT_FLIPPED, TextureFormat.RGBA, MipmapMode.BASE_LEVEL, true);
pressImage.close();
}



} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

I'm getting a Square 2X2 black and white image. Can anybody help me on this ?
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #1 on: 26. February 2010, 10:20:47 AM »

The 2x2 image is the fallback texture, that is returned, if anything went wrong during the texture loading process (i.e. exception is thrown).

I suggest to just store the texture name, resolution and color depth and the pixel data to the database and then simply implement a TextureImageFormatLoader and load that data.

Marvin
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic