using System;
using System.Drawing;
public class ImageFinder
{
public static Point FindImageByColor(Bitmap screen, Color targetColor, int tolerance = 10)
{
for (int y = 0; y < screen.Height; y++)
{
for (int x = 0; x < screen.Width; x++)
{
Color pixel = screen.GetPixel(x, y);
if (Math.Abs(pixel.R - targetColor.R) < tolerance &&
Math.Abs(pixel.G - targetColor.G) < tolerance &&
Math.Abs(pixel.B - targetColor.B) < tolerance)
{
return new Point(x, y);
}
}
}
return Point.Empty;
}
}
using System;
using System.Drawing;
public class TemplateMatcher
{
public static Point MatchTemplate(Bitmap source, Bitmap template)
{
int bestX = 0, bestY = 0;
double minDiff = double.MaxValue;
for (int y = 0; y <= source.Height - template.Height; y++)
{
for (int x = 0; x <= source.Width - template.Width; x++)
{
double diff = CalculateDifference(source, template, x, y);
if (diff < minDiff)
{
minDiff = diff;
bestX = x;
bestY = y;
}
}
}
return new Point(bestX, bestY);
}
private static double CalculateDifference(Bitmap source, Bitmap template, int x, int y)
{
double diff = 0;
for (int ty = 0; ty < template.Height; ty++)
{
for (int tx = 0; tx < template.Width; tx++)
{
Color sc = source.GetPixel(x + tx, y + ty);
Color tc = template.GetPixel(tx, ty);
diff += Math.Abs(sc.R - tc.R) + Math.Abs(sc.G - tc.G) + Math.Abs(sc.B - tc.B);
}
}
return diff;
}
}
using System;
using Tesseract;
public class OCRReader
{
public static string ReadText(string imagePath)
{
using (var engine = new TesseractEngine("./tessdata", "chi_sim", EngineMode.Default))
{
using (var img = Pix.LoadFromFile(imagePath))
{
using (var page = engine.Process(img))
{
return page.GetText();
}
}
}
}
public static string ReadText(Bitmap bitmap)
{
using (var engine = new TesseractEngine("./tessdata", "chi_sim", EngineMode.Default))
{
using (var pix = PixConverter.ToPix(bitmap))
{
using (var page = engine.Process(pix))
{
return page.GetText();
}
}
}
}
}
using System;
using System.Collections.Generic;
namespace Example
{
public class Calculator
{
private readonly List _numbers = new List();
public void AddNumber(int number)
{
_numbers.Add(number);
}
public int Sum()
{
int total = 0;
foreach (var num in _numbers)
{
total += num;
}
return total;
}
public static void Main()
{
var calc = new Calculator();
calc.AddNumber(10);
calc.AddNumber(20);
Console.WriteLine($"Sum: {calc.Sum()}");
}
}
}
class User {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
return `Hello, my name is ${this.name}`;
}
static isAdult(age) {
return age >= 18;
}
}
const user = new User('Alice', 25);
console.log(user.greet());
console.log(User.isAdult(user.age));
#include <iostream>
#include <vector>
#include <algorithm>
template <typename T>
class Calculator {
private:
std::vector<T> numbers;
public:
void addNumber(T num) {
numbers.push_back(num);
}
T sum() const {
T total = 0;
for (const auto& num : numbers) {
total += num;
}
return total;
}
double average() const {
if (numbers.empty()) return 0;
return static_cast<double>(sum()) / numbers.size();
}
};
int main() {
Calculator<int> calc;
calc.addNumber(10);
calc.addNumber(20);
calc.addNumber(30);
std::cout << "Sum: " << calc.sum() << std::endl;
std::cout << "Average: " << calc.average() << std::endl;
return 0;
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>示例页面</title>
</head>
<body>
<div class="container">
<h1>欢迎访问</h1>
<p class="lead">这是一个段落</p>
</div>
</body>
</html>
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.card {
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
transition: transform 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
}
.text-center {
text-align: center;
}
@media (max-width: 768px) {
.container {
padding: 10px;
}
}
using System;
public class SortAlgorithms
{
public static void QuickSort(int[] arr)
{
QuickSort(arr, 0, arr.Length - 1);
}
private static void QuickSort(int[] arr, int low, int high)
{
if (low < high)
{
int pivot = Partition(arr, low, high);
QuickSort(arr, low, pivot - 1);
QuickSort(arr, pivot + 1, high);
}
}
private static int Partition(int[] arr, int low, int high)
{
int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++)
{
if (arr[j] <= pivot)
{
i++;
Swap(arr, i, j);
}
}
Swap(arr, i + 1, high);
return i + 1;
}
private static void Swap(int[] arr, int i, int j)
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
using System;
public class SearchAlgorithms
{
public static int BinarySearch(int[] arr, int target)
{
int left = 0;
int right = arr.Length - 1;
while (left <= right)
{
int mid = left + (right - left) / 2;
if (arr[mid] == target)
return mid;
if (arr[mid] < target)
left = mid + 1;
else
right = mid - 1;
}
return -1;
}
public static int LinearSearch(int[] arr, int target)
{
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == target)
return i;
}
return -1;
}
}