![JPG 이미지를 리소판 C#으로](images/JPG%20Image%20to%20Lithophane.jpg#center)
JPG 이미지는 사진, 그림 및 기타 시각적 정보를 저장하는 데 널리 사용됩니다. 반면, lithophane은 뒤에 있는 광원에 따라 특성이 변하는 3차원 이미지를 나타냅니다. 이 문서에서는 C#에서 JPG 이미지를 리소판으로 변환하는 방법을 다룹니다.
JPG 이미지-리소판 변환기 – C# API 설치
Aspose.3D for .NET API를 사용하여 다양한 3차원 모델을 조작할 수 있습니다. 다운로드 섹션에서 또는 다음 NuGet 설치 명령을 사용하여 DLL 파일을 다운로드하여 API를 구성하기만 하면 됩니다.
PM> Install-Package Aspose.3D
C#에서 JPG 이미지를 리소판으로 변환
다음 단계에 따라 JPG 이미지를 Lithophane으로 변환할 수 있습니다.
- 입력된 JPG 이미지를 로드합니다.
- Mesh 개체에 대한 계산 작업을 수행합니다.
- Save 방법을 사용하여 3D 장면을 생성하고 개체를 저장합니다.
다음 샘플 코드는 C#에서 프로그래밍 방식으로 JPG 이미지를 Lithophane으로 변환하는 방법을 보여줍니다.
string file = "template.jpg";
string output = "file.fbx";
// 몇 가지 새 매개변수 생성
Aspose.ThreeD.Render.TextureData td = Aspose.ThreeD.Render.TextureData.FromFile(file);
const float nozzleSize = 0.9f;
const float layerHeight = 0.2f;
var grayscale = ToGrayscale(td);
const float width = 120.0f;
float height = width / td.Width * td.Height;
float thickness = 10.0f;
float layers = thickness / layerHeight;
int widthSegs = (int)Math.Floor(width / nozzleSize);
int heightSegs = (int)Math.Floor(height / nozzleSize);
// 메쉬 개체에 대한 계산 작업 수행
Aspose.ThreeD.Entities.Mesh mesh = new Aspose.ThreeD.Entities.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.Width, td.Height, dx, dy);
float v = (1 - gray) * thickness;
mesh.ControlPoints.Add(new Aspose.ThreeD.Utilities.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++;
}
}
// 3D 장면 생성 및 개체 저장
Aspose.ThreeD.Scene scene = new Aspose.ThreeD.Scene(mesh);
scene.Save(output, Aspose.ThreeD.FileFormat.FBX7400ASCII);
// 호출할 샘플 메서드
static float Sample(float[,] data, int w, int h, float x, float y)
{
return data[(int)(x * w), (int)(y * h)];
}
// 호출할 ToGrayscale 메서드
static float[,] ToGrayscale(Aspose.ThreeD.Render.TextureData td)
{
var ret = new float[td.Width, td.Height];
var stride = td.Stride;
var data = td.Data;
var bytesPerPixel = td.BytesPerPixel;
for (int y = 0; y < td.Height; y++)
{
int ptr = y * stride;
for (int x = 0; x < td.Width; x++)
{
var 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;
}
무료 임시 라이센스 받기
무료 임시 라이선스를 요청하여 API를 전체 용량으로 평가할 수 있습니다.
온라인 데모
이 API를 사용하여 개발된 JPG Image to Lithophane Converter 웹 앱을 사용해 보십시오.
결론
이 기사에서는 JPG 이미지를 리소판으로 변환하는 방법을 살펴보았습니다. 리소판을 사용하여 3D 모델을 만들 수 있으며 두께를 사용하여 이미지의 어둠을 반영하고 인쇄된 모델 뒤에 광원을 놓으면 이미지를 볼 수 있습니다. 또한 문서 섹션을 방문하여 API에서 제공하는 다른 기능을 확인할 수 있습니다. 모호한 점이 있는 경우 포럼으로 문의해 주십시오.