ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to determine file type on WIA device?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

skippix

USA
68 Posts

Posted - Jun 29 2014 :  13:08:55  Show Profile  Reply
I've got some code that iterates through a list of files found on a WIA device attached to my laptop in order to copy them to my laptop.

It had been working just fine, but when I attached my son's iPhone, it started dying with an "out of memory" error. I was able to trace it to the fact my son had been making movies with his phone.

ImageEnView1.IO.WIAParams.GetItemPropertyAttrib(WIA_IPS_XRES,nil,attrib,values);
  iImageEnIO := TImageEnIO.Create(nil);
  try
    Gauge1.MaxValue := TreeView1.Items.Count - 1;
    for i := 1 to TreeView1.Items.Count - 1 do
    begin
      { Get the node }
      iNode := TreeView1.Items.Item[i];

      {RIGHT HERE is where I'd like to test to see if the file is a jpg or not}
      if (FileIsNotAJpg) then
        Continue;

      LabelProgress1.Caption := 'Transferring image to ' +
        IncludeTrailingPathDelimiter(Folder1.Text) + iNode.Text + '.jpg';
      { Force to saveing as jpeg setting the desired image format }
      iImageEnIO.WIAParams.TransferFormat := ietfJpeg;
      iImageEnIO.WIAParams.ProcessingBitmap := iImageEnIO.IEBitmap;
      iImageEnIO.WIAParams.GetItemPropertyAttrib();
      { After the image is loaded save the image to disk }
      iImageEnIO.WIAParams.SaveTransferBufferAs :=
        IncludeTrailingPathDelimiter(Folder1.Text) + iNode.Text + '.jpg';
      { Transfer the image from the camera to iImageEnIO }
      iImageEnIO.WIAParams.Transfer(TIEWiaItem(iNode.Data), False);
      { Update progress gauge. }
      Gauge1.Progress := i;
      Gauge1.Update;
      if ACancel then
        Break;
    end;


I'm stuck on what code will determine "FileIsNotAJpg". I'm thinking it involves WIAParams.GetItemPropertyAttrib(WIA_IPA_FORMAT,nil,attrib,values);
and WiaImgFmt_JPEG, but I have no clue as to what the syntax is to make this work.

Thanks for your help!

xequte

39053 Posts

Posted - Jun 29 2014 :  22:07:28  Show Profile  Reply
Hi

Have you tried using the WIAScanner demo, selecting the problematic item and reviewing what item properties are returned for it? (You might also want to add a line item for WIA_IPA_FORMAT, though note that this is already assigned by setting TransferFormat to ietfJPEG to WiaImgFmt_JPEG).



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

skippix

USA
68 Posts

Posted - Jun 30 2014 :  14:00:52  Show Profile  Reply
Thanks! It took a bit to figure it out, but the following is what I came up with and it seems to be working.


        SelectedItem := TIEWiaItem(iNode.Data);
        with ImageEnView1.IO.WIAParams do
          s := GetItemProperty(WIA_IPA_FILENAME_EXTENSION, SelectedItem);

        if (LowerCase(s) <> 'jpg') then
          Continue;


What would really be useful, though, would be knowing how you populate a TreeView...
Go to Top of Page

xequte

39053 Posts

Posted - Jun 30 2014 :  19:22:24  Show Profile  Reply
Why not just model the code of TIEWia.FillTreeView?

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

skippix

USA
68 Posts

Posted - Jul 01 2014 :  03:25:25  Show Profile  Reply
quote:
Why not just model the code of TIEWia.FillTreeView?

until you suggested it, i didn't realize i had the source code! since the debugger stepped over the call to FillTreeView, i didn't think to look. that will be very handy in the future...thanks!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: