Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ImageProcessing
Hey! I need to convert 8 bpp avi file into 16 bpp avi file.
 
Does anyone know how to do it?
 
I used this code to get bitmap images from avi file. It works fine with 16 bpp or more but does not work for 8bpp avi files properly.
 
public Bitmap GetBitmap(int position){
if(position > countFrames){
throw new Exception("Invalid frame position: "+position);
}
 
Avi.AVISTREAMINFO streamInfo = GetStreamInfo(StreamPointer);
 
//Decompress the frame and return a pointer to the DIB
int dib = Avi.AVIStreamGetFrame(getFrameObject, firstFrame + position);
//Copy the bitmap header into a managed struct
Avi.BITMAPINFOHEADER bih = new Avi.BITMAPINFOHEADER();
bih = (Avi.BITMAPINFOHEADER)Marshal.PtrToStructure(new IntPtr(dib), bih.GetType());

if(bih.biSizeImage < 1){
throw new Exception("Exception in VideoStreamGetFrame");
}
 
//copy the image

byte[] bitmapData;
int address = dib + Marshal.SizeOf(bih);
 

Bitmap saveableBitmap;

if (bih.biBitCount < 16)
{
//copy palette and pixels
// Bitmap b = (Bitmap)Image.FromStream(aviStream);
bitmapData = new byte[bih.biSizeImage + Avi.PALETTE_SIZE];


}
else
{
//copy only pixels
bitmapData = new byte[bih.biSizeImage];
}
 
Marshal.Copy(new IntPtr(address), bitmapData, 0, bitmapData.Length);
 
//copy bitmap info
byte[] bitmapInfo = new byte[Marshal.SizeOf(bih)];
IntPtr ptr;
ptr = Marshal.AllocHGlobal(bitmapInfo.Length);
Marshal.StructureToPtr(bih, ptr, false);
address = ptr.ToInt32();
Marshal.Copy(new IntPtr(address), bitmapInfo, 0, bitmapInfo.Length);
 
Marshal.FreeHGlobal(ptr);
 
//create file header
Avi.BITMAPFILEHEADER bfh = new Avi.BITMAPFILEHEADER();
bfh.bfType = Avi.BMP_MAGIC_COOKIE;
bfh.bfSize = (Int32)(55 + bih.biSizeImage); //size of file as written to disk
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = Marshal.SizeOf(bih) + Marshal.SizeOf(bfh);
if (bih.biBitCount < 16)
{
//There is a palette between header and pixel data
bfh.bfOffBits += Avi.PALETTE_SIZE;
}
 
//write a bitmap stream
BinaryWriter bw = new BinaryWriter(new MemoryStream());
 
//write header
bw.Write(bfh.bfType);
bw.Write(bfh.bfSize);
bw.Write(bfh.bfReserved1);
bw.Write(bfh.bfReserved2);
bw.Write(bfh.bfOffBits);
//write bitmap info
bw.Write(bitmapInfo);
//write bitmap data
bw.Write(bitmapData);
 
Bitmap bmp = (Bitmap)Image.FromStream(bw.BaseStream);
saveableBitmap = new Bitmap(bmp.Width, bmp.Height);
Graphics g = Graphics.FromImage(saveableBitmap);
g.DrawImage(bmp, 0, 0);
g.Dispose();
bmp.Dispose();
 
bw.Close();

return saveableBitmap;
}
 

 

Please help me I am new to C#.
 
Thanks in Advance.
Posted 19-Jul-11 23:22pm
Edited 20-Jul-11 1:24am
v2
Comments
ankur.mu at 20-Jul-11 5:06am
   
If anyone knows to read 8bpp avi files & split them into bmp images. PLZ help me out.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I don't know of a way to convert them. Use DexterLib to get frames from an avi.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 21 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100