Save-Point
[Resolved] Shrinking an Icon - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: [Resolved] Shrinking an Icon (/thread-3891.html)



[Resolved] Shrinking an Icon - Yin - 01-11-2012

Hey, I was just wondering how I would shrink an icon. I have this right now:

Code:
bitmap = RPG::Cache.icon(item.icon_name)    self.contents.font.color = normal_color    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 16, 16))    self.contents.draw_text(x + 20, y, width-80, 16, item.name)


It makes the area 16x16, but the icon is still normal sized.


RE: Shrinking an Icon - DerVVulfman - 01-11-2012

I use this to increase graphic sizes for a zoomed effect in my CharGen project
Code:
def resize(bitmapped,flag)
    if flag == true
      temp_bmp = bitmapped.clone
      rect = Rect.new(0, 0, temp_bmp.width, temp_bmp.height)
      rect2 = Rect.new((temp_bmp.width/$game_zoom.chargen[1].to_i)*(($game_zoom.chargen[3].to_i)-1),
                       (temp_bmp.height/$game_zoom.chargen[2].to_i)*(($game_zoom.chargen[4].to_i)-1),
                       temp_bmp.width/$game_zoom.chargen[1].to_i,
                       temp_bmp.height/$game_zoom.chargen[2].to_i)
      temp_bmp = Bitmap.new(temp_bmp.width, temp_bmp.height)
      temp_bmp.stretch_blt(rect, bitmapped, rect2)
      bitmapped = temp_bmp
    end    
    return bitmapped
  end
Okay.... it may be a mess. The thing is the temp_bmp.stretch_blt(rect, bitmapped, rect2) routine.

rect is the rectangle holding the size/shape of your original
rect2 is the rectangle of your shrunk/resized image
bitmapped is your file
and temp_bmp is your new one


RE: Shrinking an Icon - Yin - 01-11-2012

I'm sorry, I sort of understand but how would I use this?

resize("icon name", true)

How does it know what size to switch to?

NVM let me figure this out! :) I've been trying to teach myself.

Thank you!

Ok, so I've been here... trying to figure this out. This is the new method.

Code:
if item == nil
      return
    end
    self.contents.font.color = normal_color
    #self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 16, 16))
    bitmap = RPG::Cache.icon(item.icon_name)
    rect = Rect.new(0, 0, 16, 16)
    icon = Rect.new(0, 0, 16, 16)
    bitmap.stretch_blt(rect, bitmap,icon)
    self.contents.draw_text(x + 20, y, width-80, 16, item.name)

It just comes up blank now.


RE: Shrinking an Icon - NightOwl - 01-13-2012

I didn't know you edited your post. Last I saw was "gonna figure this out". I woulda come earlier had I known.

Well, you commented out the line that pasted the revised icon and forgot to redo it after the resize. You also performed the resize, but didn't establish it as a new bitmap. I did a little editing as you can see here.
Code:
if item == nil
  return
end
self.contents.font.color = normal_color
bitmap    = RPG::Cache.icon(item.icon_name)
newbitmap = bitmap.clone
rect      = Rect.new(0, 0, 32, 32)
rect2     = Rect.new(0, 0, 16, 16)
newbitmap = bitmap.stretch_blt(rect, bitmap, rect2)
self.contents.blt(x, y + 4, newbitmap, rect2)
self.contents.draw_text(x + 20, y, width-80, 16, item.name)



RE: Shrinking an Icon - Yin - 01-13-2012

I'm going to try this out asap. For some reason, I thought that the stretch blt was standalone and did not need the regular blt call.


RE: Shrinking an Icon - Victor Sant - 01-13-2012

the stretch_blt is stand alone, but you didn't apply it to the window content

Change the
Code:
bitmap.stretch_blt(rect, bitmap,icon)
self.contents.draw_text(x + 20, y, width-80, 16, item.name)

to
Code:
self.contents.stretch_blt(rect, bitmap,icon)
self.contents.draw_text(x + 20, y, width-80, 16, item.name)



RE: Shrinking an Icon - Yin - 01-26-2012

Thanks I got it working properly.