## Problem with crop image with fix W/H

Please discuss general Delphi programming topics here.

### Problem with crop image with fix W/H

Delphi 3
Form1 = main program
JPEGImage1: TJPEGImage; //Handel the jpeg image.
ScrollBox1: TScrollBox; // handel big jpeg image.
OpenDialog1: TOpenDialog; //Dialog for load the jpeg file.

Form2 = Preview windows
Image1:Timage

This code in the Unit1.pas at procedure TForm1.JPEGImage1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
Code: Select all
 For addX:=1 to 95 do Begin  For addY:=1 to 67 do  Begin   Form2.Image1.Canvas.Pixels[addX, addY] := Form1.JPEGImage1.Canvas.Pixels[ziX+addX,ziY+addY];  End; End;

This programcode works but not as good I want it to, what can I do for a better code?
Attachments
Unit2.pas
Unit1.pas
lgrfbs
Member

Posts: 3
Joined: September 11th, 2011, 1:58 pm

### Re: Problem with crop image with fix W/H

Convert your JPEG image to bitmap (by assigning it to a bitmap), then use CopyRect method of canvas to crop the image.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

### Re: Problem with crop image with fix W/H

I will try it soon.
The "JPEGImage1" is a component as load jpeg file and is based on the timage, shall I remove this and draw direct on a cavans insted?
lgrfbs
Member

Posts: 3
Joined: September 11th, 2011, 1:58 pm

### Re: Problem with crop image with fix W/H

If you draw the image on canvas, it would be easier for you to use CopyRect method.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

### Re: Problem with crop image with fix W/H

Sorry for the late answer, I are in professional training for my real work.
I have try to do as you say, the new is in the zip file.

The is 3 things I want to fix:
* Then I move the mouse over the big images and the crop preview window do real update.
* The output crop images shall be in 256 colour and bmp-format.
* Remove the for-code in the procedure TForm1.JPEGImage1Click(Sender: TObject); for the preview window.

I can not write graphics code in delphi as good I want.
Attachments
A.zip
2011-09-25: Some new code.