XF and associated OC code to crop an image embedded in a cell


Version: 2026

Type: Features

Category: Programming

Subcategory: Origin C

Jira: ORG-30878


Example:

1.Insert an image into the first cell of active Worksheet.

2.Run following OC codes.

#include <Origin.h>
#include <../OriginLab/opencv.h>
void test_crop()
{
	Worksheet wks = Project.ActiveLayer();
	if (wks) {
		ocvMat mat;
		if (wks.GetAttachedPicture(0,0,mat)) {
		RECT rect;
		rect.left = rect.top = 0;
		rect.right = mat.cols / 2;
		rect.bottom = mat.rows / 2;
		mat.Crop(rect);
		wks.SetAttachedPicture(0,0,mat);
		wks.GetPage().Refresh();
		}
	}
}