terça-feira, 15 de janeiro de 2013

Recuperar Imagem redimensionada no java

  1. public class ImageUtils {
  2.     private static BufferedImage scale(BufferedImage img, int type, int dimencao, boolean higherQuality) {
  3.         BufferedImage ret = img;
  4.         int w, h;
  5.         if (higherQuality) {
  6.             // Use multi-step technique: start with original size, then
  7.             // scale down in multiple passes with drawImage()
  8.             // until the target size is reached
  9.             w = img.getWidth();
  10.             h = img.getHeight();
  11.         } else {
  12.             // Use one-step technique: scale directly from original
  13.             // size to target size with a single drawImage() call
  14.             w = dimencao;
  15.             h = dimencao;
  16.         }
  17.         Graphics2D graphics = null;
  18.         BufferedImage tmp = null;
  19.         if (higherQuality) {
  20.             if (w >= h) {
  21.                 h = h * dimencao / w;
  22.                 w = dimencao;
  23.             } else {
  24.                 w = w * dimencao / h;
  25.                 h = dimencao;
  26.             }
  27.         }
  28.         tmp = new BufferedImage(w, h, type);
  29.         graphics = tmp.createGraphics();
  30.         graphics.setComposite(AlphaComposite.Src);
  31.         graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
  32.         graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
  33.         graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  34.         graphics.drawImage(ret, 0, 0, w, h, null);
  35.         graphics.dispose();
  36.         ret = tmp;
  37.         return ret;
  38.     }
  39.     public static byte[] getScaledImage(File file, int dimensao) {
  40.         byte[] result = null;
  41.         try {
  42.             BufferedImage image = ImageIO.read(file);
  43.             BufferedImage thumbs = ImageFileUtils.scale(image, BufferedImage.TYPE_INT_RGB, dimensao, true);
  44.             ByteArrayOutputStream baos = new ByteArrayOutputStream();
  45.             ImageIO.write(thumbs, FilenameUtils.getExtension(file.getName()), baos);
  46. //            ImageIO.write(image, FilenameUtils.getExtension(file.getName()), baos);
  47.             result = baos.toByteArray();
  48.         } catch (FileNotFoundException fnfe) {
  49.             logger.debug(fnfe == null ? "Imagem não localizada" : fnfe.getMessage());
  50.         } catch (Exception ex) {
  51.             logger.debug(ex == null ? ">>> erro ao atualizar o Outputstream do response." : ex.getMessage());
  52.         }
  53.         return result;
  54.     }
  55. }

Alinhamento Vertical dentro de uma div



< ?xml version="1.0" encoding="iso-8859-1"? >
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
< html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt" lang="pt" >
< head >
< title >Vertical Align< /title >
< style type="text/css" >
< !--
#main {
display: table;
}
#row {
display: table-row;
}
#cell {
float: none;
display: table-cell;
vertical-align: middle;
background-color: #CCCC00;
height: 200px;

}
-- >
< /style >
< /head >

< body >
< div id="main" >
  < div id="rows" >
         < div id="cell" >ok< /div >
  < /div >
< /div >
< /body >
< /html >

Fonte: http://forum.imasters.com.br/topic/132304-tableless-alinhamento-vertical-o-mito/

quarta-feira, 9 de janeiro de 2013

Editor de audio online

https://twistedwave.com/online/

Modificando a resolução do monitor

para identificar quais resoluções são suportadas

$xrandr

para adicionar uma nova resolução
$ cvt 1920 1080 60
# 1920x1080 59.96 Hz (CVT 2.07M9) hsync: 67.16 kHz; pclk: 173.00 MHz
Modeline "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync

para adicionar a resolução as configurações
$ xrandr --newmode "1920x1080_60.00"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync


para adicionar a configuração ao dispositivo de video
$xrandr --addmode VGA-0 "1920x1080_60.00"

agora é so definir a configuração

atenção se a resolução não for suportada pela placa verifique o drive do monitor.


Mudança temporária para placas de videos que nao suporta altas resoluções

xrandr --output LVDS1 --scale 1.5x1.5

tente

xrandr --output LVDS1 --scale 4.0x4.0


segunda-feira, 7 de janeiro de 2013

Updade com números aleatórios no oracle


Fazem parte da package DBMS_RANDOM os métodos:
Initialize (Inicializa o processo com um gerador pré definido)
Seed (Reinicia / altera o gerador)
Terminate (Termina a geração)
Random (Gera o valor randômico)
value (gera valor numérico de acordo com o intervalo dado – default de 0 a 1)
string (gera conjunto de caracteres de acordo com os parâmetros abaixo)
Primeiro parâmetro: tipo de string a ser gerada (sempre digitada em upper case). Segundo parâmetro: tamanho da string.
U – Upper case
L – Lower case
A – Alfanumérico (Alphanumeric)
X – Alfanumérico com caracteres upper case (Alphanumeric with upper case alphabets)
P – Somente caracteres imprimíveis (printable characters only)
Outros caracteres: retorno será somente em upper case (Providing any other character will return the output in upper case only)
Exemplos:
SQL> select dbms_random.value from dual;
VALUE
———-
0,45800212
SQL> select trunc(dbms_random.value(10, 99), 0) x from dual;
X
———-
15
SQL> select dbms_random.string(‘U’, 5) x from dual;
X
——————————————————————————–
YBGZO
SQL> select dbms_random.string(‘A’, 5) x from dual;
X
——————————————————————————–
xWGqo

WARNING: Parameters: Invalid chunk ignored"

Esse warning ocorre quando o formulário enviado possui campos não identificados

exemplo de post que gera este problema

  1. j_idt108:j_idt168:0:j_idt171:0:quantidade:10
  2. :
  3. j_idt108:j_idt168:0:j_idt171:1:quantidade:10
  4. :
Ao analizar o submit com uma ferramenta de profile pude encontrar esta divergência no form.

A causa deste problema foi:
em uma página jsf possuía um formulário


< h:form >
quantidade: < h:inputtext id="quantidade" >< /h:inputtext >
comentario: < textArea >< /textArea >

< /h:form >



Havia colocado o textarea somente para teste de layout, porém como ele está dentro do formulário, durante uma requisição ajax ele é submetido, o que gera o warning

WARNING: Parameters: Invalid chunk ignored"

para cada tag não jsf.

para resolver isso somente substitui o textArea por


< h:form >
quantidade: < h:inputtext id="quantidade" >< /h:inputtext >
comentario: < h:inputtextarea id="comentatio" >< /h:inputtextarea >

< /h:form >



O que gerou o seguinte post

  1. j_idt108:j_idt168:0:j_idt171:0:quantidade:10
  2. j_idt108:j_idt168:0:j_idt171:0:comentatio:
  3. j_idt108:j_idt168:0:j_idt171:1:quantidade:10
  4. j_idt108:j_idt168:0:j_idt171:0:comentario:

Que resolveu o problema