I'm trying to have the user upload an image and allow the user to change the color of a part of the image and then display that image back to the user.
From what I've gathered, it's the easiest to use bmp files. My test images consist of 24-bit bmp files generated from MS paint of a single color.
I do not understand why the values correspond to a color: -1 for white, 0 for red, -96 for blue... etc.
For now, I'm using arbitrary screen dimensions and small enough bmp files so that they do not extend past the user's screen.
This is what I have so far (with notes to help myself out):
Code: Select all
#include "fbgfx.bi"
WindowTitle "ImageEditor"
Declare Sub mainMenu
Declare Sub changeColor
'To set the size of the screen
Dim As Integer DeskW, DeskH
ScreenControl fb.GET_DESKTOP_SIZE, DeskW, DeskH
ScreenRes DeskW+5,DeskH,32
print "Desktop Res: " + Str(DeskW) + "x" + Str(DeskH)
Dim Shared As Integer ScreenW,ScreenH
ScreenInfo ScreenW,ScreenH
Print "Screen Res: " + Str(ScreenW) + "x" + Str(ScreenH)
'Code to have user choose a file
Dim Shared As String userImage
Input "Enter the file name of a bmp: ", userImage
'Get the image dimensions
Dim Shared As UInteger imageW,imageH
'Could use ImageInfo here...
Open userImage For Binary As #1
'Note: Do not need quotes around "userImage" because the variable
'IS already a string
Get #1, 19, imageW
Get #1, 23, imageH
Close #1
'Let user know about the file
Print "Selected File: " + Str(userImage)
Print "Image Dimensions: " + Str(imageW) + "x" + Str(imageH)
Print "Press a key to load the image"
Sleep
Cls
'================================================================================================================
'Create a buffer to display image
'Image buffer info: http://bourabai.kz/einf/freebasic/TutFBgfxImgAndFontBuf.html
Dim imageBuffer As Any Ptr
imageBuffer = ImageCreate(imageW,imageH)
'Load the image
BLoad userImage, imageBuffer
Put (ScreenW/4,ScreenH/4), imageBuffer
'ImageDestroy(imageBuffer)
Print "Press a key to continue"
Sleep
Cls
'Gather the pixels
Dim Shared imageArray(0 To imageW-1,0 To imageH-1) As Byte
For Row As Integer = 0 to imageW-1
For Column As Integer = 0 to imageH-1
imageArray(Row,Column) = Point(Row,Column,imageBuffer)
Print imageArray(Row,Column);
Next Column
Print ""
Next Row
Sleep
Cls
mainMenu
'=======================================================================================================
Sub mainMenu
Cls
Dim mode As Integer
Print "1. Color"
Print "2. Exit"
Input "Enter the number corresponding to the desired operation: ", mode
If mode = 1 Then
changeColor
Elseif mode = 2 Then
end
Else
mainMenu
EndIf
End Sub
/'Change color by the bit
----------------------------------------------------------------------------------------------------------------------'/
Sub changeColor
Cls
Dim As Integer Lrow, Urow, Lcolumn, Ucolumn
Dim colorValue As Byte
'Display the range that the user is able to change the colors
Print "The bounds for the rows in your image are " + Str(LBound(imageArray,1)) + " to " +Str(UBound(imageArray,1)+1)
Print "The bounds for the columns in your image are " + Str(LBound(imageArray,2)) + " to " + Str(UBound(imageArray,2)+1)
Print ""
'Prompt the user for the area to modify
Print "Enter the desired bounds to change"
Input "Row Lower Bound: ", Lrow
Input "Row Upper Bound: " ,Urow
Input "Column Lower Bound: ",Lcolumn
Input "Column Upper Bound: ",Ucolumn
Input "Enter a number for the desired color value: " , colorValue
Print "Press a key to change the values to the desired value."
Sleep
Cls
'----------------------------------------------------------------
Print"Effected Values"
For Row As Integer = Lrow to Urow
For Column As Integer = Lcolumn To Ucolumn
imageArray(Row,Column) = colorValue
Print imageArray(Row,Column);
Next Column
Print ""
Next
Sleep
Cls
'-----------------------------------------------------------------
Print "Overall Values"
For Row As Integer = 0 to imageW-1
For Column As Integer = 0 to imageH-1
Print imageArray(Row,Column);
Next Column
Print ""
Next Row
Sleep
Cls
Print "Press a key to continue"
Sleep
End Sub
'==================================================================================================================
Cls
'Display image back to user (Not sure what to do here)
/'For loop to give values from imageArray to imageBuffer except that imageBuffer is not an array. . .
For x As Integer = 0 To imageW
For y As Integer = 0 To imageH
imageBuffer(x,y) = imageArray(x,y)
Next
Next
'/
'Need to find a way to copy values from imageArray to imageBuffer
Put (ScreenW/5,ScreenH/5), imageArray, (0,0)-(imageW,imageH),PSet
ImageDestroy(imageBuffer)
Sleep