CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2008
    Posts
    6

    HOWTO add watermark into RAW img file

    Hi all,

    I am trying to modify a virtual printer open source code.
    Basically, the virtual printer will generate a raw img file, and I wanna to add text/image watermark before transfer to other image formats, such as JPG, PDF.

    Does anyone have any idea about how to do this in C/C++?

    Thank you.

    James

  2. #2
    Join Date
    Mar 2009
    Posts
    22

    Re: HOWTO add watermark into RAW img file

    the most straight forward way I can think of would be to manually copy the pixels of the watermark (I'm assuming image watermark here, but certainly you can make text into image) into the target raw image. Because the image format is raw, it would be easy to manipulate directly but this can be a slow implementation. Depending on what kind of watermark you want (is it in background or in foreground, is it transparent or partially transparent, ...) this may be a good or a bad idea. Can you describe the nature of your watermark image in more details?

  3. #3
    Join Date
    Nov 2008
    Posts
    6

    Re: HOWTO add watermark into RAW img file

    Freeman0119

    Thank you for reply.
    I am thinking to add text directly into the raw img file instead of add watermark image.
    So in this case, user can have the options abt what text they want to add.

    However, I am just start reading the hdc and some textout functions.
    I need some idea to kick out.

    I don't think the transparent watermark text is necessary, and of course it would even better to have it.
    But I haven't figure out how to do it.

    Thank you.

    James

  4. #4
    Join Date
    Mar 2009
    Posts
    22

    Re: HOWTO add watermark into RAW img file

    well so I can assume you are programming for Windows. I would do it this way:

    1. create a memory dc (using CreateCompatibleDC())
    2. create a bitmap (using CreateBitmap()) and select it into the memory dc (using SelectObject());
    3. create a font with whatever face, size, ... you like (using CreateFont()), select it into the memory dc (using SelectObject());
    4. render the desired text into the memory dc (using TextOut())
    5. obtain the raw data of the bitmap in the memory dc (using GetDIBits()), which should contain the drawn text now, so this is your watermark image raw data
    6. manually copy the watermark image data into specific position of your target image data. you can choose not to overwrite whenever the watermark pixel is white (default background color of your watermark image), in this way you make your watermark transparent in background. you can also blend the color of your watermark text pixels to the target image pixels at some weight, in this way you make your watermark texts half transparent. If you don't like it to be transparent, just directly overwrite. this is the good thing about raw data -- you can do whatever you want manually in a very straight forward way.

    if you have the target image in the format of an HBITMAP, you can do the copying by calling BitBlt() function. transparency can also be achieved but a little bit tricky. blending I don't know how to do. the advantage of using BitBlt() is that it is usually a lot faster than manually copying the data blocks.

    just a rough idea, I haven't tested it out so there might be glitches... also if anyone knows a better way plz point out...

  5. #5
    Join Date
    Nov 2007
    Posts
    613

    Re: HOWTO add watermark into RAW img file

    First of all, do you know EXACTLY the format of your raw file ? There are lots of different raw formats many of them quite sophisticated. If you know it let us know it too.

    I would suggest you first to convert the raw to a standard image format, then apply text or watermark. Writing directly to a raw file can be very difficult, you can do it only with byte level processing. Windows doesn't offer any support to do that.

    BTW, you can use HDC only with bitmaps.

  6. #6
    Join Date
    Nov 2008
    Posts
    6

    Re: HOWTO add watermark into RAW img file

    to Freeman0119,

    Thank you for your detailed steps.
    It is very helpful for me.
    I appreciate it.


    to Srelu,

    Thank your for your reply.
    I checked the header of the raw file.
    It seems it is a PCL file or PJL. Sorry I am not familiar with the image processing.
    Should I convert it into other file format before creating DC?


    Thank you for you guys' help.
    James

  7. #7
    Join Date
    Mar 2009
    Posts
    22

    Re: HOWTO add watermark into RAW img file

    I'm not familiar with these formats. Google tells me they are vector formats for printers, in that case what I talked about is not useful to you. I guess srelu's suggestion would be your best bet -- convert them into a standard format (like HBITMAP) and use an API (like BitBlt()) to do the data manipulation.

  8. #8
    Join Date
    Nov 2007
    Posts
    613

    Re: HOWTO add watermark into RAW img file

    Most image capturing device manufacturers have their own file formats. Only they know them. You should check if the manufacturer offers some some sort of API (libraries, dlls, help files) to deal with the image. If they do, most likely you'll find file format conversion functions.

    If no API is provided, you may try to inspect the raw file byte by byte and try to understand what's in it, but frankly I think your chances to get anywhere are slim. You may try to capture a completely white image and see what's in the file, then a completely black one and see again, then images with simple shapes. But I'm not sure it will yield any result.

    Well, if you manage to obtain a bitmap, convert it to a 32 bit/pixel color format, then use the AlphaBlend function to do the actual watermarking.

  9. #9
    Join Date
    Apr 2009
    Posts
    1

    Re: HOWTO add watermark into RAW img file


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured