
Create your Lithophane from BMP via Java
Create your Lithophane from BMP using Java library without any 3D modeling software.
How to Create your Lithophane from BMP File Using Java
In order to create your lithophane from BMP file, we’ll use
API which is a feature-rich, powerful and easy to use lithophane API for Java platform. You can download its latest version directly from
and install it within your Maven-based project by adding the following configurations to the pom.xml.
Repository
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-3d</artifactId>
<version>version of aspose-3d API</version>
<classifier>jdk17</classifier>
</dependency>
Steps to Create your Lithophane from BMP via Java
Java programmers can easily create your lithophane from BMP in just a few lines of code.
- Create some new parameters and create a Mesh object
- Perform computational operations on Mesh objects
- BMP file loads 3d scene through Mesh class
- Call the Scene.Save method with object
System Requirements
Aspose.3D for JAVA is supported on all major operating systems. Just make sure that you have the following prerequisites.
- Microsoft Windows or a compatible OS with Java Runtime Environment for JSP/JSF Application and Desktop Applications.
- Get latest version of Aspose.3D for Java directly from Maven.
JAVA code to Create your Lithophane from BMP
//The original image that needs to be uploaded and the 3d file output after saving
String file = "template.bmp";
String output = "outFile.fbx";
//Create some new parameters
TextureData td= TextureData.fromFile(file);
final float nozzleSize = 0.9f;//0.2mm
final float layerHeight = 0.2f;
float[][] grayscale = ToGrayscale(td);
final float width = 120.0f;//canvas width is 200.0mm
float height = width / td.getWidth() * td.getHeight();
float thickness = 10.0f;//10mm thickness
float layers = thickness / layerHeight;
int widthSegs = (int)Math.floor(width / nozzleSize);
int heightSegs = (int)Math.floor(height / nozzleSize);
//Perform computational operations on Mesh objects
Mesh mesh = new Mesh();
for (int y = 0; y < heightSegs; y++)
{
float dy = (float)y / heightSegs;
for (int x = 0; x < widthSegs; x++)
{
float dx = (float)x / widthSegs;
float gray = Sample(grayscale, td.getWidth(), td.getHeight(), dx, dy);
float v = (1 - gray) * thickness;
mesh.getControlPoints().add(new Vector4(dx * width, dy * height, v));
}
}
for (int y = 0; y < heightSegs - 1; y++)
{
int row = (y * heightSegs);
int ptr = row;
for (int x = 0; x < widthSegs - 1; x++)
{
mesh.createPolygon(ptr, ptr + widthSegs, ptr + 1);
mesh.createPolygon(ptr + 1, ptr + widthSegs, ptr + widthSegs + 1);
ptr++;
}
}
//Generate 3d scene and save objects
Scene scene = new Scene(mesh);
scene.save(output, FileFormat.FBX7400ASCII);
//The sample method to call
static float Sample(float[][] data, int w, int h, float x, float y)
{
return data[(int)(x * w)][(int)(y * h)];
}
//ToGrayscale method to call
static float[][] ToGrayscale(TextureData td)
{
float[][] ret = new float[td.getWidth()][td.getHeight()];
int stride =td.getStride();
byte[] data = td.getData();
int bytesPerPixel = td.getBytesPerPixel();
for (int y = 0; y < td.getHeight(); y++)
{
int ptr = y * stride;
for (int x = 0; x < td.getWidth(); x++)
{
float v = (data[ptr] * 0.21f + data[ptr + 1] * 0.72f + data[ptr + 2] * 0.07f) / 255.0f;
ret[x][y] = v;
ptr += bytesPerPixel;
}
}
return ret;
}
Free App to Create your Lithophane from BMP
Lithophane BMP right now by visiting our Live Demos website.The live demo has the following benefits
Java 3D Scene Manipulation Library
Aspose.3D is a CAD and Gameware API to load, modify and convert 3D files. API is a standalone and does not require any any 3D modeling or rendering software. One can easily use API for Discreet3DS, WavefrontOBJ, STL (ASCII, Binary), Universal3D, FBX (ASCII, Binary), Collada, glTF, PLY, GLB, DirectX and more formats.BMP What is BMP File Format?
Files having extension .BMP represent bitmap image files that are used to store bitmap digital images. These images are independent of graphics adapter and are also called device independent bitmap (DIB) file format. This independency serves the purpose of opening the file on multiple platforms such as Microsoft Windows and Mac. The BMP file format can store data as two-dimensional digital images in both monochrome as well as color format with various colour depths.
Read MoreOther Supported App to Create your Lithophane from Formats
Using JAVA, One can also create your lithophane from many other file formats including.