Home › Forums › TWAIN Classic › Image Properties
- This topic has 1 reply, 1 voice, and was last updated 10 years, 10 months ago by si_ben.
- AuthorPosts
I’m trying to obtain an Image with the following specifications with no success…
.Tiff (FileType)
300 DPI (X,Y)
BitDepth (1)
Compression : CCITT T.6 (Group4)
W(InPixels) 2550
H(InPixels) 3300 (Letter Size)My Device doesn’t ‘support’ Compression or it won’t let me set it for some other reason and I also cannot use the
ICAP_ImageFileFormat.I set my DPI like so :
case (short)TwCap.IYResolution:
// (Capability, 300DPI)
t_Cap = new TwCapability(TwCap.IYResolution, 300);
rc = DScap(appid, srcds, TwDG.Control, TwDAT.Capability, TwMSG.Set, t_Cap);
// Check Result
if (rc != TwRC.Success)
{
Report_Status();
}
break;
I get success code from the set. Okay when I get to
// Declare new instance of Image Information
TwImageInfo iinf = new TwImageInfo();
// Get Current Image Info
rc = DSiinf(appid, srcds, TwDG.Image, TwDAT.ImageInfo, TwMSG.Get, iinf);
if (rc != TwRC.Success)
{
CloseSrc();
return pics;
}
// Set to Native Transfer
rc = DSixfer(appid, srcds, TwDG.Image, TwDAT.ImageNativeXfer, TwMSG.Get, ref hbitmap);
if (rc != TwRC.XferDone)
{
CloseSrc();
return pics;
}
my iinf DOES Reflect the capabilities I set (I also set like B&W and stuff). When my image is saved and I view the properties, the DPI is 96, BitDepth is 32 and its RGB.
Other notes, I chose not to show the UserInterface. So it never pops up. Right before I start scanning all the settings are proper. Im using NativeImageXfr.
The only thing that I can determine is that there is a function that runs :
public Image ImageFromIntPtr(IntPtr imagePtr)
{
BITMAPINFOHEADER bmpInfoHeader = new BITMAPINFOHEADER();
IntPtr bmpptr = GlobalLock(imagePtr);
IntPtr pixptr = GetPixelInfo(bmpptr, bmpInfoHeader);
Bitmap bitmap = new Bitmap(bmpInfoHeader.biWidth, bmpInfoHeader.biHeight);
Graphics graphics = Graphics.FromImage(bitmap);
IntPtr hdc = graphics.GetHdc();
SetDIBitsToDevice(hdc, 0, 0, bmpInfoHeader.biWidth, bmpInfoHeader.biHeight,
0, 0, 0, bmpInfoHeader.biHeight, pixptr, bmpptr, 0);
graphics.ReleaseHdc(hdc);
return (Image)bitmap;
}
Thing is I dont know how to manipulate the fields of BITMAPINFOHEADER(). Whats going on!! When I use Twirl and I set the same capabilities it comes out like it should with the 300 DPI. What am I doing that messes up this image??
I found one way to apply the compression and the DPI that I needed. Seems like there is more than one way to do it, but it was in my .Save() method [OfType(Image)].. Originally I was saving it just as (FileLocation, Image Extension)
Here is the following code that helped me obtain my result :
///
/// Save Button
///
///
///
private void button2_Click(object sender, EventArgs e)
{
List list = nessScanning1.ImagesList;
int i = 1;
foreach (Image img in list)
{
ImageCodecInfo myImageCodecInfo;
System.Drawing.Imaging.Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myImageCodecInfo = GetEncoderInfo("image/tiff");
myEncoder = System.Drawing.Imaging.Encoder.Compression;
myEncoderParameters = new EncoderParameters(1);
myEncoderParameter = new EncoderParameter(myEncoder, (long)EncoderValue.CompressionCCITT4);
myEncoderParameters.Param[0] = myEncoderParameter;
Bitmap image;
image = new Bitmap(img);
image.SetResolution(300,300);
image.Save(string.Format("C:\Temp\Pic_{0}.tiff", i++), myImageCodecInfo, myEncoderParameters);
}
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for (j = 0; j < encoders.Length; ++j)
{
if (encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
So if your scanner cannot support (CompressionFileType) there is still a way to obtain the result…
- AuthorPosts