473,471 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to draw an image very fast from a file in the stream format?

6 New Member
Hi there,

I would like to display thousands of image files on the screen. I am using the following code to display them:

Bitmap Origbmp = new Bitmap(Filename);
bmp = new Bitmap(Origbmp.Width, Origbmp.Height, PixelFormat.Format32bppArgb);
Graphics gr = Graphics.FromImage(bmp);
gr.DrawImage(Origbmp, 0, 0, Origbmp.Width, Origbmp.Height);


but now the files are in a special format that cannot be displayed using the above code. So I have to load the file into memory, change some particular bytes and then pass them to the Origbmp. so I do as follows:

//read the file into a stream
byte[] fileInBytes = File.ReadAllBytes(Filename);
Stream fileInStream = new MemoryStream(fileInBytes);
fileInStream.Write(Newbytes, pos,len);
Bitmap Origbmp = new Bitmap(fileInStream);
bmp = new Bitmap(Origbmp.Width, Origbmp.Height, PixelFormat.Format32bppArgb);
Graphics gr = Graphics.FromImage(bmp);
gr.DrawImage(Origbmp, 0, 0, Origbmp.Width, Origbmp.Height);

is there anyway to do it faster? How can I read the file directly to a stream rather than first reading it to a byte array and then to a stream?
Is there any other way to do the whole thing more efficient and faster?
Aug 18 '10 #1
3 1882
Aimee Bailey
197 Recognized Expert New Member
If the intention is to modify pixels on the bitmap before it's drawn, wouldn't you be better using the Graphics library?

Aimee.
Aug 26 '10 #2
mina2040
6 New Member
Hi Aimee,

thanks for your post. The intention is to modify some buyes of the file before drawing it on the screen. Has this make it more clear?
Aug 26 '10 #3
mzmishra
390 Recognized Expert Contributor
I did something like below in my code to display image in a webpage.

byte[] bArrImage = null;
MemoryStream memoryStream = null;
System.Drawing.Image Image = null;
bArrImage = //code to get the image from database
memoryStream = new MemoryStream(bArrImage);
Image = Bitmap.FromStream(memoryStream);
Aug 27 '10 #4

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

Similar topics

6
by: Ali Eghtebas | last post by:
Hi, Need fast help pls: Format (1 "###,###.##") = "1" <<<<----- OK! Format (0, "###,###.##") = "" <<<<----- WHY? How can I make this work with Zero?
13
by: lkrubner | last post by:
Suppose I need to get an image as a stream of bytes. I want to store this in a variable and then embed it in some Postscript code. In my Postscript code, the image might look like this: {<...
4
by: | last post by:
I cant seem to find the commmand that I can use to save an image file from a url to my local harddrive. I am looking to save a jpg from a webpage that I have screen scraped. I have a web...
3
by: frustrated | last post by:
I am trying to share a file stream between two threads, but havent got a clue as to how to do it. The first thread will be reading the file, and the second thread will(/might) be writing to the...
7
by: Lee | last post by:
Hi, I'm a stream virgin and am attempting to output strings to a file. My approach is to write the string initially to a 'stringstream' and only when complete write the stringstream to the file...
2
by: myjpa1 | last post by:
Hi, all, I want to draw image directly onto top of screen, which simulates the OSD(on screen display) effects. However, class Graphics must link to certain controls, that cannot be used to draw...
1
by: saetiagous | last post by:
Hello, I have a file stream, which retreives an image from my database and holds in its temp. 'hand'. How do i put this into an Image object on my asp.net webpage??? PLease help someone,...
2
by: =?Utf-8?B?S3VuIE5pdQ==?= | last post by:
Dear all, I'm new here and I'm sorry to trouble. But I've got the following problem when trying to draw a PNG file on a panel. My code is like this: Image mapImage = Image.FromFile...
3
by: Claire | last post by:
Hi, I read image data from a database and cache them locally to file via a filestream. One of my users commented that his application isnt showing images. On checking his file cache I found that...
1
by: rahulrsh | last post by:
I am doing an image processing project which requires multiple threads to operate and write to an output file stream... Is is possible by some function to read and write specific locations of a file...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.