473,802 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Twain and Stream questions

I have a project that is capturing pictures from my web cam. I can save the
image to a file and
load it back from the file into my image control no problem.
But I would like to either load it into the image control directly, or
into/out of a stream.

Given the GdipSaveImageTo Stream definition how do I create a parameter for
the stream parameter,
that gets me a usable stream when it is all done?

Or given the following code, any ideas on how to load the bitmap directly
from the twain source?
I have included the working code that saves/reads using a file, the function
definition and the
code that returns a pointer to the pixels of the bitmap.

Any help here would be appreciated.

(Code based on code I found on CodeProject)
[DllImport("gdip lus.dll", ExactSpelling=t rue, CharSet=CharSet .Unicode)]
internal static extern int GdipSaveImageTo Stream(IntPtr image, IntPtr
stream, [In] ref Guid Encoder, IntPtr encoderParams);

private void UseFile()
{
ArrayList pics = _source.Transfe rPictures();
EndingScan();
_source.CloseSr c();

IntPtr image = (IntPtr) pics[ 0 ];
IntPtr pBmp = GlobalLock(imag e) ;
IntPtr pixelData = GetPixelLocatio n(pBmp) ;

int st = GdipCreateBitma pFromGdiDib(pBm p, pixelData, ref image) ;

Guid clsid;
// Save to file and load from file
string fileName = String.Format(" C:\\temp\\FileN ame{0}.JPG", _picNo++);
if (!GdiPlus.GetCo decClsid(fileNa me, out clsid))
{
return;
}

if (File.Exists(fi leName)== true)
{
File.Delete(fil eName) ;
}

st = GdipSaveImageTo File(image, fileName, ref clsid, IntPtr.Zero);
_picture.Image = Image.FromFile( fileName);

GlobalFree(pBmp ) ;

}
protected IntPtr GetPixelLocatio n( IntPtr bmp )
{
BITMAPINFOHEADE R bitmapHeader = new BITMAPINFOHEADE R();
Marshal.PtrToSt ructure( bmp, bitmapHeader );

if( bitmapHeader.bi SizeImage == 0 )
{
bitmapHeader.bi SizeImage = ((((bitmapHeade r.biWidth *
bitmapHeader.bi BitCount) + 31) & ~31) >> 3) * bitmapHeader.bi Height;
}

int pixel = bitmapHeader.bi ClrUsed;
if( (pixel == 0) && (bitmapHeader.b iBitCount <= 8) )
{
pixel = 1 << bitmapHeader.bi BitCount;
}
pixel= (pixel * 4) + bitmapHeader.bi Size + (int) bmp;
return (IntPtr) pixel;
}

Nov 16 '05 #1
0 2405

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4829
by: ren | last post by:
Hello all, I'm looking for a method, to program TWAIN directly via API calls... Because the Twain OCX under Windows from Kodak is very slow... When I scan via software or the OCX, the TWAIN driver reloads everytime, I would like to keep it open, so I can close it when I exit the program. Thanx, Paul
0
2312
by: Neil Benn | last post by:
Hello, Has anyone had any success with python twain? I've downloaded it and run the module however, I'm getting a python core crash when calling to SourceManager.OpenSource. Needless to say, I've already tested the scanner with a twain based application and it didn't crash it so I'm guessing that the issue is with the python twain and not the scanner itself. Any tips, helps or <didn't you check that you wally comments> would
0
1982
by: Mikael Olofsson | last post by:
Hi all! Sorry for this rather lengthy post. It's a long preamble followed by a few questions based on that. Here's my situation: I am trying to write a specialized scanner utility for my own needs, and I want to use the module twain to control my scanner. I haven't used the twain module before, which is most certainly why I'm facing problems. My problem is to interprete some of the information I get from the scanner. The scanner, by...
3
12873
by: Konrad | last post by:
Hi Can you point me articles concerning using of twain drivers for grabbing image from camera. Thanks Konrad
4
1938
by: Chuck Rewood | last post by:
Can somebody here tell me how to access TWAIN from web ? I am gonna make a button to call TWAIN however, the twain.h from (www.twain.org) need some handle from hWnd (System.Windows.Form ??) What kind of wrapper or is there any namespace available ? Thanks, Riwut
2
3323
by: samuabreu | last post by:
I'm currently developing an API of Twain for Java. As Twain is implemented in C (and in fact Im writing and calling C methods from the app) I couldn't find a better group to search for twain development related issues. Here's my question: Does anyone know why when I negociate the capabilities ICAP_XRESOLUTION and ICAP_YRESOLUTION I'm getting all sorts of repeated random values like: 100, 100, 0, 0, 117, 5, 8, 0, 87, 78, 79, 83, 115,...
4
9802
by: Dustin Davis | last post by:
I'm hoping there is a TWAIN expert lurking here somewhere :) I'm writing a very customized application. The software will be set up in multiple location and will always have two types of scanners attached to the computer. The scanners are microfilm/fiche and a flatbed. So I've created a scanner setup screen where the user can select the twain source for the fiche/film scanner and the twain source for the flatbed scanner. I'm using an...
3
3333
by: =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post by:
I'm facing what i consider to be a serious problem, because i can't find the solution!!! I've made possible, for the software i'm developing, to aquire images from a scanner using WIA. The problem is that, when i aquire an image in, for instance, photo editor, i have the oportunity to choose between the several drivers availlable for the scanner. These drivers are WIA and Twain drivers. Both. So, the software i'm developing, must be...
1
8362
by: =?Utf-8?B?UmljYXJkbyBGdXJ0YWRv?= | last post by:
I'm facing what i consider to be a serious problem, because i can't find the solution!!! I've made possible, for the software i'm developing, to aquire images from a scanner using WIA. The problem is that, when i aquire an image in, for instance, photo editor, i have the oportunity to choose between the several drivers availlable for the scanner. These drivers are WIA and Twain drivers. Both. So, the software i'm developing, must be...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10542
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, 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...
0
10309
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 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...
0
10068
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 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...
0
9119
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
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 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...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
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
3
2968
bsmnconsultancy
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...

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.