Re: image graphics drawing confusion

From: Bob Powell [MVP] (bob_at__spamkiller_bobpowell.net)
Date: 07/31/04


Date: Sat, 31 Jul 2004 13:14:46 +0200

I actually haven't written any C++ for about 5 years... The FAQ does have a
bit of a managed code bias. Things will be changing on there very soon
though and C++ will always be an important language.

I will do something along those lines. To ensure that you see the articles I
suggest you subscribe to the RSS feed for the FAQ.

-- 
Bob Powell [MVP]
Visual C#, System.Drawing
The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
"cwineman" <me@home.com> wrote in message news:410aad96$1_2@127.0.0.1...
> I still don't get it. Maybe I'm dense.I don't see how (or why) one of
these
> image objects could (would) have a second buffer for storing a thumbnail
> version of the original. What good would it do, since the thumbnail
version
> is really a modification of the original, to the width/height that the
> caller wants?
>
> Anyway, I rewrote my resizing function to look similar to the code you had
> in your previous post. Now everything works just like a want.Thanks.
>
> I guess maybe your FAQ is only for managed .NET. I have used the
> System.IO.MemoryStream to create an image from a file buffer in memory. I
> keep getting confused because I am writing imaging code using GDI+ in
> managed and unmanaged code. What I was actually having problems with was
> loading an image from a buffer in unmanaged C++. There is a function
> Gdiplus::Bitmap::FromStream
>
> And it requires an IStream. I couldn't find an equivalent of
> System.IO.MemoryStream so I had to use all of those mysterious COM
> functions. So I guess I should ask you, in unmanaged C++, do you know of a
> better way to load a Bitmap from a file buffer in memory?
>
> I appreciate you help. Have a good weekend.
>
> "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> news:uDgKVrmdEHA.2352@TK2MSFTNGP09.phx.gbl...
> > The point I'm trying to make is that if the original file had a
thumbnail
> it
> > would be in a different part of the file structure and would look
similar
> to
> > the original. Even though you changed the bits on the real image, maybe
> the
> > thumbnail bits didn't get changed. When you extracted the thumbnail
again
> it
> > just gave you back the old, unaltered thumbnail stretched to whatever
size
> > you asked for.
> >
> > I will certainly put an article in there for loading an image from a
file
> > buffer in memory. I did something like this a while ago for a customer
who
> > had a bitmap in a byte buffer. I handed the byte buffer to a memory
stream
> > and read the file in from the memory stream. That might work as an
> > alternative to your CreateStreamOnHGlobal method. You can construct a
> memory
> > stream with a byte buffer and hand the memory stream to the FromStream
> > method.
> > -- 
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > The Image Transition Library wraps up and LED style instrumentation is
> > available in the June of Well Formed for C# or VB programmers
> > http://www.bobpowell.net/currentissue.htm
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/gdiplus_faq.htm
> >
> > The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
> > Windows Forms Tips and Tricks RSS:
http://www.bobpowell.net/tipstricks.xml
> > Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
> >
> >
> >
> >
> >
> >
> > "cwineman" <me@home.com> wrote in message news:410a7827$1_2@127.0.0.1...
> > > Hmm. I'm not sure how it can have a pre-defined thumbnail. I
dynamically
> > > create a thumbnail of the size I desire. If there is a pre-difined
> > > thumbnail, how large is it? Wouldn't it get over-written?
> > >
> > > I've checked out your faq several times in trying to answer some of my
> > > imaging questions. One thing you might consider adding is something
> about
> > > how to load an image from a file buffer in memory. I had trouble with
> > that,
> > > and it seems like something that would be a pretty common need for
> > > developers. I eventually had to use a bunch of COM calls (which I know
> > > nothing about) to load from an IStream. The code is below. Is there
some
> > > easier way than that? Alot of people were saying I should write my own
> > > IStream implementation. Seems like a lot of work just to load an image
> > from
> > > memory.
> > >
> > > Thanks for you help.
> > >
> > > Gdiplus::Bitmap * CSecurLinxImage::LoadBitmap( unsigned char *
> fileBuffer,
> > > int length )
> > >
> > > {
> > >
> > > HGLOBAL m_hMem = GlobalAlloc( GMEM_FIXED, length );
> > >
> > > BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
> > >
> > > memcpy( pmem, fileBuffer, length );
> > >
> > > IStream* pstm;
> > >
> > > CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);
> > >
> > > Gdiplus::Bitmap * bitmap = Gdiplus::Bitmap::FromStream( pstm, FALSE );
> > >
> > > GlobalUnlock( m_hMem );
> > >
> > > pstm->Release();
> > >
> > > return bitmap;
> > >
> > > }
> > >
> > >
> > > "Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
> > > news:emlJytkdEHA.524@TK2MSFTNGP09.phx.gbl...
> > > > The GDI+ FAQ has articles on changing the resolution of an image and
> > > drawing
> > > > an image that will explain the process in more detail. Here's how to
> > > reduce
> > > > an image to 50% it's size...
> > > >
> > > > Bitmap bm=Bitmap.FromFile("myImage.bmp");
> > > > Bitmap tmp=new Bitmap(bm.Width/2, bm.Height/2);
> > > > Graphics g=Graphics.FromImage(tmp);
> > > > g.DrawImage(bm,new
> > > >
> > >
> >
>
Rectangle(0,0,tmp.Width,tmp.Height),0,0,bm.Width,bm.Height,GraphicsUnit.Pixe
> > > > l);
> > > > g.Dispose();
> > > > bm.Dispose();
> > > > tmp.Save(......); // save the half-size file
> > > >
> > > > Some JPEG images have a pre-defined thumbnail. This would have been
> > > > generated before you modified the image. I'm assuming that you
changed
> > the
> > > > bits for the main image, saved the thing, including the old
thumbnail
> > and
> > > > when you extract the thumbnail the software decides to use the old,
> > > > unchanged bits of the supplementary image, not the new ones.
> > > >
> > > >
> > > > -- 
> > > > Bob Powell [MVP]
> > > > Visual C#, System.Drawing
> > > >
> > > > The Image Transition Library wraps up and LED style instrumentation
is
> > > > available in the June of Well Formed for C# or VB programmers
> > > > http://www.bobpowell.net/currentissue.htm
> > > >
> > > > Answer those GDI+ questions with the GDI+ FAQ
> > > > http://www.bobpowell.net/gdiplus_faq.htm
> > > >
> > > > The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
> > > > Windows Forms Tips and Tricks RSS:
> > http://www.bobpowell.net/tipstricks.xml
> > > > Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
> > >
> > >
> >
> >
>
>


