- Регистрация
- 06.08.2013
- Сообщения
- 99
- Благодарностей
- 6
- Баллы
- 8
Hi,
split image into 4 equal parts :
I couldn't find any way to do it via the actions.
So I coded this script in C#
but it returns this error:
Compiling code of Error in action "CS0246" "The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)". [Row: 43; Column: 12]
Compiling code of Error in action "CS0246" "The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)". [Row: 43; Column: 38]
While I have imported System.Net 4.0
split image into 4 equal parts :

I couldn't find any way to do it via the actions.
So I coded this script in C#
ImageDivider:
string imageURL = project.Variables["imageURL"].Value;
string SaveImagePath = project.Variables["SaveImagePath"].Value;
void DivideAndSaveImage()
{
if (string.IsNullOrEmpty(imageURL))
{
project.SendInfoToLog("The image URL cannot be empty", "Error in imageURL");
return;
}
string outputDirectory = Path.Combine(SaveImagePath, "images");
if (!Directory.Exists(outputDirectory))
{
Directory.CreateDirectory(outputDirectory);
}
using (Image image = DownloadImageFromUrl(imageURL))
{
int width = image.Width / 2;
int height = image.Height / 2;
Rectangle[] sections =
{
new Rectangle(0, 0, width, height),
new Rectangle(width, 0, width, height),
new Rectangle(0, height, width, height),
new Rectangle(width, height, width, height)
};
for (int i = 0; i < sections.Length; i++)
{
string savePath = Path.Combine(outputDirectory, $"part{i + 1}.jpg");
SaveImageSection(image, sections[i], savePath);
}
}
}
Image DownloadImageFromUrl(string imageUrl)
{
Image image;
using (WebClient webClient = new WebClient())
{
byte[] imageBytes = webClient.DownloadData(imageUrl);
using (MemoryStream memoryStream = new MemoryStream(imageBytes))
{
image = Image.FromStream(memoryStream);
}
}
return image;
}
void SaveImageSection(Image image, Rectangle rect, string savePath)
{
using (Bitmap bmp = new Bitmap(rect.Width, rect.Height))
{
using (Graphics g = Graphics.FromImage(bmp))
{
g.DrawImage(image, 0, 0, rect, GraphicsUnit.Pixel);
}
bmp.Save(savePath);
}
}
but it returns this error:
Compiling code of Error in action "CS0246" "The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)". [Row: 43; Column: 12]
Compiling code of Error in action "CS0246" "The type or namespace name 'WebClient' could not be found (are you missing a using directive or an assembly reference?)". [Row: 43; Column: 38]
While I have imported System.Net 4.0

