Results 1 to 7 of 7

Thread: Need to load .NET bitmap from 1bpp png stored as 32bpp

  1. #1
    Join Date
    May 2011
    Posts
    52

    Need to load .NET bitmap from 1bpp png stored as 32bpp

    I am making a .NET C++ application that loads PNG/TIF images keen on System:: Drawing::Bitmap. However, when I build a new bitmap like this:

    Code:
    Bitmap bm = gcnew System:: Drawing::Bitmap(gcnew System:: String("1bpp.png"));
    The bitmap I have become has PixelFormat: Format32bppArgb, even though the PNG file format is stored in cargo 1bpp. However, I want the image is loaded into the pixel format of the PNG (1bpp in this situation) because my algorithm assumes that distribution of memory.
    Apart from converting back to 1bpp during charging (which is inefficient), is there any way for me to load the PNG as a bitmap 1bpp directly? Even if you can only get a pointer to the buffer contains the pixel data that you can use this to construct a bitmap, so I want to know if this is possible. I would like to avoid external (non-NET) library if possible.

  2. #2
    Join Date
    May 2009
    Posts
    637

    Re: Need to load .NET bitmap from 1bpp png stored as 32bpp

    In my experiments (PNG files only, though) it seemed that this "conversion force" pixel format only happens to one bpp files. I tried to convert the bitmap charged back to bpp like this:
    Code:
    m_bmp = m_bmp->Clone(Rectangle(Point(0, 0), m_bmp->Size), PixelFormat::Format1bppIndexed);
    Unfortunately, it kept throwing an OutOfMemoryException. According to MSDN you should only do so if the parameter rectangle passed to this method exceeds the limits of the source bitmap that is clearly not the case here. It seems that this type of conversion is not possible to use this simple method.

  3. #3
    Join Date
    May 2009
    Posts
    511

    Re: Need to load .NET bitmap from 1bpp png stored as 32bpp

    I do not think the Bitmap class has a copy of the bitmap data read raw file. Certainly, you are free to access the file honestly, but knowing the bit depth of the file is not small to TIFF format. As the situation seems now, by the conversion of 32 bpp to 1 bpp on the basis of the Bitmap class. NET itself is a great option to consider. The biggest problem I see with this is to determine if the original data was bpp, but of course I do not know the details of your situation and cannot be a relatively easy way that I do not know.

  4. #4
    Join Date
    May 2009
    Posts
    543

    Re: Need to load .NET bitmap from 1bpp png stored as 32bpp

    I think it is not simple to beat the code has been linked to, as it makes its conversion into a single call to BitBit (). Well, maybe GDI has no (full) use of small businesses in this role that is likely to leave significant room for optimization. However, I personally do not really like the programming of the SSE features and am very happy if I have access to the routines that make use of them for me. Write your own SSE based on the conversion would certainly be a lot of work and also you cannot do in managed code. However, the incorporation of native routines is not as hard on C + + / CLI though at least structurally complicate your program.

  5. #5
    Join Date
    May 2009
    Posts
    529

    Re: Need to load .NET bitmap from 1bpp png stored as 32bpp

    I was not aware that you have control over the code that generates the images. However, this seems an ideal solution: I think at least NET framework must support him. Now this seems a perfect setting for a batch converter based on the console to fix pre-existing images. I did not even really need to be efficient so you can also use a method of converting pixel-wise based on the Bitmap class. NET if you cannot get much based approach to work.

  6. #6
    Join Date
    Apr 2009
    Posts
    569

    Re: Need to load .NET bitmap from 1bpp png stored as 32bpp

    I was a little intrigued by this, so I tried to reproduce the behavior described, and could not do it no matter what. For me, all images are loaded correctly, but the problems attached here, and Bitmap:: Clone works perfectly and successfully becomes 1bpp format. I attached a very simple test project in a zip file also contains a compiled version. Could either of you compile the project on the computer or try to run the two exe-s and see if there is any difference? There is absolutely nothing fancy about the project, using the same things you tried, so I hope that once compiled in one of their machines, the error still be there. All functionality in Form1.h in the event handler of the button.

  7. #7
    Join Date
    May 2009
    Posts
    539

    Re: Need to load .NET bitmap from 1bpp png stored as 32bpp

    In spite of (rather short) MSDN description of Bitmap (int, int, PixelFormat) constructor does not pass a single word about this, there seems no way to construct an instance of a bitmap format indexed pixel, except load from a file, with the clone (rectangle, PixelFormat) to convert what appears to be likely only in Win7 or using the bitmap (int, int, int, PixelFormat, IntPtr) constructor with pre-prepared bitmap raw data that either would require a major effort on the side of the developer or an approach based on win-API.

Similar Threads

  1. How to Optimize getPixel() calls for 1bpp vs. 8bpp?
    By Megatruck in forum Software Development
    Replies: 6
    Last Post: 27-06-2011, 07:38 AM
  2. What are Bitmap files?
    By L 4 Life in forum Windows Software
    Replies: 5
    Last Post: 18-01-2011, 08:04 AM
  3. Using stored procedures and stored functions in MySQL
    By Adiran in forum Software Development
    Replies: 6
    Last Post: 14-12-2010, 01:54 AM
  4. Locally stored profile does not load
    By Utanka in forum Windows XP Support
    Replies: 4
    Last Post: 14-10-2009, 09:45 PM
  5. Windows cannot load the locally stored profile
    By charlestek in forum Windows Server Help
    Replies: 0
    Last Post: 01-05-2007, 04:34 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,012,178.13440 seconds with 17 queries