我目前正在使用以下内容将PNG写入文件:
#include <png.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
/* Pixels in this bitmap structure are stored as BGR. */
typedef struct _RGBPixel {
uint8_t blue;
uint8_t green;
uint8_t red;
} RGBPixel;
/* Structure for containing decompressed bitmaps. */
typedef struct _RGBBitmap {
RGBPixel *pixels;
size_t width;
size_t height;
size_t bytewidth;
uint8_t bytes_per_pixel;
} RGBBitmap;
/* Returns pixel of bitmap at given point. */
#define RGBPixelAtPoint(image, x, y) \
*(((image)->pixels) + (((image)->bytewidth * (y)) \
+ ((x) * (image)->bytes_per_pixel)))
/* …Run Code Online (Sandbox Code Playgroud) (为什么我要这样做:我没有运气在Windows上使用libpng预先构建的二进制文件(尽管经过了数小时的试验和错误),因此我现在正在尝试自己编译它.我发现这个有用的博客关于此的帖子,完成了Microsoft Visual Studio 2008项目文件,但遗憾的是仍然无法使用它.)
它在链接到此处找到的zlib二进制文件时成功编译,但在尝试将其链接到测试文件时,我收到以下内容:
C:\Documents and Settings\Administrator\My Documents>cl "C:\Documents and Settin
gs\Administrator\My Documents\test.c" "C:\Documents and Settings\Administrator\M
y Documents\libpng.lib" -I "C:\Documents and Settings\Administrator\My Documents\include"
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
test.c
Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:test.exe
test.obj
"C:\Documents and Settings\Administrator\My Documents\libpng.lib"
MSVCRTD.lib(MSVCR90D.dll) : error LNK2005: _abort already defined in LIBCMT.lib(
abort.obj)
MSVCRTD.lib(MSVCR90D.dll) : … 如何使用win32 API将保存为".BMP"文件的缓冲区复制到剪贴板?即,我有一个Windows V3位图的原始缓冲区(包括标题),我可以字面上write()一个文件,并将产生一个有效的.BMP文件,但我想将其复制到剪贴板.
在OS X上,在普通的C中,代码看起来像这样(按预期工作):
#include <ApplicationServices/ApplicationServices.h>
int copyBitmapToClipboard(char *bitmapBuffer, size_t buflen)
{
PasteboardRef clipboard;
CFDataRef data;
if (PasteboardCreate(kPasteboardClipboard, &clipboard) != noErr) {
return PASTE_OPEN_ERROR;
}
if (PasteboardClear(clipboard) != noErr) return PASTE_CLEAR_ERROR;
data = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, bitmapBuffer, buflen,
kCFAllocatorNull);
if (data == NULL) {
CFRelease(clipboard);
return PASTE_DATA_ERROR;
}
if (PasteboardPutItemFlavor(clipboard, 42, kUTTypeBMP, data, 0) != noErr) {
CFRelease(data);
CFRelease(clipboard);
return PASTE_PASTE_ERROR;
}
CFRelease(data);
CFRelease(clipboard);
return PASTE_WE_DID_IT_YAY;
}
Run Code Online (Sandbox Code Playgroud)
我不确定如何使用win32 API完成此任务.这是我已经得到的,但它似乎无声地失败(也就是说,函数返回成功的错误代码,但在尝试粘贴时,菜单项被禁用).
#include <windows/windows.h>
int copyBitmapToClipboard(char *bitmapBuffer, size_t buflen)
{
if (!OpenClipboard(NULL)) …Run Code Online (Sandbox Code Playgroud)