Hello friends,
i want to convert pixel format of any image to normal RGB32bit pixel format image using VB.NET 2010.i have alredy done with VB.NET 2005.
i searched using Object browser.no success.
plz tel me a function to do that.
thanks
[ Post made via Mobile Device ]
How convert pixel format?
Re: How convert pixel format?
Why don't you use simple mathematics to convert from one format to the other?
Re: How convert pixel format?
If the following code helps, try to convert it to VB.Net. It's in C#.
Code: Select all
Bitmap img = (Bitmap)Image.FromFile(dlg.FileName);
// Ensure that it's a 32 bit per pixel file
if (img.PixelFormat!=PixelFormat.Format32bppPArgb){
Bitmap temp = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppPArgb);
Graphics g = Graphics.FromImage(temp);
g.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel);
img.Dispose();
g.Dispose();
img = temp;
}
Re: How convert pixel format?
Thank Neo,
actually it was helpful.i could convert it very easily.
This is converted code.
i have used Format32bppRgb insted of Format32bppArgb.because i want it.
thank Neo
[ Post made via Mobile Device ]
actually it was helpful.i could convert it very easily.
This is converted code.
Code: Select all
imports system.drawing
imports system.drawing.imagine
public class Form1
private sub Btn_click()
dim img as bitmap=new bitmap(application.startuppath+"/tux.png")
'cheack pixel format of opend image is 32bppRGB
if not img.pixelformat=pixelformat.format32bppRgb then
dim tmp as bitmap(img.width,img.height,pixelformat.format32bpp)
dim g as graphics=graphics.fromimage(tmp)
g.drawimage(img,new rectangle(0,0,img.width,img.height),0,0,img.width,img.height,graphicsunit.pixel
tmp.save(application.startuppath+"/tux.bmp")
end if
end sub
end class
thank Neo
[ Post made via Mobile Device ]
Re: How convert pixel format?
Hello Saman,
What is simpal mathematical system which you knew.
please tel me about it.
i have very small knowledge about images,pixel,file types,colours,...
i knew it from explore Python image libarary files in ubuntu.
thank
[ Post made via Mobile Device ]
What is simpal mathematical system which you knew.
please tel me about it.
i have very small knowledge about images,pixel,file types,colours,...
i knew it from explore Python image libarary files in ubuntu.
thank
[ Post made via Mobile Device ]
Re: How convert pixel format?
Saman why are you silent?
can you help me?please
i like to know your system.it will be important to me and all ECs.
i have alredy searched in EC. i couldnt find anyone.
thank
[ Post made via Mobile Device ]
can you help me?please
i like to know your system.it will be important to me and all ECs.
i have alredy searched in EC. i couldnt find anyone.
thank
[ Post made via Mobile Device ]
Re: How convert pixel format?
Sorry dude, I was busy.
Neo has added a code and glad to know that you got it working. Your post meant like a feature which was removed from the latest .Net. Even in a case like that, you can use simple transformations to convert from one colour plane to the other.
For example, one of the very common transformation is between YUV and RGB. Usually cameras output data in YUV format and you need to get it converted to RGB to display on a PC. Again, if you need to convert to JPG or MPEG, you need to convert it back from RGB to YUV. Here are the transformations.
RGB to YUV Conversion
Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
YUV to RGB Conversion
B = 1.164(Y - 16) + 2.018(U - 128)
G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
R = 1.164(Y - 16) + 1.596(V - 128)
In your case, RGB32 is about having three 8-bit (3 bytes) for RGB data and one extra byte of Alpha.
Neo has added a code and glad to know that you got it working. Your post meant like a feature which was removed from the latest .Net. Even in a case like that, you can use simple transformations to convert from one colour plane to the other.
For example, one of the very common transformation is between YUV and RGB. Usually cameras output data in YUV format and you need to get it converted to RGB to display on a PC. Again, if you need to convert to JPG or MPEG, you need to convert it back from RGB to YUV. Here are the transformations.
RGB to YUV Conversion
Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128
YUV to RGB Conversion
B = 1.164(Y - 16) + 2.018(U - 128)
G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
R = 1.164(Y - 16) + 1.596(V - 128)
In your case, RGB32 is about having three 8-bit (3 bytes) for RGB data and one extra byte of Alpha.
Re: How convert pixel format?
Thank you Saman,
it is really nice and very simple system.actually it will be important to me in future.
i have small memory about this. this had in Python image library.
Thank you Saman for dedicate your valuale time fore me.
[ Post made via Mobile Device ]
it is really nice and very simple system.actually it will be important to me in future.
i have small memory about this. this had in Python image library.
Thank you Saman for dedicate your valuale time fore me.
[ Post made via Mobile Device ]