不知道这里只不支持WB Editor?

作者首次在优快云 Blog写作,遇到无法使用WB Editor的问题,不确定是自身原因还是优快云的问题。

第一次来优快云 Blog写点东西,可惜不能使用WB Editor,不知道是我自己的原因还是优快云的原因,不能使用。

#include "image_opration.h" // 初始化图片编辑器 ImageEditor* create_image_editor(const char* baseImagePath) { ImageEditor* editor = (ImageEditor*)malloc(sizeof(ImageEditor)); if (!editor) return NULL; // 读取基础图片 FILE* file = fopen(baseImagePath, "rb"); if (!file) { free(editor); return NULL; } BMPHeader header; BMPInfoHeader infoHeader; fread(&header, sizeof(BMPHeader), 1, file); fread(&infoHeader, sizeof(BMPInfoHeader), 1, file); editor->basePixels = (Pixel*)malloc(BASE_WIDTH * BASE_HEIGHT * sizeof(Pixel)); fseek(file, header.offset, SEEK_SET); fread(editor->basePixels, sizeof(Pixel), BASE_WIDTH * BASE_HEIGHT, file); fclose(file); editor->count = 0; pthread_mutex_init(&editor->lock, NULL); return editor; } // 释放资源 void destroy_image_editor(ImageEditor* editor) { if (!editor) return; for (int i = 0; i < editor->count; i++) { free(editor->images[i].pixels); } free(editor->basePixels); pthread_mutex_destroy(&editor->lock); free(editor); } // 添加小图片到指定位置 int add_image(ImageEditor* editor, const char* smallImagePath, int x, int y, const char* outputPath) { pthread_mutex_lock(&editor->lock); if (editor->count >= MAX_IMAGES) { pthread_mutex_unlock(&editor->lock); return 0; } // 读取小图片 FILE* file = fopen(smallImagePath, "rb"); if (!file) { pthread_mutex_unlock(&editor->lock); return 0; } BMPHeader header; BMPInfoHeader infoHeader; fread(&header, sizeof(BMPHeader), 1, file); fread(&infoHeader, sizeof(BMPInfoHeader), 1, file); SmallImage* img = &editor->images[editor->count]; img->pixels = (Pixel*)malloc(SMALL_SIZE * SMALL_SIZE * sizeof(Pixel)); fseek(file, header.offset, SEEK_SET); fread(img->pixels, sizeof(Pixel), SMALL_SIZE * SMALL_SIZE, file); fclose(file); strcpy(img->path, smallImagePath); img->x = x; img->y = y; img->width = SMALL_SIZE; img->height = SMALL_SIZE; editor->count++; // 合成图片 Pixel* result = (Pixel*)malloc(BASE_WIDTH * BASE_HEIGHT * sizeof(Pixel)); memcpy(result, editor->basePixels, BASE_WIDTH * BASE_HEIGHT * sizeof(Pixel)); for (int i = 0; i < editor->count; i++) { SmallImage* current = &editor->images[i]; for (int py = 0; py < current->height; py++) { for (int px = 0; px < current->width; px++) { int baseX = current->x + px; int baseY = current->y + py; if (baseX >= 0 && baseX < BASE_WIDTH && baseY >= 0 && baseY < BASE_HEIGHT) { Pixel* src = &current->pixels[py * current->width + px]; Pixel* dest = &result[baseY * BASE_WIDTH + baseX]; *dest = *src; // 直接覆盖像素 } } } } // 保存结果 file = fopen(outputPath, "wb"); if (!file) { free(result); pthread_mutex_unlock(&editor->lock); return 0; } BMPHeader newHeader = {0x4D42, 54 + BASE_WIDTH * BASE_HEIGHT * 4, 0, 0, 54}; BMPInfoHeader newInfoHeader = { sizeof(BMPInfoHeader), BASE_WIDTH, BASE_HEIGHT, 1, 32, 0, BASE_WIDTH * BASE_HEIGHT * 4, 0, 0, 0, 0 }; fwrite(&newHeader, sizeof(BMPHeader), 1, file); fwrite(&newInfoHeader, sizeof(BMPInfoHeader), 1, file); fwrite(result, sizeof(Pixel), BASE_WIDTH * BASE_HEIGHT, file); fclose(file); free(result); pthread_mutex_unlock(&editor->lock); return 1; } // 查找点击位置的小图片 int find_image_at(ImageEditor* editor, int x, int y) { // 从后向前查找(最后添加的在最上面) for (int i = editor->count - 1; i >= 0; i--) { SmallImage* img = &editor->images[i]; if (x >= img->x && x < img->x + img->width && y >= img->y && y < img->y + img->height) { return i; } } return -1; } // 删除或移动图片 void handle_image_interaction(ImageEditor* editor, int startX, int startY, int endX, int endY, const char* outputPath) { pthread_mutex_lock(&editor->lock); int index = find_image_at(editor, startX, startY); if (index == -1) { pthread_mutex_unlock(&editor->lock); return; } // 删除操作:起点和终点相同 if (startX == endX && startY == endY) { free(editor->images[index].pixels); // 移动数组元素填补空缺 for (int i = index; i < editor->count - 1; i++) { editor->images[i] = editor->images[i + 1]; } editor->count--; } // 移动操作 else { int targetIndex = find_image_at(editor, endX, endY); SmallImage* moved = &editor->images[index]; // 与目标位置图片交换 if (targetIndex != -1 && targetIndex != index) { SmallImage target = editor->images[targetIndex]; editor->images[targetIndex] = *moved; *moved = target; } // 移动到空白位置 else { moved->x = endX - moved->width / 2; moved->y = endY - moved->height / 2; } } // 重新合成并保存图片 Pixel* result = (Pixel*)malloc(BASE_WIDTH * BASE_HEIGHT * sizeof(Pixel)); memcpy(result, editor->basePixels, BASE_WIDTH * BASE_HEIGHT * sizeof(Pixel)); for (int i = 0; i < editor->count; i++) { SmallImage* current = &editor->images[i]; for (int py = 0; py < current->height; py++) { for (int px = 0; px < current->width; px++) { int baseX = current->x + px; int baseY = current->y + py; if (baseX >= 0 && baseX < BASE_WIDTH && baseY >= 0 && baseY < BASE_HEIGHT) { Pixel* src = &current->pixels[py * current->width + px]; Pixel* dest = &result[baseY * BASE_WIDTH + baseX]; *dest = *src; } } } } FILE* file = fopen(outputPath, "wb"); if (file) { BMPHeader header = {0x4D42, 54 + BASE_WIDTH * BASE_HEIGHT * 4, 0, 0, 54}; BMPInfoHeader infoHeader = { sizeof(BMPInfoHeader), BASE_WIDTH, BASE_HEIGHT, 1, 32, 0, BASE_WIDTH * BASE_HEIGHT * 4, 0, 0, 0, 0 }; fwrite(&header, sizeof(BMPHeader), 1, file); fwrite(&infoHeader, sizeof(BMPInfoHeader), 1, file); fwrite(result, sizeof(Pixel), BASE_WIDTH * BASE_HEIGHT, file); fclose(file); } free(result); pthread_mutex_unlock(&editor->lock); } //叠加图片操作 void overlay_image_any_position(const char* backgroundPath,const char* foregroundPath,const char* outputImagePath,int startX,int startY) { // 创建编辑器 ImageEditor* editor = create_image_editor(backgroundPath); // 添加小图片 add_image(editor, foregroundPath,startX, startY, outputImagePath); // 释放资源 destroy_image_editor(editor); } //长按删除操作 void overlay_image_del(const char* backgroundPath,const char* outputImagePath,int startX,int startY,int end_x,int end_y) { // 创建编辑器 ImageEditor* editor = create_image_editor(backgroundPath); // 模拟长按删除 (相同位置) handle_image_interaction(editor, startX,startY,end_x,end_y,outputImagePath); // 释放资源 destroy_image_editor(editor); } //长按移动交换操作 void overlay_image_swap(const char* backgroundPath,const char* outputImagePath,int startX,int startY,int end_x,int end_y) { // 创建编辑器 ImageEditor* editor = create_image_editor(backgroundPath); // 模拟移动交换 (拖动到另一个图片位置) handle_image_interaction(editor, startX,startY,end_x,end_y,outputImagePath); // 释放资源 destroy_image_editor(editor); }修改上述bmp为24位
08-24
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至同网络结构或加入更多确定性因素进行深化研究。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值