473,748 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.NET doesn’t recognize PixelFormat.For mat16bppRgb565

4 New Member
I am writing a regression testing suite that uses some image comparison features for some RFI (radio frequency interference) testing equipment. I capture an image (from the screen of the device), and save this first image as a reference as “what the screen should look like;” then when executing a “macro” on the device, I will then capture another image and compare it to the “reference” image – the details aren’t important, but FYI.

The images I am analyzing come to me in a bitmaped (800X600) image that uses PixelFormat.For mat16bppRgb565.

The problem is that I need to save an image of this pixel format to disk, then retrieve it later for comparison. When I attempt to open this saved bmp, .NET (I have tried both VB and C#) open it as a PixelFormat.For mat32bppRgb (automatically converting it for me) – and I need the image to be in the same PixelFormat to compare them.

So, I have a couple of possible solutions:
1) read the saved bitmap (in PixelFormat.For mat16bppRgb565) raw off the hard disk using a BinaryReader. – The problem with that is that BMP images have header files that make the bmp load correctly; if one were to read the raw bmp data off the hard disk, it is usually flipped 180, inverted, and slightly offset.
2) Use some .NET library to correctly open the bitmapped image (PixelFormat.Fo rmat16bppRgb565 ).
3) Convert both images (the one from disk, and the newly captured image) into a compatible format. Ideally PixelFormat.For mat8bppIndexed (or .gif). I messed around with this for a while trying to do something like:
Expand|Select|Wrap|Line Numbers
  1.         public static Bitmap ConvertToGif(Bitmap img) {
  2.             Bitmap temp = new Bitmap(img.Width, img.Height, 
  3.                    PixelFormat.Format8bppIndexed);
  4.             BitmapData tempLocked = temp.LockBits(
  5.                 new Rectangle(0, 0, temp.Width, temp.Height),
  6.     ImageLockMode.WriteOnly,     PixelFormat.Format8bppIndexed);
  7.             Byte[] a = new Byte[img.Width * img.Height];
  8.             temp.UnlockBits(tempLocked);
  9.  
  10.             MemoryStream fs = new MemoryStream(a);
  11.             img.Save(fs, ImageFormat.Gif);
  12.             temp = new Bitmap(fs);
  13.             fs.Close();
  14.  
  15.             return temp;
  16. }
  17.  
With no luck – any ideas?
Aug 30 '07 #1
1 6470
theShmit
4 New Member
I actually figured out how to read the piselformat.16r bg565 in c#


Expand|Select|Wrap|Line Numbers
  1. private const int BITMAP_HEADER_OFFSET_BYTES = 61;
  2.  
  3. public static Bitmap Open565(String fileName) {
  4.             try {
  5.                 Bitmap temp = new Bitmap(800, 600, PixelFormat.Format16bppRgb565);
  6.                 BitmapData tempLocked = temp.LockBits(
  7.                     new Rectangle(0, 0, 800, 600), ImageLockMode.WriteOnly,
  8.                     PixelFormat.Format16bppRgb565);
  9.                 BinaryReader br = new BinaryReader(File.Open(fileName, FileMode.Open));
  10.                 byte[] bin = new byte[tempLocked.Height * tempLocked.Stride + 
  11.                     BITMAP_HEADER_OFFSET_BYTES];
  12.  
  13.                 br.Read(bin, 0, bin.Length - 1);
  14.                 br.Close();
  15.  
  16.                 System.Runtime.InteropServices.Marshal.Copy(bin,
  17.                     BITMAP_HEADER_OFFSET_BYTES - 1, tempLocked.Scan0,
  18.                     bin.Length - 1 - BITMAP_HEADER_OFFSET_BYTES);
  19.  
  20.                 temp.UnlockBits(tempLocked);
  21.                 temp.RotateFlip(RotateFlipType.RotateNoneFlipY);
  22.                 return temp;
  23.             } catch (Exception) {
  24.                 Console.WriteLine("Error in converting image.");
  25.                 return new Bitmap(1, 1, PixelFormat.Format4bppIndexed);
  26.             }
  27.  
  28.  
  29.         }
  30.  
does anyone know how to convert an image to .gif (PixelFormat.Fo rmat8bppIndexed ) in runtime?

thanks
Aug 30 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3391
by: lawrence | last post by:
I've a template with some PHP code in it. I need to get the names of all the PHP commands, so I can import them and so I can make sure they are officially allowed (for security purposes, users are only allowed to use officially allowed commands). I'm using the following class method. substr is not working as I expect. When I echo out $location1 and $location2 I get 8287 and 8306 which are correct answers for the first PHP command. But when...
149
25181
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
3
33572
by: Flix | last post by:
Is there some way to convert a Bitmap from one PixelFormat (16bit or with indexed colors) to another(24bit), without doing per pixel operations?
2
1495
by: Phil Galey | last post by:
If you have a bitmap, but need for it to be of a different PixelFormat, how can you do that? PixelFormat is ReadOnly. Does it have to be done while Drawing to a graphics object? I wonder if there's a code sample available somewhere in which this is done. Thanks Phil Galey
3
37659
by: johnb41 | last post by:
I need to use the bitmap.getpixel method to work on the pixel level of an image. But GetPixel will not work with Indexed images. The images that i work with are black & white text scans. I create the bitmap object like this: Dim b As Bitmap = Bitmap.FromFile("c:\scan.tif") But I want to convert this file to PixelFormat.Format24bppRgb (or something NOT indexed)
0
3834
by: Mil | last post by:
Hello, I'm trying to convert Images using Bitmap class. I want to use different options for example reduce the size of image. In my code I tried to create a Bitmap class instance with a Bitmap's constructor: new Bitmap(source.Width, source.Height, PixelFormat.Format8bppIndexed);
2
7532
by: Sharon | last post by:
Hello Experts, I'm creating a bitmap object like this: Bitmap myImage = new Bitmap(1024, 1024, System.Drawing.Imaging.PixelFormat.Format24bppRgb); But when I invoking the function myImage .MakeTransparent() (with or without parameters), the myImage.PixelFormat changes to Format32bppArgb. Why is that and how can I avoid it but still making the Bitmap transparent ?
1
1933
by: Nathan Sokalski | last post by:
I have created declared a Bitmap using the following statement: Dim bmp As New Bitmap(100, 100, PixelFormat.Format8bppIndexed) Because the SetPixel() method is disabled and a Graphics object cannot be created for indexed PixelFormats, I am not sure how to edit the Bitmap. I am assuming that there is some class or technique other than the following: Dim bmpdata As BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height),...
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.