DrawImage blurry
DrawImage blurry
I am using DrawImage() to draw a zoomed version of an image (the image sizes are multiplied by 'zoom', which is a float). However, the enlarged versions come out blurry. Is there a way to stop this and have it just enlarge it 'raw'?
Alternatively, is there a way to draw sub-pixels on a canvas (where 'zoom' would be 0.25, 0.5, etc.) for when the image is zoomed out? I have all the pixel data stored in an array.
Alternatively, is there a way to draw sub-pixels on a canvas (where 'zoom' would be 0.25, 0.5, etc.) for when the image is zoomed out? I have all the pixel data stored in an array.
Re: DrawImage blurry
How are you zooming it? With ResizeImage()? If so, it smooths by default, so make sure you use the #PB_Image_Raw flag with it.
Re: DrawImage blurry
I am using the width and height parameters of DrawImage to define the desired size.
I am attempting to make a small pixel editor, so I don’t think ResizeImage would be fast enough, as I need the image redrawn each time a change is made to the pixel data.
I am attempting to make a small pixel editor, so I don’t think ResizeImage would be fast enough, as I need the image redrawn each time a change is made to the pixel data.
Re: DrawImage blurry
Oops, I forgot that DrawImage() did resizing. Sorry for my pointless reply.
Re: DrawImage blurry
ResizeImage is pretty fast.wombats wrote:I am using the width and height parameters of DrawImage to define the desired size.
I am attempting to make a small pixel editor, so I don’t think ResizeImage would be fast enough, as I need the image redrawn each time a change is made to the pixel data.
You could also access the drawing buffer and create your own procedure.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: DrawImage blurry
Hi
Using MouseWheel
Do not use the original image and do not use cumulative resizing
Using MouseWheel
Do not use the original image and do not use cumulative resizing
Code: Select all
UseGIFImageDecoder()
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
OpenWindow(0, 0, 0, 800, 500, "PictureViewer", #PB_Window_SystemMenu|#PB_Window_MaximizeGadget| #PB_Window_ScreenCentered)
ExplorerListGadget(0, 10, 10, 250, 470, "*.bmp;*.jpg;*.png;*.tga;*.tif;*.gif",#PB_Explorer_GridLines)
SetGadgetColor(0, #PB_Gadget_BackColor, $DDFFFF)
SetGadgetColor(0, #PB_Gadget_FrontColor, $FF0000)
CanvasGadget(1,270,10,515,470,#PB_Canvas_Border)
oldDelta.f = 1
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_LeftDoubleClick
file$ = GetGadgetText(0) + GetGadgetItemText(0, GetGadgetState(0))
If FileSize(file$) > 0
LoadImage(0, file$)
If IsImage(0)
CopyImage(0,1)
If IsImage(1)
StartDrawing(CanvasOutput(1))
Box(0,0,OutputWidth(),OutputHeight(),$FFFFFF)
DrawImage(ImageID(1),OutputWidth()/2-ImageWidth(1)/2,OutputHeight()/2-ImageHeight(1)/2)
StopDrawing()
EndIf
EndIf
EndIf
EndSelect
Case 1
Select EventType()
Case #PB_EventType_MouseWheel
Delta.f = GetGadgetAttribute(1, #PB_Canvas_WheelDelta )/100 + oldDelta.f
If Delta.f < 0.01
Delta.f = 0.01
EndIf
If IsImage(0)
CopyImage(0,1)
ResizeImage(1,ImageWidth(0)*Delta,ImageHeight(0)*Delta)
If IsImage(1)
StartDrawing(CanvasOutput(1))
Box(0,0,OutputWidth(),OutputHeight(),$FFFFFF)
DrawImage(ImageID(1),OutputWidth()/2-ImageWidth(1)/2,OutputHeight()/2-ImageHeight(1)/2)
StopDrawing()
EndIf
oldDelta.f = Delta.f
EndIf
EndSelect
EndSelect
EndSelect
ForEver
Egypt my love
Re: DrawImage blurry
Thank you for the example code, RASHAD!
The drawing buffer confuses me to no end. I can't seem to find a simple explanation on how to change a pixel.wilbert wrote:ResizeImage is pretty fast.wombats wrote:I am using the width and height parameters of DrawImage to define the desired size.
I am attempting to make a small pixel editor, so I don’t think ResizeImage would be fast enough, as I need the image redrawn each time a change is made to the pixel data.
You could also access the drawing buffer and create your own procedure.
Re: DrawImage blurry
Rashad, your example doesn't do anything for me when I scroll the mousewheel after selecting an image?
Re: DrawImage blurry
Change line 13 to:
Code: Select all
CanvasGadget(1,270,10,515,470,#PB_Canvas_Border|#PB_Canvas_Keyboard )
Re: DrawImage blurry
@wombats
How do you want to change pixels?.Before or after zooming
Post any simple example
New zoom snippet
Supported :
-Arrow Up & Down
-PgUp & PgDn
-MouseWheel
How do you want to change pixels?.Before or after zooming
Post any simple example
New zoom snippet
Supported :
-Arrow Up & Down
-PgUp & PgDn
-MouseWheel
Code: Select all
UseGIFImageDecoder()
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseTIFFImageDecoder()
OpenWindow(0, 0, 0, 800, 500, "PictureViewer", #PB_Window_SystemMenu|#PB_Window_MaximizeGadget| #PB_Window_ScreenCentered)
ExplorerListGadget(0, 10, 10, 210, 480, "*.bmp;*.jpg;*.png;*.tga;*.tif;*.gif",#PB_Explorer_GridLines)
SetGadgetColor(0, #PB_Gadget_BackColor, $DDFFFF)
SetGadgetColor(0, #PB_Gadget_FrontColor, $FF0000)
SetGadgetItemAttribute(0, 0,#PB_Explorer_ColumnWidth,60,1)
SetGadgetItemAttribute(0, 0,#PB_Explorer_ColumnWidth,40,2)
RemoveGadgetColumn(0,3)
CanvasGadget(1,230,10,560,480,#PB_Canvas_Border|#PB_Canvas_Keyboard)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_LeftDoubleClick
SetActiveGadget(1)
oldDelta.f = 1
file$ = GetGadgetText(0) + GetGadgetItemText(0, GetGadgetState(0))
If FileSize(file$) > 0
LoadImage(0, file$)
If IsImage(0)
CopyImage(0,1)
If IsImage(1)
StartDrawing(CanvasOutput(1))
Box(0,0,OutputWidth(),OutputHeight(),$FFFFFF)
DrawImage(ImageID(1),OutputWidth()/2-ImageWidth(1)/2,OutputHeight()/2-ImageHeight(1)/2)
StopDrawing()
EndIf
EndIf
EndIf
EndSelect
Case 1
Select EventType()
Case #PB_EventType_KeyDown
Status = GetGadgetAttribute(1, #PB_Canvas_Key)
If Status = #PB_Shortcut_Up
Delta.f = oldDelta.f + 1/100
ElseIf Status = #PB_Shortcut_PageUp
Delta.f = oldDelta.f + 10/100
ElseIf Status = #PB_Shortcut_Down
Delta.f = oldDelta.f - 1/100
ElseIf Status = #PB_Shortcut_PageDown
Delta.f = oldDelta.f - 10/100
EndIf
If Delta.f > 10.0
Delta.f = 10
ElseIf Delta.f < 0.01
Delta.f = 0.01
EndIf
If IsImage(0)
CopyImage(0,1)
ResizeImage(1,ImageWidth(0)*Delta,ImageHeight(0)*Delta)
If IsImage(1)
StartDrawing(CanvasOutput(1))
Box(0,0,OutputWidth(),OutputHeight(),$FFFFFF)
DrawImage(ImageID(1),OutputWidth()/2-ImageWidth(1)/2,OutputHeight()/2-ImageHeight(1)/2)
StopDrawing()
EndIf
oldDelta.f = Delta.f
EndIf
Case #PB_EventType_MouseWheel
Delta.f = GetGadgetAttribute(1, #PB_Canvas_WheelDelta )/100 + oldDelta.f
If Delta.f < 0.01
Delta.f = 0.01
EndIf
If IsImage(0)
CopyImage(0,1)
ResizeImage(1,ImageWidth(0)*Delta,ImageHeight(0)*Delta)
If IsImage(1)
StartDrawing(CanvasOutput(1))
Box(0,0,OutputWidth(),OutputHeight(),$FFFFFF)
DrawImage(ImageID(1),OutputWidth()/2-ImageWidth(1)/2,OutputHeight()/2-ImageHeight(1)/2)
StopDrawing()
EndIf
oldDelta.f = Delta.f
EndIf
EndSelect
EndSelect
EndSelect
ForEver
Egypt my love
Re: DrawImage blurry
Rashad, that is a great example.
I was pleasantly surprised that all the commands used were available in PureBasic.
I was expecting all kinds of Win API commands.
I was pleasantly surprised that all the commands used were available in PureBasic.
I was expecting all kinds of Win API commands.
- It was too lonely at the top.
System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
System : PB 6.10 LTS (x64) and Win Pro 11 (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem