libpng와 함께 FreeType 라이브러리를 사용하여 글리프의 PNG 이미지를 출력하려고합니다. 글리프 래스터 비트 맵을 만들 수 있고 유효한 PNG 파일을 만들 수 있지만 두 가지를 함께 넣을 수는 없습니다. 문제는 끝 부분이 라인에서 온다 :C 컴파일러 오류 : 포인터 유형으로 변환 할 수 없습니다.
png_bytep image = (png_bytep) slot->bitmap;
내가 단순히 png_bytep
에 FreeType에서 비트 맵을 캐스팅하고 pnglib을 통과 할 수없는 것 같다 (이 소망 적 사고였다). 다음 오류가 발생합니다.
/home/david/Desktop/png.c: In function ‘main’:
/home/david/Desktop/png.c:47:2: error: cannot convert to a pointer type
그러나 여기서부터 어떻게해야하는지 잘 모르겠습니다. 그러나 여기에 코드의 전체 블록 : 당신은 이미지 대신 &image
를 통과해야처럼
#include <stdlib.h>
#include <stdio.h>
#include <png.h>
#include <ft2build.h>
#include FT_FREETYPE_H
main() {
// Declare FreeType variables
FT_Library library;
FT_Face face;
FT_GlyphSlot slot = face->glyph;
FT_UInt glyph_index;
int pen_x, pen_y, n;
char* file = "/usr/share/fonts/truetype/freefont/FreeMono.ttf";
// Declare PNG variables
png_uint_32 width = 100;
png_uint_32 height = 100;
int bit_depth = 16;
int color_type = PNG_COLOR_TYPE_GRAY;
char* file_name = "/home/david/Desktop/out.png";
png_structp png_ptr;
png_infop info_ptr;
// Render font
FT_New_Face(library, file, 0, &face);
FT_Set_Pixel_Sizes(face, 0, 16);
glyph_index = 30;
FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT);
FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
// Create a PNG file
FILE *fp = fopen(file_name, "wb");
// Create the PNG in memory
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
info_ptr = png_create_info_struct(png_ptr);
png_init_io(png_ptr, fp);
// Write the header
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_write_info(png_ptr, info_ptr);
// Write image data
png_bytep image = (png_bytep) slot->bitmap;
png_write_image(png_ptr, &image);
// End write
png_write_end(png_ptr, NULL);
fclose(fp);
}
감사합니다! 타르와 같은 대답이지만 좀 더 심오합니다. 두 좋은 대답! 그리고 '렌더링 글꼴'섹션에서 일어나는 segfault를 알아 내려고했습니다. 어떤 아이디어? :-) –