我用软件将一个24位RGB图像转换成了rgb565 rgb888格式用

在我的应用程序,我加载图片作为32位(ARGB_8888)是这样的:
Bitmap.Config mBitmapC
mBitmapConfig = Bitmap.Config.ARGB_8888;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = mBitmapC
mBitmap = BitmapFactory.decodeFile(SourceFileName, options);
那么规模:
mBitmap = Bitmap.createScaledBitmap(mBitmap, iW, iH, true);
如果缩放的宽度和原来它是尺寸的1/2高度(我在看堆的大小)。
更改值“ARGB_8888”到“RGB_565”(24位)缩放后给人的大小。
可以解释这一点,可能是一个建议,如何扩大在32位色彩空间?
本文地址 :CodeGo.net/312435/
-------------------------------------------------------------------------------------------------------------------------
1. 我抬起头的源类(链接)中:
public static Bitmap createScaledBitmap(Bitmap src, int dstWidth,
int dstHeight, boolean filter) {
synchronized (Bitmap.class) {
// small pool of just 1 matrix
m = sScaleM
sScaleMatrix =
if (m == null) {
m = new Matrix();
final int width = src.getWidth();
final int height = src.getHeight();
final float sx = dstWidth / (float)
final float sy = dstHeight / (float)
m.setScale(sx, sy);
Bitmap b = Bitmap.createBitmap(src, 0, 0, width, height, m, filter);
synchronized (Bitmap.class) {
// do we need to check for null? why not just assign everytime?
if (sScaleMatrix == null) {
sScaleMatrix =
并调用应该返回你的源代码不变,由于此检查身体:
if (!source.isMutable() && x == 0 && y == 0 && width == source.getWidth() &&
height == source.getHeight() && (m == null || m.isIdentity())) {
看着眼前这个又好像你原来的返回,但是,如果你恰好是可变的,您可以有效地略过这项检查,并最终在这里:
if (m == null || m.isIdentity()) {
bitmap = createBitmap(neww, newh,
source.hasAlpha() ? Config.ARGB_8888 : Config.RGB_565);
paint = // not needed
由于您没有进行任何缩放,你的矩阵将是单位矩阵 CodeGo.net,并且满足该条件。创建的,正如你所看到的,依赖于源中的alpha如果没有alpha存在,你最终得到的结果与RGB_565格式,而不是ARGB_8888。
因此,扩展和维护的32位格式,你要么是不可改变的Alpha通道。
可以很容易地创建自己的版本,保持源的像素格式:
public static Bitmap CreateScaledBitmap(Bitmap src, int dstWidth, int dstHeight, bool filter)
var m = new Matrix();
m.SetScale(dstWidth / (float)src.Width, dstHeight / (float)src.Height);
var result = Bitmap.CreateBitmap(dstWidth, dstHeight, src.GetConfig());
using (var canvas = new Canvas(result))
var paint = new Paint();
paint.FilterBitmap =
canvas.DrawBitmap(src, m, paint);
(代码是Monodroid,但它应该是容易翻译到Java)
色带解决ooooooooooyyyyyyyeaaaaaaaaaa
我分两个阶段解决色带
1)*当解码资源,它在解码RGB565的资源,显示色条带,而不是ARGB_8888,所以用于设置解码选项,ARGB_8888
每当我攀登上再次得到了带状的第二个问题是
2)这是艰难的部分,并采取了很多的寻找终于摸索
*的比例也降低了图像RGB565格式的缩放我得到的带状图像(解决这个至少一个透明像素的PNG但没有其他格式像bmp或者jpg的工作),所以在这里我创建扩展后与原来的配置在产生的规模,我从后通过复制和翻译中的java)
BitmapFactory.Options myOptions = new BitmapFactory.Options();
myOptions.inDither =
myOptions.inScaled =
myOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//important
//myOptions.inDither =
myOptions.inPurgeable =
Bitmap tempImage =
BitmapFactory.decodeResource(getResources(),R.drawable.defaultart, myOptions);//important
//this is important part new scale method created by someone else
tempImage = CreateScaledBitmap(tempImage,300,300,false);
ImageView v = (ImageView)findViewById(R.id.imageView1);
v.setImageBitmap(tempImage);
public static Bitmap CreateScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter)
Matrix m = new Matrix();
m.setScale(dstWidth / (float)src.getWidth(), dstHeight / (float)src.getHeight());
Bitmap result = Bitmap.createBitmap(dstWidth, dstHeight, src.getConfig());
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
paint.setFilterBitmap(filter);
canvas.drawBitmap(src, m, paint);
请如果我错了。
此外,如果它为你工作。
我很高兴我解决它,希望它为你工作。
我正在写代码的Android版本低于3.2(API级别&12),因为当时的行为
BitmapFactory.decodeFile(pathToImage);
BitmapFactory.decodeFile(pathToImage, opt);
bitmapObject.createScaledBitmap(bitmap, desiredWidth, desiredHeight, false /*filter?*/);
已经改变。
在旧平台(API级别&12)的方法,试图返回一个与RGB_565配置默认情况下,如果他们无法找到任何字母,从而降低了iamge的质量。这仍然是好的,你可以使用强制执行ARGB_8888
options.inPrefferedConfig = Bitmap.Config.ARGB_8888
options.inDither = false
当你的图像的每个像素有255的alpha值(即完全不透明)真正的问题。在这种情况下,标志“量hasalpha'设置为false,即使你有ARGB_8888配置。如果你的*。PNG文件都至少有一个真正透明的像素,该标志将被设置为true,你就不必担心什么。
所以,当你想创建一个使用缩放
bitmapObject.createScaledBitmap(bitmap, desiredWidth, desiredHeight, false /*filter?*/);
检查“量hasalpha'标志是否被设置为true或false,并在您的情况下,它被设置为false,从而导致获得规模这是自动转换为RGB_565格式。
因此,在API级别&=12有一个名为
public void setHasAlpha (boolean hasAlpha);
这将解决这个问题。到目前为止,这是只是问题的一个解释。
我做了研究,发现了存在已久,它是公共的,但已隐藏(@隐藏注释)。下面是它如何在Android 2.3中定义:
* Tell the bitmap if all of the pixels are known to be opaque (false)
* or if some of the pixels may contain non-opaque alpha values (true).
* Note, for some configs (e.g. RGB_565) this call is ignore, since it does
* not support per-pixel alpha values.
* This is meant as a drawing hint, as in some cases a bitmap that is known
* to be opaque can take a faster drawing case than one that may have
* non-opaque per-pixel alpha values.
public void setHasAlpha(boolean hasAlpha) {
nativeSetHasAlpha(mNativeBitmap, hasAlpha);
现在,这里是我的解决办法的建议。它不涉及任何数据复制:
检查在使用java.lang.reflect中,如果当前
有一个公共的'setHasAplha'方法。
(根据我的测试中,它完美的作品,因为API级别3,和我没有测试更低的版本中,JNI是行不通的)。您可能有问题,如果一个制造商已经明确提出了私有,保护或删除它。
称之为“setHasAlpha'方法对于一个给定的JNI。
这完美的作品,甚至或字段。这是官方的JNI不检查您是否违反了访问控制规则与否。
来源:(10.9)
这种巨大的力量,这应该明智。我不会试图修改一个final字段,即使它会工作(只是举个例子)。并请注意,这仅仅是一个解决办法...
这里是我的全部
JAVA的部分:
// NOTE: this cannot be used in switch statements
private static final boolean SETHASALPHA_EXISTS = setHasAlphaExists();
private static boolean setHasAlphaExists() {
// get all puplic Methods of the class Bitmap
java.lang.reflect.Method[] methods = Bitmap.class.getMethods();
// search for a method called 'setHasAlpha'
for(int i=0; i&methods. i++) {
if(methods[i].getName().contains("setHasAlpha")) {
Log.i(TAG, "method setHasAlpha was found");
Log.i(TAG, "couldn't find method setHasAlpha");
private static void setHasAlpha(Bitmap bitmap, boolean value) {
if(bitmap.hasAlpha() == value) {
Log.i(TAG, "bitmap.hasAlpha() == value -& do nothing");
if(!SETHASALPHA_EXISTS) { // if we can't find it then API level MUST be lower than 12
// couldn't find the setHasAlpha-method
// &-- provide alternative here...
// using android.os.Build.VERSION.SDK to support API level 3 and above
// use android.os.Build.VERSION.SDK_INT to support API level 4 and above
if(Integer.valueOf(android.os.Build.VERSION.SDK) &= 11) {
Log.i(TAG, "BEFORE: bitmap.hasAlpha() == " + bitmap.hasAlpha());
Log.i(TAG, "trying to set hasAplha to true");
int result = setHasAlphaNative(bitmap, value);
Log.i(TAG, "AFTER: bitmap.hasAlpha() == " + bitmap.hasAlpha());
if(result == -1) {
Log.e(TAG, "Unable to access bitmap."); // usually due to a bug in the own code
} else { //API level &= 12
bitmap.setHasAlpha(true);
* Decodes a Bitmap from the SD card
* and scales it if necessary
public Bitmap decodeBitmapFromFile(String pathToImage, int pixels_limit) {
Options opt = new Options();
opt.inDither = //important
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapFactory.decodeFile(pathToImage, opt);
if(bitmap == null) {
Log.e(TAG, "unable to decode bitmap");
setHasAlpha(bitmap, true); // if necessary
int numOfPixels = bitmap.getWidth() * bitmap.getHeight();
if(numOfPixels & pixels_limit) { //image needs to be scaled down
// ensures that the scaled image uses the maximum of the pixel_limit while keeping the original aspect ratio
// i use: private static final int pixels_limit = ; //1,3 Megapixel
imageScaleFactor = Math.sqrt((double) pixels_limit / (double) numOfPixels);
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap,
(int) (imageScaleFactor * bitmap.getWidth()), (int) (imageScaleFactor * bitmap.getHeight()), false);
bitmap.recycle();
bitmap = scaledB
Log.i(TAG, "scaled bitmap config: " + bitmap.getConfig().toString());
Log.i(TAG, "pixels_limit = " + pixels_limit);
Log.i(TAG, "scaled_numOfpixels = " + scaledBitmap.getWidth()*scaledBitmap.getHeight());
setHasAlpha(bitmap, true); // if necessary
加载你的lib和声明
System.loadLibrary("bitmaputils");
private static native int setHasAlphaNative(Bitmap bitmap, boolean value);
本地部分(“JNI”文件夹)
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := bitmaputils
LOCAL_SRC_FILES := bitmap_utils.c
LOCAL_LDLIBS := -llog -ljnigraphics -lz -ldl -lgcc
include $(BUILD_SHARED_LIBRARY)
#include &jni.h&
#include &android/bitmap.h&
#include &android/log.h&
#define LOG_TAG "BitmapTest"
#define Log_i(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define Log_e(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
// caching class and method IDs for a faster subsequent access
static jclass bitmap_class = 0;
static jmethodID setHasAlphaMethodID = 0;
jint Java_com_example_bitmaptest_MainActivity_setHasAlphaNative(JNIEnv * env, jclass clazz, jobject bitmap, jboolean value) {
AndroidBitmapI
if (AndroidBitmap_getInfo(env, bitmap, &info) & 0) {
Log_e("Failed to get Bitmap info");
return -1;
if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
Log_e("Incompatible Bitmap format");
return -1;
if (AndroidBitmap_lockPixels(env, bitmap, &pixels) & 0) {
Log_e("Failed to lock the pixels of the Bitmap");
return -1;
// get class
if(bitmap_class == NULL) { //initializing jclass
// NOTE: The class Bitmap exists since API level 1, so it just must be found.
bitmap_class = (*env)-&GetObjectClass(env, bitmap);
if(bitmap_class == NULL) {
Log_e("bitmap_class == NULL");
return -2;
// get methodID
if(setHasAlphaMethodID == NULL) { //initializing jmethodID
// NOTE: If this fails, because the method could not be found the App will crash.
// But we only call this part of the code if the method was found using java.lang.Reflect
setHasAlphaMethodID = (*env)-&GetMethodID(env, bitmap_class, "setHasAlpha", "(Z)V");
if(setHasAlphaMethodID == NULL) {
Log_e("methodID == NULL");
return -2;
// call java instance method
(*env)-&CallVoidMethod(env, bitmap, setHasAlphaMethodID, value);
// if an exception was thrown we could handle it here
if ((*env)-&ExceptionOccurred(env)) {
(*env)-&ExceptionDescribe(env);
(*env)-&ExceptionClear(env);
Log_e("calling setHasAlpha threw an exception");
return -2;
if(AndroidBitmap_unlockPixels(env, bitmap) & 0) {
Log_e("Failed to unlock the pixels of the Bitmap");
return -1;
return 0; // success
就是这样。我们正在做的。我已经张贴了整个代码复制和粘贴的目的。
实际的代码量不算大,但使所有这些偏执的错误检查使它成为很多更大。我希望这能帮助到任何人。
本文标题 :请问“Bitmap.createScaledBitmap”转换的32位图像转换成24位?
本文地址 :CodeGo.net/312435/
Copyright (C) 2014 CodeGo.net 沪ICP备号 联&系& c&o&d&e&g&o &@&1&2&6&.&c&o&mbmp24_2_bin_rgb565 一个将BMP888转换为BMP565的代码,这个是我自己写的,并日常在使用的工具.开发环境为Vis Picture Viewer 图片显示 238万源代码下载-
&文件名称: bmp24_2_bin_rgb565
& & & & &&]
&&所属分类:
&&开发工具: Visual C++
&&文件大小: 55 KB
&&上传时间:
&&下载次数: 18
&&提 供 者:
&详细说明:一个将BMP888转换为BMP565的代码,这个是我自己写的,并日常在使用的工具.开发环境为Visual
C++ 6.-A BMP888 BMP565 code, this is my own writing, and daily in the use of tools. Development environment for Visual C++ 6.
文件列表(点击判断是否您需要的文件,如果是垃圾请在下面评价投诉):
&&bmp24_2_bin_rgb565&&..................\bmp24_2_txt.cpp&&..................\bmp24_2_txt.h&&..................\common&&..................\......\inc&&..................\......\...\type_define.h&&..................\......\...\wnd_interface.h&&..................\......\wnd_interface.cpp&&..................\Debug&&..................\.....\bmp24_2_bin_rgb565.exe&&..................\ReadMe.txt&&..................\StdAfx.cpp&&..................\StdAfx.h&&..................\version.h&&..................\win_console_module.cpp&&..................\win_console_module.dsp&&..................\win_console_module.dsw&&..................\win_console_module.ncb&&..................\win_console_module.opt&&..................\win_console_module.plg
&近期下载过的用户:
&输入关键字,在本站238万海量源码库中尽情搜索:
&[] - Cryptanalysis of KeeLoq code-hopping using a
Single FPGA
&[] - 这个是我自己编写的一个windows字体点阵生成工具,用于嵌入式字体字库的生成和显示.一直在使用.开发环境Visual C++ 6.
&[] - 此工具,只要是把24位bmp图转换成16位565格式数据,用于嵌入式平台
&[] - convert bmp to rgb565
&[] - 把JPG/BMP图片转换位RGB565格式, 这是为了DX应用的方便(16位色), 也可以用于LINUX的帧缓存(16位色) 附带转换程序+图片查看
&[] - Program to convert the bmp image to rgb565 format.
&[] - 颜色格式转换小程序 RGB24位转换为RGB565格式。
&[] - 24位BMP转换为RGB565的BMP工具raw data 转成RGB输出图像,该怎么处理_SpringSecurity3.1.2统制一个账户同时只能登录一次_依据下拉列表的不同链接到不同页面,求高手__脚本百事通
稍等,加载中……
^_^请注意,有可能下面的2篇文章才是您想要的内容:
raw data 转成RGB输出图像,该怎么处理
SpringSecurity3.1.2统制一个账户同时只能登录一次
依据下拉列表的不同链接到不同页面,求高手
raw data 转成RGB输出图像,该怎么处理
raw data 转成RGB输出图像我能从一个广角摄像头上收集到图像的raw data 是BYTE*类型的,我现在想将这些raw data转换成rgb图像输出,该怎么办。
我在图像方面是新手,现在问题很急。
给我个简单的例子或者资料都可以。
跪求------最佳解决方案--------------------
引用:引用:引用:引用:引用:要知道数据的大小,还有是YUV还是RGB的,
终于有人回复了,我的buffer大小是的,是rgb的!
你从摄像头上取下来的数……
摄像头的数据输出格式一般分为CCIR601、CCIR656、RAW RGB等格式,此处说的RGB格式应该就是CCIR601或CCIR656格式。而RAW RGB格式与一般的RGB格式是有区别的。RGB才能用于显示
所以你就要先转换成 RGB------其他解决方案--------------------
引用:引用:引用:引用:引用:要知道数据的大小,还有是YUV还是RGB的,
终于有人回复了,我的buffer大小是的,是rgb的!
你从摄像头上取下来的数……
参照这个资源http://download.csdn.net/detail/liuhhaiffeng/2209215 raw rgb to rgb的转换------其他解决方案--------------------另外可以查下这个函数看看
cvCvtColor------其他解决方案--------------------要知道数据的大小,还有是YUV还是RGB的,------其他解决方案--------------------
引用:要知道数据的大小,还有是YUV还是RGB的,
终于有人回复了,我的buffer大小是的,是rgb的!
你从摄像头上取下来的数据已经是RGB了,直接画就是了撒。用StretchBlt
如果不是RGB的,你看下采集下来的数据是什么格式的,YUV422之类的分片方式存放数据
还是UYVY之类的点阵存放的数据,是8Bit的还是10Bit的,这些弄清出了,百度上YUVtoRGB的代码还是很多的。------其他解决方案--------------------up,真心着急啊------其他解决方案--------------------
要知道数据的大小,还有是YUV还是RGB的,
终于有人回复了,我的buffer大小是的,是rgb的!------其他解决方案--------------------
引用:引用:要知道数据的大小,还有是YUV还是RGB的,
终于有人回复了,我的buffer大小是的,是rgb的!
你从摄像头上取下来的数据已经是RGB了,直接画就是了撒。用StretchBlt
如果不是RGB的,你看下采集下来的数据是什么格式的,YUV422之类的分片方……
如何看采集下来的数据是什么格式的?采集下来的数据时BYTE*类型的。非常感谢!------其他解决方案--------------------
引用:引用:要知道数据的大小,还有是YUV还是RGB的,
终于有人回复了,我的buffer大小是的,是rgb的!
你从摄像头上取下来的数据已经是RGB了,直接画就是了撒。用StretchBlt
如果不是RGB的,你看下采集下来的数据是什么格式的,YUV422之类的分片方……
我又确认了下,摄像头取下的数据时raw rgb的 是8位的。
我直接输出,但是没有图像。
跪求帮助,真的挺急的------其他解决方案--------------------
引用:引用:引用:要知道数据的大小,还有是YUV还是RGB的,
终于有人回复了,我的buffer大小是的,是rgb的!
你从摄像头上取下来的数据已经是RGB了,直接画就是了撒。用StretchBlt
如果不是RGB的,你看下采集下……
看看你的采集参数,采出来的画面是YUV格式还是什么的,是就到网上去找转换方法,转换成RGB就行了------其他解决方案--------------------
引用:引用:引用:引用:要知道数据的大小,还有是YUV还是RGB的,
终于有人回复了,我的buffer大小是的,是rgb的!
你从摄像头上取下来的数据已经是RGB了,直接画就是了撒。用Stret……
摄像头采集的格式raw rgb的,这个可以直接输出吗?
我的输出代码是下面的:但是没结果
if(bt.CreateBitmap(, 1, 8, temp))//temp中时raw rgb格式。
//产生一个兼容的设备容器变量
dcCompatibale.CreateCompatibleDC(pDC);
dcCompatibale.SelectObject(bt); //将位图变量放入兼容设备中
bt.GetBitmap(&bm);
//产生一个矩形变量rect
GetClientRect(&rect);
//获得客户端的矩形区域,并付值给rect
pDC-&BitBlt(0,0,rect.Width(),rect.Height(),&dcCompatibale,0,0,SRCCOPY);
pDC-&StretchBlt(0, 0, rect.Width(), rect.Height(), &dcCompatibale, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
}------其他解决方案--------------------你用什么方法获取的,难道文档上没说明是yuv还是rgb的?有可能你现在得到的就是rgb的------其他解决方案--------------------
你用什么方法获取的,难道文档上没说明是yuv还是rgb的?有可能你现在得到的就是rgb的
我现在确定我得到的就是raw rgb。是从一个广角摄像头得到的,这个摄像头需要他们提供的驱动。
opencv中有将raw rgb转到rgb的方法吗?------其他解决方案--------------------
引用:你用什么方法获取的,难道文档上没说明是yuv还是rgb的?有可能你现在得到的就是rgb的
我现在确定我得到的就是raw rgb。是从一个广角摄像头得到的,这个摄像头需要他们提供的驱动。
opencv中有将raw rgb转到rgb的方法吗?
raw rgb不就是rgb么,你是想做rgb内部格式转换吧,比如转成rgb32,rgb565,rgb888之类的吧。
opencv里面好像么有我上面说的这种转换,也可能是我用的少,不知道。我只知道可以转成灰度图,HSV图之类的
SpringSecurity3.1.2统制一个账户同时只能登录一次
SpringSecurity3.1.2控制一个账户同时只能登录一次
网上看了很多资料,发现多多少少都有一些不足(至少我在使用的时候没成功),后来经过探索研究,得到解决方案。
具体SpringSecurity3怎么配置参考SpringSecurity3.1实践,这里只讲如何配置可以控制一个账户同时只能登录一次的配置实现。
网上很多配置是这样的,在&http&标签中加入concurrency-control配置,设置max-sessions=1。
&session-management invalid-session-url="/timeout"&
&concurrency-control max-sessions="1" error-if-maximum-exceeded="true"/&
&/session-management&
但是经测试一直没成功,经过一番查询原来是UsernamePasswordAuthenticationFilter中的一个默认属性sessionStrategy导致的。
首先我们在spring-security.xml中添加&debug/&,可以看到经过的过滤器如下:
Security filter chain: [
ConcurrentSessionFilter --- (主要)并发控制过滤器,当配置&concurrency-control /&时,会自动注册
SecurityContextPersistenceFilter
--- 主要是持久化SecurityContext实例,也就是SpringSecurity的上下文。也就是SecurityContextHolder.getContext()这个东西,可以得到Authentication。
LogoutFilter
注销过滤器
PmcUsernamePasswordAuthenticationFilter
--- (主要)登录过滤器,也就是配置文件中的&form-login/&配置、(本文主要问题就在这里)
RequestCacheAwareFilter
---- 主要作用为:用户登录成功后,恢复被打断的请求(这些请求是保存在Cache中的)。这里被打断的请求只有出现AuthenticationException、AccessDeniedException两类异常时的请求。
SecurityContextHolderAwareRequestFilter
---- 不太了解
AnonymousAuthenticationFilter
匿名登录过滤器
SessionManagementFilter
session管理过滤器
ExceptionTranslationFilter
---- 异常处理过滤器(该过滤器只过滤下面俩拦截器)[处理的异常都是继承RuntimeException,并且它只处理AuthenticationException(认证异常)和AccessDeniedException(访问拒绝异常)]
PmcFilterSecurityInterceptor
自定义拦截器
FilterSecurityInterceptor
那么先来看UsernamePasswordAuthenticationFilter,它实际是执行其父类AbstractAuthenticationProcessingFilter的doFilter()方法,看部分源码:
//子类继承该方法进行认证后返回Authentication
authResult = attemptAuthentication(request, response);
if (authResult == null) {
// return immediately as subclass has indicated that it hasn't completed authentication
//判断session是否过期、把当前用户放入session(这句是关键)
sessionStrategy.onAuthentication(authResult, request, response);
} catch(InternalAuthenticationServiceException failed) {
logger.error("An internal error occurred while trying to authenticate the user.", failed);
unsuccessfulAuthentication(request, response, failed);
看sessionStrategy的默认值是什么?
private SessionAuthenticationStrategy sessionStrategy = new NullAuthenticatedSessionStrategy();
然后我们查询NullAuthenticatedSessionStrategy类的onAuthentication()方法竟然为空方法[问题就出现在这里]。那么为了解决这个问题,我们需要向UsernamePasswordAuthenticationFilter中注入类ConcurrentSessionControlStrategy。
这里需要说明下,注入的属性name名称为sessionAuthenticationStrategy,因为它的setter方法这么写的:
public void setSessionAuthenticationStrategy(SessionAuthenticationStrategy sessionStrategy) {
this.sessionStrategy = sessionS
这样,我们的配置文件需要这样配置(只贴出部分代码)[具体参考SpringSecurity3.1实践那篇博客]:
&http entry-point-ref="loginAuthenticationEntryPoint"&
delete-cookies="JSESSIONID"
logout-success-url="/"
invalidate-session="true"/&
&access-denied-handler error-page="/common/view/accessDenied.jsp"/&
&session-management invalid-session-url="/timeout" session-authentication-strategy-ref="sas"/&
&custom-filter ref="pmcLoginFilter" position="FORM_LOGIN_FILTER"/&
&custom-filter ref="concurrencyFilter" position="CONCURRENT_SESSION_FILTER"/&
&custom-filter ref="pmcSecurityFilter" before="FILTER_SECURITY_INTERCEPTOR"/&
&!-- 登录过滤器(相当于&form-login/&) --&
&beans:bean id="pmcLoginFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"&
&beans:property name="authenticationManager" ref="authManager"&&/beans:property&
&beans:property name="authenticationFailureHandler" ref="failureHandler"&&/beans:property&
&beans:property name="authenticationSuccessHandler" ref="successHandler"&&/beans:property&
&beans:property name="sessionAuthenticationStrategy" ref="sas"&&/beans:property&
&/beans:bean&
&!-- ConcurrentSessionFilter过滤器配置(主要设置账户session过期路径) --&
&beans:bean id="concurrencyFilter" class="org.springframework.security.web.session.ConcurrentSessionFilter"&
&beans:property name="expiredUrl" value="/timeout"&&/beans:property&
&beans:property name="sessionRegistry" ref="sessionRegistry"&&/beans:property&
&/beans:bean&
&!-- 未验证用户的登录入口 --&
&beans:bean id="loginAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"&
&beans:constructor-arg name="loginFormUrl" value="/"&&/beans:constructor-arg&
&/beans:bean&
&!-- 注入到UsernamePasswordAuthenticationFilter中,否则默认使用的是NullAuthenticatedSessionStrategy,则获取不到登录用户数
error-if-maximum-exceeded:若当前maximumSessions为1,当设置为true表示同一账户登录会抛出SessionAuthenticationException异常,异常信息为:Maximum sessions of {0} for this principal exceeded;
当设置为false时,不会报错,则会让同一账户最先认证的session过期。
具体参考:ConcurrentSessionControlStrategy:onAuthentication()
&beans:bean id="sas" class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy"&
&beans:property name="maximumSessions" value="1"&&/beans:property&
&beans:property name="exceptionIfMaximumExceeded" value="true"&&/beans:property&
&beans:constructor-arg name="sessionRegistry" ref="sessionRegistry"&&/beans:constructor-arg&
&/beans:bean&
&beans:bean id="sessionRegistry" class="org.springframework.security.core.session.SessionRegistryImpl"&&/beans:bean&
这样设置后,即可实现一个账户同时只能登录一次,但是有个小瑕疵。
如:A用户用账号admin登录系统,B用户在别处也用账号admin登录系统,这时会出现两种情况:
1、设置exceptionIfMaximumExceeded=true,会报异常:SessionAuthenticationException("Maximum sessions of {0} for this principal exceeded");
2、设置exceptionIfMaximumExceeded=false,那么B用户会把A用户挤掉,A用户再点击用户,则会跳转到
ConcurrentSessionFilter的expiredUrl路径。
最理想的解决办法是第一种,但是不能让其报异常,在登录失败的handler中扑捉该异常,
跳转到登录页面提示用户该账号已经登录,不能再登录。
ps:但是这里还会有点问题,当用户关闭浏览器或者直接关机等非正常退出时候将登录不进去。
目前我的解决方案是:比对IP地址,判断如果是本机用户可以两次登录系统
,然后使第一次登录的账号无效。 这里代码就不贴出来了
依据下拉列表的不同链接到不同页面,求高手
根据下拉列表的不同链接到不同页面,求高手&%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%&&%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%&&!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&&html&
&base href="&%=basePath%&"&
&title&My JSP 'select.jsp' starting page&/title&
&meta http-equiv="pragma" content="no-cache"& &meta http-equiv="cache-control" content="no-cache"& &meta http-equiv="expires" content="0"&
&meta http-equiv="keywords" content="keyword1,keyword2,keyword3"& &meta http-equiv="description" content="This is my page"& &!-- &link rel="stylesheet" type="text/css" href="styles.css"& --&
&script language="javascript" type="text/javascript"&
function ChangeItem()
var name=form.name.
window.location.href="New.jsp?name="+
&% String name="";
if(request.getParameter("name")!=null)
name=request.getParameter("name");
&form name="form" method="post" action=""&
&td width="70" height="30"&查询条件:&/td&
&td width="180"&&div align="left"&
&select name="name" style="width:160;border:1" onChange="ChangeItem()"&
&option&请选择&/option&
&option value="1"&%if(name.equals("1")){%&selected&%} %&&按论文题目查询&/option&
&option value="2"&%if(name.equals("2")){%&selected&%} %&&按指导老师查询&/option&
&option value="3"&%if(name.equals("3")){%&selected&%} %&&按审核状态查询&/option&
&option value="4"&%if(name.equals("4")){%&selected&%} %&&按论题性质查询&/option&
&/div&&/td&
&%if(name.equals("1")){%&
&tr align="center"&
&td height="30"&关键字&/td&
&td&&input type="text" name="point"&&/td&
&%}if(name.equals("2")){%&
&tr align="center"&
&td height="30"&关键字&/td&
&td&&input type="text" name="point"&&/td&
&%}if(name.equals("3")){%&
&tr align="center"&
&td height="30"&关键字&/td&
&input type="radio" name="yi" value="radiobutton"/&已审核 &input type="radio" name="yi" value="radiobutton"/&未审核
&tr align="center"&&%}if(name.equals("4")){%&
&input type="radio" name="ni" value="radiobutton"/&一般课题 &input type="radio" name="ni" value="radiobutton"/&自主命题
&td height="30" colspan="2" align="center"&
&input type="submit" name="Submit2" value="查询"&
&input type="submit" name="Submit2" value="重置"&
&/body&&/html&我想实现一个功能,当点击查询按钮时,根据不同的下拉列表,显示不同的网页,该怎么实现例如当下拉列表显示“按指导老师查询”时,链接到以下页面&%@ page language="java" import="java.util.*" pageEncoding="GB2312"%&&%@ page import="java.sql.*"%&&!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&&html&
&title&以指导老师查询&/title&
&meta http-equiv="pragma" content="no-cache"& &meta http-equiv="cache-control" content="no-cache"& &meta http-equiv="expires" content="0"&
&meta http-equiv="keywords" content="keyword1,keyword2,keyword3"& &meta http-equiv="description" content="This is my page"& &!-- &link rel="stylesheet" type="text/css" href="styles.css"& --&
&%!String trans(String t)
String result=
byte temp[];
temp=t.getBytes("iso-8859-1");
result=new String(temp);
catch(Exception e)
&%CSResultSString t=request.getParameter("ti");try{ Class.forName("com.mysql.jdbc.Driver"); }catch (Exception e){out.print(e); }try{String uri="jdbc:mysql://localhost/lunwen";con=DriverManager.getConnection(uri,"root","789456");sql=con.createStatement();rs=sql.executeQuery("SELECT * FROM lunwentopic WHERE lunwentimu LIKE '%"+trans(t)+"%'");out.print("&table align=center border=1&");out.print("&tr&");out.print("&th width=160&"+"论文题目"+"&/td&");out.print("&th width=80&"+"指导老师"+"&/td&");out.print("&/tr&");while(rs.next()){out.print("&tr&");out.print("&td align=center width=160&"+rs.getString(4)+"&/td&");out.print("&td align=center width=80&"+rs.getString(7)+"&/td&");out.print("&/tr&");out.print("&/table&");}con.close();}catch(SQLException el){out.print(el); }%&
&/body&&/html&求高手指导------解决方案--------------------
&!--以下内容我放在linkSelector.jsp中--&&%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%&&%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%&&!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&
&base href="&%=basePath%&"& &title&My JSP 'select.jsp' starting page&/title&&meta http-equiv="pragma" content="no-cache"&
&meta http-equiv="cache-control" content="no-cache"&
&meta http-equiv="expires" content="0"&
&meta http-equiv="keywords" content="keyword1,keyword2,keyword3"&
&meta http-equiv="description" content="This is my page"&
&link rel="stylesheet" type="text/css" href="styles.css"&
&/head& &body&
&script language="javascript" type="text/javascript"&
function ChangeItem()
var name=form.name.
//这里要注意下
window.location.href="linkSelector.jsp?name="+
function submitForm()
var name=form.name.
if(name=="1"){
window.location.href="1.jsp";
if(name=="2"){
window.location.href="2.jsp";
if(name=="3"){
window.location.href="3.jsp";
if(name=="4"){
window.location.href="4.jsp";
}&/script&
&% String name="";
if(request.getParameter("name")!=null)
name=request.getParameter("name");
&form name="form" method="post" onSubmit=""&
&td width="70" height="30"&查询条件:&/td&
&td width="180"&&div align="left"&
&select name="name" style="width:160;border:1" onChange="ChangeItem()"&
&option&请选择&/option&
&option value="1"&%if(name.equals("1")){%&selected&%} %&&按论文题目查询&/option&
&option value="2"&%if(name.equals("2")){%&selected&%} %&&按指导老师查询&/option&
&option value="3"&%if(name.equals("3")){%&selected&%} %&&按审核状态查询&/option&
&option value="4"&%if(name.equals("4")){%&selected&%} %&&按论题性质查询&/option&
&/div&&/td&
&%if(name.equals("1")){%&
&tr align="center"&
&td height="30"&关键字&/td&
&td&&input type="text" name="point"&&/td&
&%}if(name.equals("2")){%&
&tr align="center"&
&td height="30"&关键字&/td&
&td&&input type="text" name="point"&&/td&
&%}if(name.equals("3")){%&
&tr align="center"&
&td height="30"&关键字&/td&
&input type="radio" name="yi" value="radiobutton"/&已审核
&input type="radio" name="yi" value="radiobutton"/&未审核
&tr align="center"&&%}if(name.equals("4")){%&
&input type="radio" name="ni" value="radiobutton"/&一般课题
&input type="radio" name="ni" value="radiobutton"/&自主命题
&td height="30" colspan="2" align="center"&
&input type="submit" name="Submit2" value="查询" onClick="submitForm()"&
&input type="reset" name="Submit2" value="重置"&
&/body&&/html&接下来就自己发挥吧
如果您想提高自己的技术水平,欢迎加入本站官方1号QQ群:&&,&&2号QQ群:,在群里结识技术精英和交流技术^_^
本站联系邮箱:}

我要回帖

更多关于 rgb565的存储格式 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信