api-issue-tracker
api-issue-tracker copied to clipboard
The SUStylesMoveStyle function cannot delete a specified style, and the image obtained by the SUStyledThumbnail function is only 1kb
char* c_file_path = RSTRING_PTR(file_path);
char* c_thumbnail_dir = RSTRING_PTR(thumbnail_path);
SUModelRef model = SU_INVALID;
SUResult res = SUModelCreateFromFile(&model, c_file_path);
if (res != SU_ERROR_NONE) {
rb_raise(rb_eRuntimeError, "Failed to create a new model");
}
SUStylesRef styles;
SUModelGetStyles(model, &styles);
size_t style_count = 0;
SUStylesGetNumStyles(styles, &style_count);
SUStyleRef* style_array = (SUStyleRef*)malloc(sizeof(SUStyleRef) * style_count);
if (style_array == NULL) {
return EXIT_FAILURE;
}
size_t count = 0;
SUStylesGetStyles(styles, style_count+1, style_array, &count);
for (size_t i = 0; i < count; ++i) {
SUImageRepRef thumbnail = SU_INVALID;
SUImageRepCreate(&thumbnail);
SUResult thumbnail_result = SUStyleGetThumbnail(style_array[i], &thumbnail);
if (thumbnail_result == SU_ERROR_NONE) {
SUImageRepConvertTo32BitsPerPixel(thumbnail);
char filename[256];
snprintf(filename, sizeof(filename), "thumbnail_%04zu.jpg", i);
char full_path[512];
snprintf(full_path, sizeof(full_path), "%s\\%s", c_thumbnail_dir, filename);
thumbnail_result = SUImageRepSaveToFile(thumbnail, full_path);
if (thumbnail_result != SU_ERROR_NONE) {
rb_raise(rb_eRuntimeError, "Failed to save thumbnail to file: %s", full_path);
}
if (i >1)
SUStylesRemoveStyle(styles, &style_array[i]);
printf("Style %zu has a valid thumbnail.\n", i);
}
else {
printf("Style %zu does not have a valid thumbnail.\n", i);
}
SUImageRepRelease(&thumbnail);
}
for (size_t i = 0; i < count; ++i) {
if (i > 1)
SUStylesRemoveStyle(styles, &style_array[i]);
printf("Style %zu has a valid thumbnail.\n", i);
}
memset(style_array, 0, sizeof(SUStyleRef) * style_count);
free(style_array);
SUModelRelease(&model);
SUTerminate();
return Qtrue;
This is the result we have obtained so far
I hope to get a thumbnail like Sketchup