[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Reducing pixelformat from TImagelist

Posted on 2007-10-20
6
Medium Priority
?
321 Views
Last Modified: 2010-04-05
I am using Timagelist to store a series of bitmap images which are originally pf8bit.
The Timagelist takes the format of the screen (32 bit)
I want to store these images on disk in 8bit bitmap files.
However if I try to change
  ImageList1.GetBitmap(n,Bitmap3);
  Bitmap3.PixelFormat := pf8bit;
... I lose grey scales

Thanks for your help
0
Comment
Question by:diver999
  • 3
  • 3
6 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 20114505
in order to maintain pixel format, or any other information except width and height, you need to set it explicitly. see this example of a proper way to put a bitmap in an imagelist and save it back to file preserving pixelformat

procedure TForm1.FormCreate(Sender: TObject);
var b:TBitmap;
    opf:TPixelFormat;
begin
  b:=TBitmap.create;
  try
    b.LoadFromFile('c:\test.bmp');
    opf:=b.PixelFormat;
    imagelist1.Height:=b.Height;
    imagelist1.Width:=b.Width;
    imagelist1.Add(b, nil);
  finally
    freeandnil(b);
  end;
  b:=TBitmap.Create;
  try
    b.PixelFormat:=opf;
    imagelist1.GetBitmap(0, b);
    b.SaveToFile('c:\test_.bmp');
  finally
    freeandnil(b);
  end;
end;
0
 

Author Comment

by:diver999
ID: 20114975
Thanks for the input.  <test.bmp> is 8 bit grey scale bitmap.   Display resolution is 32bit
Please look at this :
procedure TForm1.FormCreate(Sender: TObject);
var b:TBitmap;
    opf:TPixelFormat;
begin
  b:=TBitmap.create;
  try
    b.LoadFromFile('c:\test.bmp');
    opf:=b.PixelFormat;
    imagelist1.Height:=b.Height;
    imagelist1.Width:=b.Width;
    imagelist1.Add(b, nil);
  finally
    freeandnil(b);
  end;
  b:=TBitmap.Create;
  try
    b.LoadFromFile('c:\test.bmp');   //this must have the original pf
    imagelist1.GetBitmap(0, b);       //if I omit this line, test_.bmp is as test.bmp
    b.SaveToFile('c:\test_.bmp');    //if from imagelist, only one in 4 grey scales present
  finally
    freeandnil(b);
  end;
end
0
 

Author Comment

by:diver999
ID: 20114976
sorry - that should have been 1 in 8 grey scales...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 28

Expert Comment

by:2266180
ID: 20115298
well, if you look in the imagelist sources, you will notice that when you "get" a bitmpat, a new one is created and the old one is drawn onto the new one. which makes a lot of information to be lost.

so, why do you need to put the imabe in the imagelist and then save it back again? maybe there is a better solution, so give me more details on what you are trying to acomplish.
0
 

Author Comment

by:diver999
ID: 20115355
The original 8-bit bitmap is not loaded from a file - it is read in from an image acquisition card as part of an automatic image processing system.
Images are processed and some of them are stored in the imagelist
The user may then choose to save the images from the imagelist to a series of .bmp files.
Sometime later he may want to re-examine them by reading them back  into the bitmap object.
The grey scale reduction seems to be occuring when an image is stored by GetBitmap from the imagelist and then SaveToFile.
I think the problem is that Timagelist stores bitmaps in screen device format and getting it into a lower res object results in data loss.  
Hope this makes sense...
0
 
LVL 28

Accepted Solution

by:
2266180 earned 600 total points
ID: 20115408
that has nothing to do with it. I explained what is happening. re-read my explanation.

I suggest you do something like this:
- add each image that you add in teh imagelist into an object list
- when you want to save the image to file, save the one from teh object list.
do the above for every case when you have a save from the image list. (in case you have more than 1 image list).

you will define the objectlist like:

objectList:TObjectList;
and create it like:
objectList:=TObjectList.create(false);

add Contnrs to the uses clause.

then use it like:

TBitmap(objectList[index]).savetofile(filename);

add to it like: objectList.add(bitmap);
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month19 days, 8 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question