473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How can i to save byte array data to a stream and convert them to a bitmap instance

I cannot open TGA file use framework's class,so I am trying to convert TGA file to BMP file(or others).Now I have read the palette data and pixel data successfully.One way I create a temporary BMP file so I can open it again by use filestream.but it is stupid.

Can anyone tell me create bitmap instance by using palette data and pixel data?

any reply is very thanksful.
Feb 15 '08 #1
3 2304
Plater
7,872 Expert 4TB
Hmm, I'm not sure about creating a bmp from a pallette, but I seem to remember finding the MemoryStream object very usefull in creating bitmaps from byte data. About all I can offer though.
Feb 15 '08 #2
Hmm, I'm not sure about creating a bmp from a pallette, but I seem to remember finding the MemoryStream object very usefull in creating bitmaps from byte data. About all I can offer though.
very thanks for your guide!

well, I am failed to use MemmoryStream to create bitmap.
bitmap constructor:bitmap(stream);

When I use MemoryStream to create bitmap,The error window tell me parameter is wrong.so I have to find a way to create bitmap by using palette data and pixel data I get from the TGA file.

by the way,can you show me how to use MemoryStream to create bitmap?

thanks!
Feb 16 '08 #3
Hmm, I'm not sure about creating a bmp from a pallette, but I seem to remember finding the MemoryStream object very usefull in creating bitmaps from byte data. About all I can offer though.
Thank you for your reply.I found a way to solve my proble.Can you show me some advices:

byte[] paletteArr = readPaletteData();
byte[] pixelArr = readPixelData();

Bitmap bmp = new Bitmap(Width,Height);

for (int i = 0; i < Height;i++ )
{
for (int j = 0; j < Width; j++)
{
Color tmp;
int R = (int)paletteArr[pixelArr[i * Width + j] * 3 + 2];
int G = (int)paletteArr[pixelArr[i * Width + j] * 3 + 1];
int B = (int)paletteArr[pixelArr[i * Width + j] * 3 + 0];

tmp = Color.FromArgb(R,G,B);

bmp.SetPixel(j, Height - 1 - i, tmp);
}

}
return bmp;

Thanks!
Feb 16 '08 #4

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

Similar topics

7
by: Sergio Florez M. | last post by:
How can I convert a Bitmap to a byte array? I've searched all over and none of the code samples I've managed to find work. Actually, I just need to create a Byte array starting from an Image...
1
by: James Dean | last post by:
Could somebody tell me a quick way to write a whole byte array to a 1 bit per pixel bitmap if its possibleinstead of locking the bits and doing it like that..... *** Sent via Developersdex...
1
by: Andy Jacobs | last post by:
Hi, I have a row in a DataTable that contains colums of identifying data and I need to save a bitmap in that row. (I'm going to write the entire DataSet to disk as XML to be used by another...
9
by: Ivan Demkovitch | last post by:
Hi! I would like to know if I can save File on Server using server-side code? For example, I like to create thumbnail images and populate specific directory. Do I need specific permissions...
10
by: Niyazi | last post by:
Hi, I developed an application and I am using SQL Server 2000 developer edition. I create my database and I have also created tbl_USER table. I have an ID, RealName, UserName, and UserPassword...
10
by: Danny | last post by:
I am working on a project where I will receive xml documents from clients machines as a byte array. They will use the web browser navigate method to post the data to my ASP.NET page. I then pick up...
3
by: SveinErik | last post by:
Hi, I'm trying to find a method to save bmp, jpg and png files as ico files, 16x16 size. I have managed to convert and save bmp files to icon, but only in 32x32 size. I can't figure out how to save...
3
by: =?Utf-8?B?Um9nZWxpbw==?= | last post by:
I'm having the wierdest problem. I'm trying to save images into a SQL 2005 database. the field is just called "IMAGES" and hte data type is "image". here is my code to save //following code...
1
by: =?Utf-8?B?Y2hyaXNiZW4=?= | last post by:
Hi, Assuming I have a class/struct with only following types float, int, string what is the most efficient way to pack it to a single byte array before I send it out. I tried to use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.