If I read a bitmap image from one file and save it to another the save
operation is slow unless I draw on the image. In other words,
Image inputImage = Image.FromFile( @"c:\temp\sourc e.bmp" );
using ( Graphics g = Graphics.FromIm age( inputImage ) )
{
g.DrawLine( new Pen(Brushes.Whi te), 0, 0, 1, 1 );
}
inputImage.Save ( @"c:\temp\sink. bmp", ImageFormat.Bmp );
is many times faster than
Image inputImage = Image.FromFile( @"c:\temp\sourc e.bmp" );
inputImage.Save ( @"c:\temp\sink. bmp", ImageFormat.Bmp );
So what side effect is created by DrawLine that speeds up the Save?
I have a small console app I called ImageCopy that demostrates what
I'm talking about. The results go like this on my machine using a
3.5Mb .bmp file:
C:\>ImageCopy c:\temp\source. bmp c:\temp\sink.bm p nodrawing
no drawing
READ: 00:00:00.031250 0
DRAW: 00:00:00
SAVE: 00:00:00.343750 0
TOTAL: 00:00:00.375000 0
C:\>ImageCopy c:\temp\source. bmp c:\temp\sink.bm p draw
with drawing
READ: 00:00:00.031250 0
DRAW: 00:00:00
SAVE: 00:00:00.015625 0
TOTAL: 00:00:00.046875 0
The save time differs by a factor of about 20x in this run. On a 5x
slower CPU the difference was more like 60x.
Here's the source for my ImageCopy console application (C#):
using System;
using System.Drawing;
using System.Drawing. Imaging;
namespace ImageCopy
{
class ImageCopy
{
[STAThread]
static void Main(string[] args)
{
DateTime startTotalTime = DateTime.Now;
DateTime startReadTime = DateTime.Now;
Image inputImage = Image.FromFile( args[0] ); // Read
TimeSpan readDuration = DateTime.Now - startReadTime;
DateTime startDrawTime = DateTime.Now;
if ( args.Length == 3 && args[2] == "draw" )
{
Console.WriteLi ne( "with drawing" );
using ( Graphics g = Graphics.FromIm age( inputImage ) )
{
g.DrawLine( new Pen(Brushes.Whi te), 0, 0, 1, 1 );
}
}
else
{
Console.WriteLi ne( "no drawing" );
}
TimeSpan drawDuration = DateTime.Now - startDrawTime;
DateTime startSaveTime = DateTime.Now;
inputImage.Save ( args[1], ImageFormat.Bmp ); // Save
TimeSpan saveDuration = DateTime.Now - startSaveTime;
TimeSpan totalDuration = DateTime.Now - startTotalTime;
Console.WriteLi ne( " READ: " + readDuration.To String() );
Console.WriteLi ne( " DRAW: " + drawDuration.To String() );
Console.WriteLi ne( " SAVE: " + saveDuration.To String() );
Console.WriteLi ne( "TOTAL: " + totalDuration.T oString() );
}
}
I run tests from a .bat file that contains these two lines:
imagecopy c:\temp\source. bmp c:\temp\sink.bm p dontdraw
imagecopy c:\temp\source. bmp c:\temp\sink.bm p draw 0 2148 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: F. Hall |
last post by:
If I read a bitmap image from one file and save it to another the save
operation is slow unless I draw on the image. In other words,
Image inputImage = Image.FromFile( @"c:\temp\source.bmp" );
using ( Graphics g = Graphics.FromImage( inputImage ) )
{
g.DrawLine( new Pen(Brushes.White), 0, 0, 1, 1 );
}
inputImage.Save( @"c:\temp\sink.bmp", ImageFormat.Bmp );
|
by: Detlef Huettenbach |
last post by:
I was trying to convert a Windows Forms prototype
application to an ASP.NET solution that makes use of
loading data streams into the Image Web/Windows control.
For WinForms no problem. However in ASP.NET, the image
control does not display tiffs,pngs,.. still it does
display gif-streams. Memory stream writing into a gif-
stream of the tiff and other streams likewise fails,
although the streams seem to be filled correctly.
On top of that,...
|
by: Miguel Dias Moura |
last post by:
Hello,
I created a page in ASP.Net / VB where i placed an image.
The image's file to use should be "images/imgN.gif", where N is the
value of the parameter Number passed to the page in the URL.
Can someone tell me how to do this?
Thank You,
|
by: Scott Schluer |
last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG)
to a B&W photo?
Thanks,
Scott
|
by: Jeronimo Bertran |
last post by:
Hello,
I am using a rendering aspx page to display a database image on an Image
control. When the database record is retrieved, I am saving the bitmap
to a session variable for the rendering aspx to load. Here is the code
on the rendering page:
CODE FOR ImageForm.aspx
private void Page_Load(object sender, System.EventArgs e)
| |
by: Michael |
last post by:
I'm trying to use the Bitmap class's Save Method to save a Bitmap as a
GIF. My code runs fine, and converts the image, but the quality is
not anywhere close to as good. I know that GIF quality is not a good
as a BMP's but, is there a way to convert the image while preserving
its quality. Any help would be greatly appreciated. Here's what I
have...
Public Enum ImageType
Bmp = 0
Emf = 1
|
by: tshad |
last post by:
I am trying to set up an Image authorization where you type in the value
that is in a picture to log on to our site.
I found a program that is supposed to do it, but it doesn't seem to work.
It should put a blue and yellow box on the page with "This is a test" as
part of the picture. But what I get is a broken Gif.
The other problem is that I can't view the source???? The view source is
disabled for this page. What causes this?
|
by: Emmi |
last post by:
Hi there, just starting in PHP and found some code that would switch out pages depending on link clicked. It worked great loading different pages. Then I thought I would try the same code by calling an image instead of a page. When I use the following code, what happens is the rest of the page loads fine, but instead of getting an image I'm getting junk on the screen. Could anyone tell me what I'm doing wrong?
Here is my script:
<?php ...
|
by: Erakis |
last post by:
Hi,
I need to put a very large image as background (1030px X 774px) on the
main window of my application. Also, on this window I need to add
transparent Usercontrol, Panel and Label.
Every time I need to refresh or replace a Usercontrol, the redraw is
doing very TOO slow and there some flickering... I try to activate the
double buffering but without success. Same refresh speed.
|
by: Marcolino |
last post by:
Hi,
I have simple needs but I don't know how to implement it.
I have application that create Dynamic Button. I need to set the image
on this button, getting the icon from a form.
So pratically I need to convert dinamically a Form.Icon to
Button.Image runtime, but i don't know how.
Any help would be appreciated.
Many Thanks
|
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,...
| |
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...
|
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| | |