Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save specific part of image

Status
Not open for further replies.

soulow

Programmer
Jan 23, 2011
4
BG
Hello, I have a problem.
I load image, I am doing something with this image, and after that I want to save only specific part of the image, from the beginning to specific point(for example Width = 600 Height=60).
how can i do it?
 
Hope this helps.

This code should do the trick:

Code:
	Graphics::TBitmap *bmpOriginalImage, *bmpPartOfImage = new Graphics::TBitmap;
	TRect rectPartOfOriginalImage, rectNewImage;

	rectPartOfOriginalImage.Top = iTopEdgeOfCroppedImage;
	rectPartOfOriginalImage.Left = iLeftEdgeOfCroppedImage;
	rectPartOfOriginalImage.Bottom = iBottomEdgeOfCroppedImage;
	rectPartOfOriginalImage.Right = iRightEdgeOfCroppedImage;

	bmpPartOfImage->Width = rectPartOfOriginalImage.Right - rectPartOfOriginalImage.Left;
	bmpPartOfImage->Height = rectPartOfOriginalImage.Bottom - rectPartOfOriginalImage.Top;
	rectNewImage.Top = 0;
	rectNewImage.Left = 0;
	rectNewImage.Bottom = bmpCroppedImage->Height;
	rectNewImage.right = bmpCroppedImage->Width;

	bmpPartOfImage->Canvas->CopyRect(rectNewImage, bmpOriginalImage->Canvas, rectPartOfOriginalImage);
	delete bmpOriginalImage;
	delete bmpPartOfImage;
iTopEdgeOfCroppedImage, iLeftEdgeOfCroppedImage, iBottomEdgeOfCroppedImage, and iRightEdgeOfCroppedImage represent the physical edges of the area you wish to copy.

Steve.
 
thank you, but I am having problem, cause I am using TImage, can I convert TImage to TBitmap?
because i am drawing something on the TIimage image and when CopyRect the canvas, only the pictures is copied without the drawing
 
TPicture, which is a member of TImage, contains a TBitmap:

Code:
Image1->Picture->Bitmap->CopyRect(...);

Steve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top