用C输出图像 [英] Image output in C
问题描述
快速的问题,是否有一种方法可以使用C从文件显示图像(例如bmp)?显然,它不在graphics.h中,我不能使用Allegro,因为它不支持Borland(或者我已经读过).我需要为学校项目使用非常老的编译器.我想问问是否有人有使用其他库进行此操作的经验?如果是,那是哪个图书馆?非常感谢.
Quick question, is there a way to show an image(ex. bmp) from file using C? It's not in graphics.h apparently, and I can't use Allegro because it does not support Borland(or so I've read). I need to use the very old compiler for a school project. I would like to ask if anyone had any experience of doing this using other libraries? If yes, which library was it? Thanks a lot.
推荐答案
我希望您拥有像Borland C ++ builder 3 ++或turbo C ++这样的可视(windows)borland,而不是MS DOS.在这种情况下,这很容易,因为您可以使用 VCL 中的位图,因此不需要其他包含.
I hope you have visual (windows) borland like Borland C++ builder 3++ or turbo C++ not the MS DOS one. in that case it is quite easy because you can use bitmap which is part of VCL so no additional include is needed.
- 此处,您可以找到有关在borland下渲染的一些提示
- here you can find some hints on rendering under borland
现在如何将图片从文件可视化到窗口:
now how to visualize picture from file to your window:
// this will create and load your bitmap
Graphics::TBitmap *bmp=new Graphics::TBitmap;
bmp->LoadFromFile("image.bmp");
bmp->HandleType=bmDIB;
bmp->PixelFormat=pf32bit;
// on paint you can draw your image to form,paintbox,another bitmap or whatever...
Form1->Canvas->Draw(0,0,bmp); // also you can use stretch draw or copy rectangle GDI functions
// before exiting delete the bmp
delete bmp;
[注释]
如果需要 jpg ,还可以通过bmp->SaveToFile("out.bmp");
保存图像,然后添加:
You can also save image by bmp->SaveToFile("out.bmp");
In case you need jpg then add:
#include <jpeg.hpp>
TJPEGImage *jpg=new TJPEGImage;
jpg->LoadFromFile("image.jpg");
bmp->Assign(jpg);
delete jpg;
这会将 jpg 加载到您的 bmp 中,您也可以用相同的方式保存 jpg . 提防较旧的Borlands在TJPEGImage
中存在错误,并且如果 jpg 分辨率过大会崩溃**
this will load jpg to your bmp also you can save jpg as well in the same way. Beware older Borlands has a bug in TJPEGImage
and will crash if the jpg resolution is too big**
这篇关于用C输出图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!