..
You can set the PixelFormat to pf8bit but the result may not be good.
If you need higher quality, you'll have to create an optimized palette.
For this, use the GifImage lib written by Anders Melander and modified
by Finn Tolderlund to fix compatibility issues with Delphi 6 and 7.
It can be downloaded from Finn's site:
http://home20.inet.tele.dk/tolderlund/delphi/
http://finn.mobilixnet.dk/delphi/
//-----------------------------------------------
uses
GIFImage;
procedure TForm1.Button1Click(Sender: TObject);
var
BMP1,BMP2 : TBitmap;
begin
BMP1 := TBitmap.Create;
try
BMP1.LoadFromFile('24bit.bmp');
if (BMP1.PixelFormat > pf8bit)
then begin
BMP2 := ReduceColors(BMP1,rmQuantizeWindows,dmNearest,8,0)
try
//Do whatever you need with BMP2
BMP2.SaveToFile('8bit.bmp');
finally
BMP2.Free;
end;
end
else ShowMessage('Image already 8bit or less');
finally
BMP1.Free;
end;
end;
//-----------------------------------------------
HTH,
Ronaldo
My Image control just gets text printed on it. It doesn't
load any pictures, or even uses them.
The control itself needs to be set, not the picture within it.
> The control itself needs to be set, not the picture within it.
Are you saving the image to file?
Please show us some code.
Ronaldo
You cannot change the pixel format of a control. You can only change the
pixel format of a bitmap, which might be displayed by some control like
a TImage. If your TImage does display a bitmap, simply change its pixel
format. But it's hard to tell you more without seeing some code or a
better explaination what you're trying to do, especially since what you
want to do looks a bit strange to me. Why would you want to do this? And
isn't there a better way to print text to a control than using a TImage?
Jens
--
Jens Gruschel
http://www.pegtop.net
The problem is, the Delphi Image control takes on the resolution
that Windows is set in. Lowering it from 32 to 16 bit is
much helpful. 256 color might also be useful if text
still looks good. since it's a bitmap, graphics can go
anywhere quickly. The text is also scrollable easily without
all the hard work when a Image control is within a scrollable
form.
with Form1.Image1.canvas do begin
font.name := Settings.LongFontUsed;
font.size := Settings.LongFontSize;
font.color := clwhite;
brush.style := bssolid;
brush.color := clwhite;
TextOut(x,y, FileString[i]);
end;
> The problem is, the Delphi Image control takes on the resolution
> that Windows is set in.
No, it does not. You can set the number of colors using the
Image.Picture.Bitmap.PixelFormat. If you want 256 colors, set it to
pf8bit. Please notice that there are also the pf4bit (16 colors) and
pf1bit (2 colors) formats.
> since it's a bitmap, graphics can go anywhere quickly. The text
> is also scrollable easily without all the hard work when a Image
> control is within a scrollable form.
Another approach: keep the text in a StringList; keep a list of the
graphics and it's coordinates in a TList; create a smaller BMP (the size
of the form's ClientRect) it will work as the "current page". Use the
ScrollBox's OnChange event and the Position property to find out the
first string to be written; write them until you run out of text or the
page is filled; search the list for graphics on the current page and
draw them.
>
> with Form1.Image1.canvas do begin
> font.name := Settings.LongFontUsed;
> font.size := Settings.LongFontSize;
> font.color := clwhite;
> brush.style := bssolid;
> brush.color := clwhite;
> TextOut(x,y, FileString[i]);
> end;
Not really sure what I'm doing but I *think* this sample code using your
setup (if I undertstood it...) but controlling the number of colors. Add
a ScrollBox to a form and set it's Align property to alClient. Add an
Image inside the ScrollBox and set it's Align property to alClient. Add
an OnCreate event to the form:
procedure TForm1.FormCreate(Sender: TObject);
var
i,Y,dY : integer;
begin
Image1.Picture.Bitmap := TBitmap.Create;
Image1.Picture.Bitmap.PixelFormat := pf16bit; //pf4bit
Image1.Picture.Bitmap.Width := Image1.Width;
Image1.Picture.Bitmap.Height := 24800;
Image1.Picture.Bitmap.Canvas.Brush.Color := clBlue;
Image1.Picture.Bitmap.Canvas.FillRect(Image1.Picture.Bitmap.Canvas.ClipRect);
Image1.Picture.Bitmap.Canvas.Font.Color := clYellow;
SetBkMode(Image1.Picture.Bitmap.Canvas.Handle,TRANSPARENT);
ScrollBox1.VertScrollBar.Range := Image1.Picture.Bitmap.Height;
dY := Round(Image1.Picture.Bitmap.Canvas.TextHeight('Yy')*1.1);
Y := 0;
i := 0;
repeat
inc(i);
Image1.Picture.Bitmap.Canvas.TextOut(0,Y,IntToStr(i));//FileString[i]
inc(Y,dY);
until (Y > Image1.Picture.Bitmap.Height);
Image1.Picture.Bitmap.SaveToFile('C:\BMP256c.bmp'); //'C:\BMP16c.bmp'
end;
Please take some time to figure out if the huge bitmap approach is
really the best possible.
HTH,
Ronaldo
shoud read
Image1.Picture.Bitmap.PixelFormat := pf8bit; //pf4bit
Ronaldo