473,657 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lots of bitmap problems

I have 1 bit per pixel information and i have the width and height of
this data.Each bit corresponds to a 24 bit colour value. I want to
convert this to 24bit per pixel bitmap.
Do i need to multiply the width and the height by 24 or just the width?.
I tried to multiply the width by 24 but the value is too large?.....what
can i do?.
The 1bpp data is at resolution 600dpi.....can i just use the set
resolution function to change it to 96dpi or do i need to do something
else?.

Basically i want to know the steps i need to do in C#......How to create
a 24bpp 96dpi bitmap from 1bpp 600dpi(width and height) resolution data.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
8 7170
You can simply draw the 1 bit-per-pixel image onto a 24 bit image using
DrawImage...

Bitmap onebit=(Bitmap) Image.FromFile( "theimagefile") ;
Bitmap bm=new Bitmap(onebit.W idth, onebit.Height,
PixelFormat.For mat24bppRGB);
Graphics g=Graphics.From Image(bm);
g.DrawImage(one bit,new
Rectangle(0,0,o nebit.Width,one bit.Height),0,0 ,onebit.Width,o nebit.Height,Gr a
phicsUnit.Pixel );
g.dDispose();

The bm bitmap now contains a 24bpp copy of the original one bit per pixel
image.

The resolution of the copy will not be the same as that of the original. You
can change this using the SetResolution method. Remember that resolution has
nothing to do with pixel-dimensions.
--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"James Dean" <m_*******@yaho o.com> wrote in message
news:u%******** **********@TK2M SFTNGP10.phx.gb l...
I have 1 bit per pixel information and i have the width and height of
this data.Each bit corresponds to a 24 bit colour value. I want to
convert this to 24bit per pixel bitmap.
Do i need to multiply the width and the height by 24 or just the width?.
I tried to multiply the width by 24 but the value is too large?.....what
can i do?.
The 1bpp data is at resolution 600dpi.....can i just use the set
resolution function to change it to 96dpi or do i need to do something
else?.

Basically i want to know the steps i need to do in C#......How to create
a 24bpp 96dpi bitmap from 1bpp 600dpi(width and height) resolution data.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
But unfortunately its compressed 1bpp data.....i have an RGB color value
for each pixel that is set?.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Hi James
I have 1 bit per pixel information and i have the width and height of
this data.Each bit corresponds to a 24 bit colour value. I want to
convert this to 24bit per pixel bitmap.
Try this:

Bitmap.Clone(Re ctangle rect,
PixelFormat format).
Do i need to multiply the width and the height by 24 or just the width?.
I tried to multiply the width by 24 but the value is too large?.....what
can i do?.
The 1bpp data is at resolution 600dpi.....can i just use the set
resolution function to change it to 96dpi or do i need to do something
else?.

Basically i want to know the steps i need to do in C#......How to create
a 24bpp 96dpi bitmap from 1bpp 600dpi(width and height) resolution data.


I don't know much about dpis, because i allways count bitmaps in
pixels, but there is...

Bitmap.SetResol ution(
float xDpi,
float yDpi
);

....that you can try.

Cheers

Marcin
Nov 16 '05 #4
Is it possible to set the index colors of your 1bpp bitmap?. Probably
not.....

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Hi James
But unfortunately its compressed 1bpp data.....i have an RGB color value
for each pixel that is set?.


