Timage变白并且位图的大小为0字节 [英] Timage gets white and bitmap has size 0 bytes

查看:52
本文介绍了Timage变白并且位图的大小为0字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的TImage组件中存储了一些数据.我想将图像另存为位图.执行此代码,TImage内容变为白色,并且硬盘上仅创建了一个0字节的bmp文件.我的代码有什么问题?

I have some data stored inside my TImage Component. I want to save the image as an bitmap. Executing this code the TImage content gets white and only a bmp file with 0 bytes has been created on the harddisk. What is wrong with my code ?

  MainStatusbar.SimpleText := 'save the image .... ';
  if SaveDialog.Execute then
  begin
    Image1.picture.Bitmap.SaveToFile(SaveDialog.filename);
  end;
  MainStatusbar.SimpleText := 'done ';

推荐答案

TPicture 是用于容纳多种不同类型图像的容器.如果当前图像不是 TBitmap ,则 Picture.Bitmap 将不包含您的图像.当您引用 Picture.Bitmap 时,原始图像将被破坏,并创建一个空的 TBitmap .因此,显而易见的解释是,当调用 SaveToFile()时, Picture.Bitmap 为空.

TPicture is a container for multiple different types of images. If the current image is not a TBitmap, then Picture.Bitmap will not contain your image. When you refer to Picture.Bitmap your original image will be destroyed, and an empty TBitmap created. So, the obvious explanation in that Picture.Bitmap is empty when SaveToFile() is called.

您应该通过调用 Picture 对象上的 SaveToFile 来保存图像:

You should be saving your image by calling SaveToFile on the Picture object instead:

Image1.Picture.SaveToFile(...);

这篇关于Timage变白并且位图的大小为0字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