Relevant Pages

  • Re: image graphics drawing confusion
    ... since the thumbnail version ... System.IO.MemoryStream to create an image from a file buffer in memory. ... > and read the file in from the memory stream. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: image graphics drawing confusion
    ... store a thumbnail version of an image in their file structure. ... System.Drawing.Image object using one of these thumbnail-encapsulating jpg ... The Image object just has a buffer for the original image data, ... > System.IO.MemoryStream to create an image from a file buffer in memory. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: image graphics drawing confusion
    ... thumbnail PropertyItem if it exists and does not necessarily construct the ... Answer those GDI+ questions with the GDI+ FAQ ... The Image object just has a buffer for the original image ... >> System.IO.MemoryStream to create an image from a file buffer in memory. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: image graphics drawing confusion
    ... The point I'm trying to make is that if the original file had a thumbnail it ... I handed the byte buffer to a memory stream ... Answer those GDI+ questions with the GDI+ FAQ ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Im stumped!!
    ... > is the problem In the main loop that creates the vertex and index buffers, ... > write to some memory that I shouldn't have, but If I'm wrong, please ... > allows the program to run without access violations. ... a.c.l.l.c-c++ FAQ mirror: http://nullptr.merseine.nu:8080/acllcc++.html ...
    (alt.comp.lang.learn.c-cpp)

Loading