"Do you want to convert 1bit bitmap data - not Bitmap - (width*height/8
bytes) into 24bpp Bitmap?"
If this data is compressed, then only easy way is to try
to create Bitmap from stream... :(

The simplest way is to create new 24bpp Bitmap
and iterate through whole (1bit) bitmap data:

1. Remeber that 1bpp bitmap row has length = width/8,
2. Your destination 24bpp bitmap will be approx. 24x greater than 1bpp
3. Treat each byte of source as 8 pixels for destiation bitmap
(8 * 3 bytes of output per 1 input byte)

There should be more threads in this group history that
could be very usefull.

Regards

Marcin
Nov 16 '05 #6
I have trouble displaying the bitmap. I have 1bpp information. I also
have a command telling me what color i need to set the bytes to when the
colour is switched on. The trouble is i do all this but it will not
display properly. I convert this to 8bpp information. I set the relevant
pixel to for example "255,0,0" for Red.....is this right?....i set the
Red byte to 255 and the other two values set to 0. I think the Bitmap
data class i am using is not working properly. Have a look at the data
below.

bitmap = new
Bitmap(PageSize InPixels.Width, PageSizeInPixel s.Height,System .Drawing.Ima
ging.PixelForma t.Format8bppInd exed);

public struct PixelData
{
public byte RedValue;
public byte GreenValue;
public byte BlueValue;
};

public void LockBitmap()
{
GraphicsUnit unit = GraphicsUnit.Pi xel;
RectangleF boundsF = bitmap[bitmap_Count - 1].GetBounds(ref unit);
Rectangle bounds = new Rectangle((int) boundsF.X,
(int) boundsF.Y,
(int) boundsF.Width,
(int) boundsF.Height) ;

// Figure out the number of bytes in a row
// This is rounded up to be a multiple of 4
// bytes, since a scan line in an image must always be a multiple of 4
bytes
// in length.
width = (int) boundsF.Width * sizeof(PixelsDa ta);
if (width % 4 != 0)
{
width = 4 * (width / 4 + 1);
}
bitmapData =
bitmap[bitmap_Count - 1].LockBits(bound s, ImageLockMode.R eadWrite,
PixelFormat.For mat8bppIndexed) ;

pBase = (Byte*) bitmapData.Scan 0.ToPointer();
}

public void Make24BppBitmap ()
{

//LineDataStore stores the 1bpp information
fixed(byte* ThisData = LineDataStore)
{
byte* CurrLine = ThisData + (y * ByteWidth);
PixelData* pPixel = PixelAt(0, y);
for (int x = 0; x < size.X; x++)
{
//check to see if bit is set by using masking
if it is set
then
{
pPixel->RedValue = GetBitmapColorV alue[0];
pPixel->GreenValue = GetBitmapColorV alue[1];
pPixel->BlueValue = GetBitmapColorV alue[2];
}
pPixel++;
}

}

}

For the above i only get a black bitmap......wha ts the problem.......


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7
Sorry that function should be named Make8BppBitmap( ) not
Make24BppBitmap ()

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #8
The 1bpp image will have a colour palette, you can set the palette values or
alternatively use a ColorMap and an ImageAttributes class to change the
colour as it's drawn.

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"James Dean" <m_*******@yaho o.com> wrote in message
news:OP******** *****@TK2MSFTNG P11.phx.gbl...
Is it possible to set the index colors of your 1bpp bitmap?. Probably
not.....

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
556
by: Prashant | last post by:
Hi, I have a huge problem. I have a data file which looks something like this -: ..1 .5 .9 -1 .2 .5 ...... ..2 .9 .1 .4 .3 -1 ...... ..2 .4 .5 .7 .6 .2 ...... ........
3
17376
by: instruo | last post by:
I'm using the System.Drawing.Bitmap class for loading a 32-bit bmp file which includes an alpha channel. The problem is, when it gets loaded (just using the Bitmap(string filename) constructor), it doesn't bother bringing the alpha along with it. All of the pixels just show "255" as their alpha value and Bitmap.IsAlphaPixelFormat() returns false. I know that the alpha does exist physically and has worked with this exact image in other...
0
3596
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it into byte from a stream. Exception (System.ArgumentException: Invalid parameter used) occurs when reading from byte over a memory-stream back to the Bitmap object. Please help, I'm really stuck here! Here's the code I use (Sorry for a long...
2
2223
by: creepwood | last post by:
I'm trying to load and image into a DB and alongside the image also a thumbnailed version of the image, but somewhere in my code, the stream doesn't take the thumbnail data. When I just change toe bitmap.save() to a file instead of a stream it works just fine. Dim bm As Bitmap = System.Drawing.Image.FromStream(fs) Dim newHeight As Integer = 40 Dim newWidth As Integer = (newHeight / bm.Height) * bm.Width
9
8415
by: SStory | last post by:
I use a bitmap class new bitmap(filepath) this should and does load my jpg into memory. I then want to use mybitmap.save(filepath,imaging.imageformat.jpeg) to save it; overwriting the original. If this outfile path is different there is no problem but when it is the same file it blows up with a generic GDI+error.
3
8624
by: CSH | last post by:
Hi all, I've run into a small problem opening and saving bitmaps. Concider the following code: Dim oBM as Bitmap Dim cFileName as String ... some code to get the filename etc...
7
2016
by: Dennis | last post by:
I am trying to implement drawing on a bitmap and using bitblt to transfer it to the control graphics object in the paint event. It seems to draw on the bitmap ok but doesn't get transferred to the control graphics object in the paint event. Any help would be appreciated. Here is my code: public class as mycontrol Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nxDest As Integer, ByVal nyDest As...
4
13264
by: Andrew | last post by:
Hi, I'm trying to blit small bitmaps onto a larger bitmap, and I've got a few issues wrt positioning and output size. I think my problems are due to DPI differences... My small images are 72 DPI My Large image (which i need to create in code) needs to be 300 DPI.
1
5592
by: martinsmith160 | last post by:
Hi all I am trying to create a level builder tool for a final year project and im having some problems drawing. I have placed a picture box within a panel so i can scroll around the image which is working fine. My aim is to double click the picture box and the desired image will be drawn at the mouse position. This works fine unless I scroll or minimise the form because the image isnt repainted after movement. I looked up drawing the image to...
0
8392
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
8305
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
8825
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
8732
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
6163
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
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
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.