C ++ GDI +从文件加载图像然后在*卸载图像之前删除文件*
简单就是锡上的内容
我正在使用Bitmap :: FromFile从文件加载位图,但之后我想从磁盘中删除它。
问题是,Bitmap :: FromFile绝对锁定文件的任何更改/删除,直到卸载加载的图像
这是因为我将位图存储在二进制文件中,所以我想按此顺序执行:
1.从二进制文件中提取图像
2.加载图像
3.删除#1中提取的文件
(只是对我的图像资源的一些基本保护,我只是不希望它们坐在我的程序目录中)
即使从文件中克隆加载的图像,Bitmap :: FromFile仍会将文件锁定为删除,就像在我的尝试中一样:
Bitmap* tempbmp = Bitmap::FromFile(fileanddir.c_str(),false);
Rect temprect( 0, 0, tempbmp->GetWidth(), tempbmp->GetHeight() );
// make the image to be used as a clone to the temporary
// bitmap to avoid file locking
image_to_be_used = tempbmp->Clone(temprect, PixelFormatDontCare);
// delete temporary loaded bitmap since it shouldn't be needed
delete tempbmp;
// delete the file itself, too bad the file is locked
int theresult = remove(tocharptr(fileanddir));
// returns -1, also: manually deleting at this point gives the error
// that the file is being used by another person/program
知道如何加载位图或以某种方式将其复制到内存中以便文件本身不会被锁定吗?
(所以我可以在加载后删除它一会儿)
没有找到相关结果
已邀请:
3 个回复
钨蜡唤喉晤
。您应该可以使用
在文件上打开
。加载位图后,您可以安全地删除流,然后删除临时文件。 如果二进制文件仅使用支持的算法进行压缩,则将相应的标志传递给
并让它读取存档,从而绕过将图像提取到临时文件中。否则可以实现
接口读取二进制文件并直接提取图像数据。
味芯憨
疼嘶桐