|
Вопрос # 1 388/ вопрос открыт / |
|
Здравствуйте!
У меня такой вопрос. Пишу програму и мне нужно что бы грузилось кактинка из dll а потом можно было ее поворачивать и самое главое растяговать
 |
Вопрос задал: Yura (статус: Посетитель)
Вопрос отправлен: 1 марта 2008, 23:15
Состояние вопроса: открыт, ответов: 2.
|
Ответ #1. Отвечает эксперт: Вадим К
Здравствуйте, Yura!
Итак, первым долгом нужно положить изображение в dll - это можно сделать например с помощью ресурсов.
здесь http://www.programmersclub.ru/simply-art-resursi/ есть пример как положить картинку в ресурс, как её отудова загрузить и отобразить.
можно и ещё здесь почитать http://articles.org.ru/docum/resurs.php и здесь http://oblivioncoders.net/2007/11/21/zagruzka-iz-res-fajla/
Теперь, когда картинка уже в Image, растянуть её очень просто - достаточно установить свойство Streach равным True. С поворотами немного сложнее. Вот здесь есть пример и исходники библиотечки для разворота изображения
http://www.sql.ru/forum/actualthread.aspx?tid=42227
P.S. Стараемся писать грамотно.
 |
Ответ отправил: Вадим К (статус: Академик)
Время отправки: 2 марта 2008, 14:18
|
Ответ #2. Отвечает эксперт: Feniks
Здравствуйте, Yura!
За грамотность и формулировку вопроса ставлю -1 ! Уважаемый, мы ведь тут не телепаты. Знаете пословицу: "Каков вопрос, таков и ответ" ? Поэтому, на свое усмотрение, даю вам несколько примеров в Приложении.
Приложение: Переключить в обычный режим-
- {
- This function resizes a bitmap calculating the average color of a rectangular
- area of pixels from source bitmap to a pixel or a rectangular area to target
- bitmap.
-
- It produces a soft-color and undistorsioned result image unlike the StretchDraw
- method
-
- I think that this method have a tenichal name, but I am not sure.
-
- As you can see, this function could be very optimized :p
- }
-
- procedure TFormConvertir.ResizeBitmap(imgo, imgd: TBitmap; nw, nh: Integer);
- var
- xini, xfi, yini, yfi, saltx, salty: single;
- x, y, px, py, tpix: integer;
- PixelColor: TColor;
- r, g, b: longint;
-
- function MyRound(const X: Double): Integer;
- begin
- Result := Trunc(x);
- if Frac(x) >= 0.5 then
- if x >= 0 then Result := Result + 1
- else
- Result := Result - 1;
- // Result := Trunc(X + (-2 * Ord(X < 0) + 1) * 0.5);
- end;
-
- begin
- // Set target size
-
- imgd.Width := nw;
- imgd.Height := nh;
-
- // Calcs width & height of every area of pixels of the source bitmap
-
- saltx := imgo.Width / nw;
- salty := imgo.Height / nh;
-
-
- yfi := 0;
- for y := 0 to nh - 1 do
- begin
- // Set the initial and final Y coordinate of a pixel area
-
- yini := yfi;
- yfi := yini + salty;
- if yfi >= imgo.Height then yfi := imgo.Height - 1;
-
- xfi := 0;
- for x := 0 to nw - 1 do
- begin
- // Set the inital and final X coordinate of a pixel area
-
- xini := xfi;
- xfi := xini + saltx;
- if xfi >= imgo.Width then xfi := imgo.Width - 1;
-
-
- // This loop calcs del average result color of a pixel area
- // of the imaginary grid
-
- r := 0;
- g := 0;
- b := 0;
- tpix := 0;
-
- for py := MyRound(yini) to MyRound(yfi) do
- begin
- for px := MyRound(xini) to MyRound(xfi) do
- begin
- Inc(tpix);
- PixelColor := ColorToRGB(imgo.Canvas.Pixels[px, py]);
- r := r + GetRValue(PixelColor);
- g := g + GetGValue(PixelColor);
- b := b + GetBValue(PixelColor);
- end;
- end;
-
- // Draws the result pixel
-
- imgd.Canvas.Pixels[x, y] :=
- rgb(MyRound(r / tpix),
- MyRound(g / tpix),
- MyRound(b / tpix)
- );
- end;
- end;
- end;
- ----------------------------------------------------
-
- // This function stretches a bitmap with specified number of pixels
- // in horizontal, vertical dimension
- // Example Call : ResizeBmp(Image1.Picture.Bitmap , 200 , 200);
-
- function TForm1.ResizeBmp(bitmp: TBitmap; wid, hei: Integer): Boolean;
- var
- TmpBmp: TBitmap;
- ARect: TRect;
- begin
- Result := False;
- try
- TmpBmp := TBitmap.Create;
- try
- TmpBmp.Width := wid;
- TmpBmp.Height := hei;
- ARect := Rect(0,0, wid, hei);
- TmpBmp.Canvas.StretchDraw(ARect, Bitmp);
- bitmp.Assign(TmpBmp);
- finally
- TmpBmp.Free;
- end;
- Result := True;
- except
- Result := False;
- end;
- end;
-
- ----------------------------------------------------
-
-
-
-
-
-
- x = xo + r * cos(alpha + beta)
- y = yo + r * sin(alpha + beta)
-
-
-
-
-
-
-
- uses Math;
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- bm, bm1: TBitMap;
- x, y: integer;
- r, a: single;
- xo, yo: integer;
- s, c: extended;
- begin
- bm := TBitMap.Create;
- bm.LoadFromFile('ex.bmp');
- xo := bm.Width div 2;
- yo := bm.Height div 2;
- bm1 := TBitMap.Create;
- bm1.Width := bm.Width;
- bm1.Height := bm.Height;
- a := 0;
- repeat
- for y := 0 to bm.Height - 1 do begin
- for x := 0 to bm.Width - 1 do begin
- r := sqrt(sqr(x - xo) + sqr(y - yo));
- SinCos(a + arctan2((y - yo), (x - xo)), s, c);
- bm1.Canvas.Pixels[x,y] := bm.Canvas.Pixels[
- round(xo + r * c), round(yo + r * s)];
- end;
- Application.ProcessMessages;
- end;
- Form1.Canvas.Draw(xo, yo, bm1);
- a := a + 0.05;
- Application.ProcessMessages;
- until Form1.Tag <> 0;
- bm.Destroy;
- bm1.Destroy;
- end;
-
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- Form1.Tag := 1;
- end;
 |
Ответ отправил: Feniks (статус: Бакалавр)
Время отправки: 3 марта 2008, 13:03
|
Мини-форум вопроса
Мини-форум пуст.
Чтобы оставлять сообщения в мини-форумах, Вы должны авторизироваться на сайте.
|