我正在根据
HPDF_LoadRawImageFromMem()
根据" eve {/code>buffer装入图像。
我的目标是能够从 我试着写给 有谁在将一个图书馆的图像数据转换为另一个图书馆方面有经验吗? 我之所以试图从记忆中做到这一点, 是因为我至今都在写 Magick : “ 图像实例进入一个文件, lese/code> 或Magick::Blob
,但我迄今唯一的成就是一些黑色矩形而不是我期待的图像。
我正在根据
HPDF_LoadRawImageFromMem()
根据" eve {/code>buffer装入图像。
我的目标是能够从 我试着写给 有谁在将一个图书馆的图像数据转换为另一个图书馆方面有经验吗? 我之所以试图从记忆中做到这一点, 是因为我至今都在写 Magick : “ 图像实例进入一个文件, lese/code> 或Magick::Blob
,但我迄今唯一的成就是一些黑色矩形而不是我期待的图像。
我回答有点迟,我想, 但这里是一个真实的答案。
我成功地添加了一个 ltk :: 使用 LibHaru 的 pdf 图像, 这样它应该对您同样有效 。 首先, 您需要知道您使用的图书馆是行主修还是列主修。 Lib Haru (和我知道的所有图书馆) 在行主修中工作, 所以您的图书馆也应该使用, 或者您需要“ 传输” 您的数据 。
// Black and white image (8 bits per pixel)
itk::Image<unsigned char, 2>::Pointer image = ...;
const unsigned char *imageData = image->GetBufferPointer();
const HPDF_Image image = HPDF_LoadRawImageFromMem(m_Document,
imageData, width, height, HPDF_CS_DEVICE_GRAY, 8);
// Or color image (24 bits per pixel, 8 bits per color component)
itk::Image<RGBPixel, 2>::Pointer image = ...;
const RGBPixel *imageData = image->GetBufferPointer();
const HPDF_Image image = HPDF_LoadRawImageFromMem(m_Document,
reinterpret_cast<const unsigned char *>(imageData),
width, height, HPDF_CS_DEVICE_RGB, 8);
// Usual LibHaru code. EndText, Position, Draw, StartText, etc.
// This code should not be dependant on the type
InsertImage(image);
我认为唯一的复杂部分是重新解释_cast。 黑白图像不需要, 因为它已经被定义为字节 。 例如, 如果您有此图像
102 255 255
99 200 0
255 0 100
imageData == {102, 255, 255, 99, 200, 0, 255, 0, 100};
但是,如果您有这种颜色的图像
( 0, 0, 255) (0, 255, 255) ( 42, 255, 242)
(200, 200, 255) (0, 199, 199) (190, 190, 190)
imageData == {0, 0, 255, 0, 255, 255, 42, 255, 242, 200, 200, 255, ... }
LibHaru之所以站得住脚,是因为你要他使用HPDF_CS_DEVICE_RGB,这意味着它将数据分组在(R、G、B)中。
当然,使用图像Magick, 您需要找到如何访问第一个像素。 它可能是一种方法, 如数据 () 、 开始 () 、 指针 () 等 。
Unfortunately I neither worked with ImageMagic nor libharu, however I have some experience with image processing and since nobody answered yet, maybe I can be of some help. The problem is probably that there is a plethora of raw image formats and I m quite sure that both libraries do not have the same understanding of these. What makes things worse is that the raw image interpretation of libharu is virtually not documented. However the conclusions that libharu handles raw data quite straightforward can be drawn from the parameters of: "HPDF_LoadRawImageFromMem". Width and Height are pretty much self-explanatory, with the only question of the used (probably pixels). More interesting is: "bits_per_component". This parameter probably describes how many bits are used to define one pixel (common values are 8: indexed from a palette of 256 values, 16: indexed from a palette of 65535 values, 24: one byte for red, green, and blue respectivly [RGB], 32: as 24 but with alpha channel or 8 bits for cyan, magenta, yellow, and black [CMYK], 36: as 32 but with 9 bit per value for easier transpostion...). A problem is the lousy documentation of the type: HPDF_ColorSpace, since it probably describes how color values of with: "bits_per_component" are to be interpreted. A totally different approach seems to be implemented by ImageMagic. An image object seems to have always an image format (JPEG, PNG, GIF), therefore an image object probably never has a "straightforward" memory representation but is encoded. My recommendation would be to switch the ImagaMagic image to the TIFF format, since it condones compression and therefore has a similar approach to the assumed raw interpretation by libharu. Hope this helped at least a bit... Cheers Mark.
回答永远不会迟到。
我用PNG的胶囊作为中间步骤:
Image image;
image.read("file.jpg");
Blob blob;
image.write(blob, "PNG");
HPDF_Image pdfImg = HPDF_LoadPngImageFromMem(doc, (const HPDF_BYTE*)blob.data(), blob.length());
HPDF_Page_DrawImage(doc, pdfImg, 0, 0, image.columns(), image.rows());
PDF 文档和页面创建的缩略语省略 。
I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...
I have been searching for sample code creating iterator for my own container, but I haven t really found a good example. I know this been asked before (Creating my own Iterators) but didn t see any ...
Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...
I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?
Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...
Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?