Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Want to do something crazy with .bmp files
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01289665
Message ID:
01289744
Views:
15
Quick question.... you're doing this to convert to white:
SYS(2600, nOffset+nPos, 3, 0hFFFFFF)
...you know what it would be to convert it to black?

>As Borislav says, you can do this quite easy with the GDIPlusX library. But the GetPixel, SetPixel methods can be slow if you are converting an entire file. You are probably better off using the LockBits functionality and the SYS(2600) function to maniputate the pixels at the memory level.
>
>I took the liberty of creating a program for you, I hope you don't mind...this technique creates some interesting effects.
>
>Note, this may only work on images that are 24bpp. GIFs and indexed BMPs may require some extra coding.
>
>
>LOCAL oBmp AS xfcBitmap
>LOCAL oBmpData AS xfcBitmapData
>
>DO System.app
>
>cOpenFile = GETPICT()
>IF EMPTY(cOpenFile)
>  RETURN
>ENDIF
>cSaveFile = PUTFILE("Save","output.bmp","bmp")
>IF EMPTY(cSaveFile)
>  RETURN
>ENDIF
>
>WITH _SCREEN.System.Drawing
>  ** Open the file
>  oBmp = .Bitmap.FromFile(cOpenFile)
>  ** Lock the entire image bits
>  oRect = .Rectangle.New(0, 0, oBmp.Width, oBmp.Height)
>  oBmpData = oBMP.LockBits(oRect, ;
>          .Imaging.ImageLockMode.ReadWrite, ;
>          .Imaging.PixelFormat.Format24bppRGB)
>
>  IF oBmpData.Scan0 << 0
>    ** Calculate the memory size, there are 3 bytes per pixel (24bpp)
>    nBytes = oBmpData.Width * oBmpData.Height * 3
>    nOffset = oBmpData.Scan0
>    FOR nPos = 0 TO nBytes-1 STEP 3
>      nR = ASC(SYS(2600, nOffset+nPos, 1))
>      nG = ASC(SYS(2600, nOffset+nPos+1, 1))
>      nB = ASC(SYS(2600, nOffset+nPos+2, 1))
>
>      IF MOD(nR+nG+nB,2)=1  && Pixel Sum is Odd, convert to White
>        SYS(2600, nOffset+nPos, 3, 0hFFFFFF)
>      ENDIF
>
>      ** Progress:
>      IF MOD(nPos,300)=0
>        WAIT WINDOW NOWAIT NOCLEAR ;
>            "Converting: "+ALLTRIM(STR(nPos*100/nBytes))+"%"
>      ENDIF
>    ENDFOR
>    ** Unlock the memory bits
>    oBmp.UnlockBits(oBmpData)
>    ** Save changes to a BMP file
>    oBmp.Save(cSaveFile, .Imaging.ImageFormat.Bmp)
>    WAIT CLEAR
>  ENDIF
>ENDWITH
>
>RETURN
>
ICQ 10556 (ya), 254117
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform