tags:

views:

67

answers:

2

I want to open a image(jpeg, bmp) using GDI+ using readonly mode, in c++。How can I do this? Many Thanks!

A: 

File I/O in Standard C and C++ has no notion of a read-only file. You just open the file for reading and not for writing. Using iostreams:

#include <fstream>
std::ifstream f( "jgeg.bmp", std::ios::binary );

Using C-style streams:

#include <cstdio>
FILE * f = fopen( "jpeg.bmp", "rb" );
anon
Neither is usable with GDI+.
Hans Passant
+2  A: 

In the aspect of an image file, it is always read-only. MSDN' s Gdiplus::Image::Save:

GDI+ does not allow you to save an image to the same file that you used to construct the image.

In the aspect of an image in memory, it is never read-only. When loaded as Gdiplus::Bitmap or Gdiplus::Image, an image can always be modified - you can't prevent creation of Gdiplus::Graphics that manipulates it.

AOI Karasu