Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Центр помощи > [Delphi] Работа с TImage в TImageList


Автор: Deiv 5.11.2006, 17:19
Привет,  
Для не записи несколько изображениx (images) в диске, я решил записать единственный образ 128x640 pixels (где одно букбa тянется каждое 64 pixels в 2x линиях [10 букб выше и 10 букб ниже] кажды/64 pixels) нагружая это с TIMAGELIST'om (как будто это казалось матрицей 10x2) Мой Образ имеет БЕЛОЕ дно.
_________________________________________
| A | B | C | D | E  | F  | G | H | I  | J |
| K | L | M | N | O | P  | Q | R | S  | T |
------------------------------------------

Со следующим кодoм я положу индекс:
Код

procedure TForm1.Button1Click(Sender: TObject);
var
  i,j: integer;
begin
  for i:= 0 to 9 do
    for j:= 0 to 1 do
      Imagelist1.Draw(PaintBox1.Canvas,i*50,j*50,i+(j*10));
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Bitmap, Clip: TBitmap;
begin
  Bitmap:= TBitmap.Create;
  Clip:= TBitmap.Create;
  try
    Bitmap.LoadFromFile('D:\File.bmp');
    ImageList1.Clear;
    ImageList1.Width:= Bitmap.Width div 10;
    ImageList1.Height:= Bitmap.Height div 2;
    Clip.Width:= Bitmap.Width;
    Clip.Height:= Bitmap.Height div 2;
    Clip.Canvas.CopyRect(Recorte.Canvas.ClipRect,
      Bitmap.Canvas,Rect(0,0,Bitmap.Width,Bitmap.Height div 2));
    Imagelist1.AddMasked(Clip, Clip.Canvas.Pixels[0,0]);
    Clip.Canvas.CopyRect(Clip.Canvas.ClipRect,
      Bitmap.Canvas,Rect(0,Bitmap.Height div 2,Bitmap.Width,Bitmap.Height));
    Imagelist1.AddMasked(Clip, Clip.Canvas.Pixels[0,0]);
  finally
    Bitmap.Free;
    Clip.Free;
  end;
end;


Как сделать ту же работу в Timage?Я попробывал c:
    ImageList1.BkColor:=clNone;
    ImageList1.BlendColor:= clNone;
    ImageList1.DrawingStyle:= dsTransparent;
    ImageList1.Masked:= True;
И,

   Image1.Transparent:=true;
   BitMap.TransparentColor:=BitMap.Canvas.Pixels[0,0];  //white bottom
   BitMap.Transparent:= True;
   BitMap.TransparentMode:= tmFixed;


И Я не  получаю прозрачную частью BitMap'a в TImage

Тянучи, Как я могу показать индекс например 15 [5,1] 5+ (1*10) =15 ПРОЗРАЧНЫЙ TImageList'a в TImage?





Hello,  
For to avoid and save several images in disk, I decided to save a single image of 128x640 pixels (where a Letter is drawn each 64 pixels in 2 lines [10 letters above and 10 letters below] each/64 pixels) that I load it with a TImageList (as if it seemed a matrix of 10x2) My Image has WHITE bottom  
                      _________________________________________
                     | A | B | C | D | E | F  | G | H | I  | J |
                     | K | L | M | N | O | P  | Q | R | S  | T |
                      ------------------------------------------

With the following code position an index:
Код

procedure TForm1.Button1Click(Sender: TObject);
var
  i,j: integer;
begin
  for i:= 0 to 9 do
    for j:= 0 to 1 do
      Imagelist1.Draw(PaintBox1.Canvas,i*50,j*50,i+(j*10));
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  Bitmap, Clip: TBitmap;
begin
  Bitmap:= TBitmap.Create;
  Clip:= TBitmap.Create;
  try
    Bitmap.LoadFromFile('D:\File.bmp');
    ImageList1.Clear;
    ImageList1.Width:= Bitmap.Width div 10;
    ImageList1.Height:= Bitmap.Height div 2;
    Clip.Width:= Bitmap.Width;
    Clip.Height:= Bitmap.Height div 2;
    Clip.Canvas.CopyRect(Recorte.Canvas.ClipRect,
      Bitmap.Canvas,Rect(0,0,Bitmap.Width,Bitmap.Height div 2));
    Imagelist1.AddMasked(Clip, Clip.Canvas.Pixels[0,0]);
    Clip.Canvas.CopyRect(Clip.Canvas.ClipRect,
      Bitmap.Canvas,Rect(0,Bitmap.Height div 2,Bitmap.Width,Bitmap.Height));
    Imagelist1.AddMasked(Clip, Clip.Canvas.Pixels[0,0]);
  finally
    Bitmap.Free;
    Clip.Free;
  end;
