Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 754
  • Last Modified:

Will StretchBlt work in .NET?

Hi, Experts -
I have an app that worked pretty well in VB6 that I'm importing to VB.net. Part of the VB6 code would take a custom font bitmap (6x8), write it into a picturebox, and then I would use stretchblt to bring it to the size that was needed in the display.

I've tried everything I can think of using the Graphics object in .net - it works, but the characters and images are all "fuzzy" as though "smoothing" is turned on. If I do a screen shot and zoom in, you can see where the 2-color (black font on khaki background) bitmap is no longer 2 colors and ONLY 2 colors - there are 'shades' around the lines.

I have tried turning smoothing to 'none' in the graphics objects, as well as playing with the pixel renderinghint, text contrast, and a bunch of other stuff. I cannot get the old "stretchblt" to work in .net. Can anyone suggest how to make the expanded images have SHARP definitions? MANY, MANY THANKS!
0
LongDave
Asked:
LongDave
  • 4
  • 2
1 Solution
 
Luis PérezSoftware Architect in .NetCommented:
Why doesn't StretchBlt work for you? Did you tried with this declaration?

Public Declare Function StretchBlt Lib "gdi32.dll" (ByVal hdcDest As IntPtr, ByVal nXOriginDest As Integer, ByVal nYOriginDest As Integer, ByVal nWidthDest As Integer, ByVal nHeightDest As Integer, ByVal hdcSrc As IntPtr, ByVal nXOriginSrc As Integer, ByVal nYOriginSrc As Integer, ByVal nWidthSrc As Integer, ByVal nHeightSrc As Integer, ByVal dwRop As TernaryRasterOperations) As Boolean

For the dwRop parameter, you can use
For the IntPtr parameters, you can obtain it by using:
Dim pHDC As IntPtr = [graphics_object].GetHdc()
For example:
Dim pHDC As IntPtr = e.Graphics.GetHdc()

For the dwRop parameter, use this enum:

Public Enum TernaryRasterOperations As UInteger
    SRCCOPY = 13369376     'dest = source
    SRCPAINT = 15597702    'dest = source OR dest
    SRCAND = 8913094       'dest = source AND dest
    SRCINVERT = 6684742    'dest = source XOR dest
    SRCERASE = 4457256     'dest = source AND (NOT dest )
    NOTSRCCOPY = 3342344   'dest = (NOT source)
    NOTSRCERASE = 1114278  'dest = (NOT src) AND (NOT dest)
    MERGECOPY = 12583114   'dest = (source AND pattern)
    MERGEPAINT = 12255782  'dest = (NOT source) OR dest
    PATCOPY = 15728673     'dest = pattern
    PATPAINT = 16452105    'dest = DPSnoo
    PATINVERT = 5898313    'dest = pattern XOR dest
    DSTINVERT = 5570569    'dest = (NOT dest)
    BLACKNESS = 66     'dest = BLACK
    WHITENESS = 16711778   'dest = WHITE
End Enum

Try this and tell me if it worked.
0
 
LongDaveAuthor Commented:
Sorry for the delay - had to go to my son's hockey game ... yes, this is the same declaration I used. The return value is non-zero, which indicates it should be working-but nothing appears on the picturebox image.

I'm making a graphics object of the image of a picturebox, then passing the IntPtr from it to a different class. I'm expecting the hdc (this is the desthdc)  to be static, and in use continuously. (Is this wrong?) The second hdc (srchdc) is generated from a listimage.images(x) object.

I really wish I knew why the graphics object DrawImage method is doing this to me!  I'll revisit the stretchblt, but do you have any other ideas? Like I say, it actually works with the graphics objects, it just doesn't look "crisp"  like the original app did.

Thanks!

0
 
LongDaveAuthor Commented:
I've attached the main part of the code that is giving me problems. The sub "SetUpDisplayBuffer" creates an in-memory bitmap called "ClockDisplayBuffer", and an associated graphics object CDFGraphic. I know this routine works, because if I transfer the ClockDisplayBuffer bitmap to a PictureBox in StretchImage mode, the picture comes through fine (except a bit fuzzy - the source of this whole question)

WriteOnly Property AccessBuffer passes a PictureBox from the main form. A Graphics object is created from the PictureBox.Image. and I then attempt to use StretchBlt to copy the image from CDFGraphic to g. But nothing shows up in the PictureBox. Any hints would be greatly appreciated.

    Public Sub SetUpDisplayBuffer(ByVal tWidth As Integer, ByVal tHeight As Integer, ByVal tformat As Image)
        BufferWidth = tWidth
        BufferHeight = tHeight
 
        Dim g As Graphics = Graphics.FromImage(tFormat)
        ClockDisplayBuffer = New Bitmap(21 * CellWidth, 8 * CellHeight, g)
        CDFGraphic = Graphics.FromImage(ClockDisplayBuffer)
        CDFGraphic.SmoothingMode = SmoothingMode.None
        OutHeight = CDFGraphic.VisibleClipBounds.Height
        OutWidth = CDFGraphic.VisibleClipBounds.Width
    End Sub
 
    WriteOnly Property AccessBuffer() As System.Windows.Forms.PictureBox
        Set(ByVal value As System.Windows.Forms.PictureBox)
 
            Dim g As Graphics = Graphics.FromImage(value.Image)
            Dim Thishdc As IntPtr = g.GetHdc
            Dim Thathdc As IntPtr = PS.CDFGraphic.GetHdc
            Dim ans As Integer = StretchBlt(Thishdc, 1, 1, value.Width, value.Height, Thathdc, 0, 0, PS.OutWidth, PS.OutHeight, 13369376)
            PS.CDFGraphic.ReleaseHdc()
            g.ReleaseHdc()
            ScreenIsReady = False
        End Set
    End Property

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Luis PérezSoftware Architect in .NetCommented:
If you could post the complete code, the maybe I can help you.
0
 
LongDaveAuthor Commented:
The complete code is 4450 lines, not including about 44k of resources - it might be a bit cumbersome to post it.
0
 
LongDaveAuthor Commented:
Although I didn't get Stretchblt to work, I did create a workaround. Basically I had to re-create the fonts an a pixel-by-pixel basis, multiplying the x and y coordinates based on the scale factor. By creating them in this fashion, rather than using stretchblt, everything worked out.

Not the solution I would have liked, however! :(
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now