end;


How to make the same work in a Timage?

I have proven with
    ImageList1.BkColor:=clNone;
    ImageList1.BlendColor:= clNone;
    ImageList1.DrawingStyle:= dsTransparent;
    ImageList1.Masked:= True;
and,

   Image1.Transparent:=true;
   BitMap.TransparentColor:=BitMap.Canvas.Pixels[0,0];  //white bottom
   BitMap.Transparent:= True;
   BitMap.TransparentMode:= tmFixed;

And I don't get the transparent of a part of the BitMap in a TImage

When drawing, How I show the index for example 15 [5,1] 5+(1*10)=15 TRANSPARENT of the TImageList in a TImage?


Автор: Alexeis 6.11.2006, 01:39
Deiv, I сan`t understand what вщ you need to do....
 To copy an image from a bitmap to TImage you should simply assign it to TImage.

Код

var
 bitmap : TBitmap;
begin
  Image1.Picture.Bitmap.Assign(bitmap);


To get only tranparent part, you must use WINAPI function AlphaBlend.
It combines two DCs with transparency

Here is an example (by Snowy) which combines two bitmaps with transparency.
Код

procedure TForm1.Button1Click(Sender: TObject);    
var    
  bmp1, bmp2: TBitMap;    
  Blend: TBlendFunction;    
begin    
  bmp1 := TBitMap.Create;    
  bmp2 := TBitMap.Create;    
  bmp1.LoadFromFile('C:\1.bmp'); 
  bmp2.LoadFromFile('C:\2.bmp'); 
  bmp1.PixelFormat := pf32bit; 
  bmp2.PixelFormat := pf32bit;    
  Blend.BlendOp := AC_SRC_OVER;    //You must prepare special structure 
  Blend.BlendFlags := 0;    
  Blend.SourceConstantAlpha := 128; // transparency 50% (0 - 255)    
  Blend.AlphaFormat := AC_SRC_ALPHA;    
 
  if Windows.AlphaBlend(bmp1.Canvas.Handle, 0, 0, bmp1.Width, bmp1.Height,    
                        bmp2.Canvas.Handle, 0, 0, bmp2.Width, bmp2.Height, Blend) // this function combines two bitmaps.
  then    
     Canvas.Draw(0, 0, bmp1) //draws result bitmap on the Form
    
  else 
     ShowMessage(IntToStr(GetLastError)); 

  bmp1.Free; 
  bmp2.Free; 
end;


p.s. Don`t use Promt to translate from English into Russian. It does it badly. Nobody ever can understand these sentences. smile 


Автор: Deiv 6.11.2006, 16:23
Спасибо, мой вопрос был :
Как сделать ту же работу в Timage?
How to make the same work in a Timage?

QUOTE: Here is an example (from Snowy) which combines two bitmaps with transparency.
не нужно комбинировать  (Dont' need to combine)

Мой код показывает часть от BitMap'a   в  TPaintBox'e, мне нужно делать то же самое, но в TImage (прозрачной) с TImagelist'oм (Изменять мой код TPaintBox'a   к  TImage).

My code shows a part of the BitMap in a TPaintBox, I need to do the same but in a TImage (transparent)  with TImagelist.

Автор: Alexeis 6.11.2006, 18:15
Цитата(Deiv @  6.11.2006,  16:23 Найти цитируемый пост)
I need to do the same but in a TImage (transparent)  with TImagelist.

Like TPaintBox has, TImage also has a canvas. You can use Image1.Canvas instead of PaintBox1.Canvas.

It seems to me that you already know this but Image1.Canvas doesn`t works as indeed, does it?


Автор: Deiv 7.11.2006, 02:27
Я подумал нужно было только изменить
Код

ImageList1.Draw(PaintBox1.Canvas,0,0,15)
за
Код

ImageList1.Draw(Image1.Canvas,0,0,15)

чтобы показать тот кусок [15], но это не показывает мне прозрачному.  
  
Мне нужно только переводить мой Код из TPaintBox к TImage и показал мне прозрачному. Как я могу это сделать?

I thought alone it would be to change with ImageList1.Draw(PaintBox1.Canvas,0,0,15)   x   ImageList1.Draw(Image1.Canvas,0,0,15) for to show that piece [15], but it doesn't show me transparent.  
I only need help in to translate my Code from a TPaintBox to a TImage and it also shows me transparent. How can I make that?

Автор: Alexeis 7.11.2006, 03:03
Цитата(Deiv @  7.11.2006,  02:27 Найти цитируемый пост)
I only need help in to translate my Code from a TPaintBox to a TImage and it also shows me transparent. How can I make that?


TPaintBox is just a DC, but TImage is a storage for picture. 
May be you need to convert internal TImage bitmap in to 32bit/color as TPaintBox has.

Image1.picture.bitmap.PixelFormat := pf32bit; 
//default is pfDevice

Or you can combine two images Image1.picture.bitmap.canvas and Image received with ImageList1.GetBitmap() (With function AlphaBlend)

Result Canvas will be TImage canvas. 
It will give you same result as ImageList1.Draw(PaintBox1.Canvas,0,0,15)
I checked this method. It works well.

Автор: Deiv 9.11.2006, 22:03
Я проверил код и работает очень хорошо c TTimer'om, спасибо. Сейчас у меня два вопроса:  
  
Нагружая программу, TIMAGE показывает мне белый цвет в TFORM:  
Код

    Image1.Picture.Bitmap.PixelFormat      := pf32bit;
    Image1.Picture.Bitmap.Transparent      := True;
    Image1.Picture.Bitmap.TransparentColor := clWhite; 
    Image1.Transparent   := True; //Этот код работает позже
    Form1.DoubleBuffered := True;
   
Когда я нагружаю с кнопкой:  
Код

   Image1.picture.bitmap.PixelFormat := pf32bit;
   Image1.picture.bitmap.canvas;
   ImageList1.GetBitmap(0,Image1.Picture.Bitmap); 

также показывает мне часть bitmap'a с белым дном  

1.- Могу ли показать нагружая мою программу бездонную TImage (прозрачный)? значит без белого цвета?, и Так же со click'oм кнопки "Load Part of BitMap" TImage может показать мне непосредственно (прямо) прозрачному?  

2.- Alexei Вы проверили другой Bitmap? Почему TImageList не поддерживает bitmaps 32 bits'a?


I have checked the code and it works very well with TTimer, thank you. Now I have two questions:  
  
When loading the program, TImage shows me a white color in the TForm:  
Код

    Image1.Picture.Bitmap.PixelFormat      := pf32bit;
    Image1.Picture.Bitmap.Transparent      := True;
    Image1.Picture.Bitmap.TransparentColor := clWhite;
    Image1.Transparent   := True; //This code works later
    Form1.DoubleBuffered := True;
 

When I load with the button:
Код

   Image1.picture.bitmap.PixelFormat := pf32bit;
   Image1.picture.bitmap.canvas;
   ImageList1.GetBitmap(0,Image1.Picture.Bitmap);

  
It also shows me the part of the BitMap with white bottom  
  
1.- Can I show when loading my program a bottomless TImage (transparent)? that is to say without any color?, likewise to the click of the button "Load Part of BitMap" could the TIMage show me directly transparent?
  
2.- Alexei Have you checked the other BitMap? Why doesn't TImageList support bitmaps of 32 bits?





Автор: Alexeis 9.11.2006, 22:54
Цитата(Deiv @  9.11.2006,  22:03 Найти цитируемый пост)
1.- Can I show when loading my program a bottomless TImage (transparent)? that is to say without any color?, likewise to the click of the button "Load Part of BitMap" could the TIMage show me directly transparent?

You need to fill alpha channel with 255 and 0 s. Zero for transparent fields and 255 for not transparent fields.
This binary mask can help you draw correct transparensity. Then you made so, you can use funtion alphablend to draw transparent fields witch are filled with various color.

Цитата(Deiv @  9.11.2006,  22:03 Найти цитируемый пост)
Why doesn't TImageList support bitmaps of 32 bits?

TImageList supports addition of binary mask. It can be used for transparensy.
function Add(Image, Mask: TBitmap): Integer;//see help for more information

Цитата(Deiv @  9.11.2006,  22:03 Найти цитируемый пост)
Alexei Have you checked the other BitMap

No, I checked only initial settings.

Автор: Deiv 10.11.2006, 02:19
Thanks, I solved it in the following way:
Код

    Image1.Transparent   := True;
    Image1.Picture.Bitmap.TransparentMode:= tmFixed;

    Image1.Picture.Bitmap.Width            := Image1.ClientWidth;
    Image1.Picture.Bitmap.Height           := Image1.ClientHeight;
    Image1.Picture.Bitmap.PixelFormat      := pf32bit;
    Image1.Picture.Bitmap.Transparent      := True;
    Image1.Picture.Bitmap.TransparentColor := clWhite;
    Form1.DoubleBuffered := True;

Only he stays to know about the bitmap of 32 bits ('Metals2.bmp'=32 bits)

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)